~awn-core/awn/trunk-rewrite

« back to all changes in this revision

Viewing changes to applets/taskmanager/task-manager.c

  • Committer: R. Cryderman
  • Date: 2009-11-14 22:16:09 UTC
  • Revision ID: rcryderman@gmail.com-20091114221609-32pv8x0zah4s6qph
* applets/taskmanager/task-icon.c:
* applets/taskmanager/task-manager.c:
        Optimize group. 
        Regroup non-launchers.

Show diffs side-by-side

added added

removed removed

Lines of Context:
93
93
  
94
94
  GHashTable *win_table;
95
95
  GHashTable *desktops_table;
96
 
 
 
96
  /*
 
97
   Used during grouping configuration changes for optimization purposes
 
98
   */
 
99
  GList *grouping_list;
97
100
  /* Properties */
98
101
  GValueArray *launcher_paths;
99
102
  gboolean     show_all_windows;
2291
2294
  }
2292
2295
}
2293
2296
 
2294
 
/*
2295
 
static void
2296
 
task_manager_regroup_icon (TaskManager * manager,TaskIcon * icon)
2297
 
{
2298
 
 
2299
 
}
2300
 
*/
2301
 
 
2302
2297
static void
2303
2298
task_manager_regroup_launcher_icon (TaskManager * manager,TaskIcon * grouping_icon)
2304
2299
{
2311
2306
  GtkWidget * grouping_launcher = GTK_WIDGET(task_icon_get_launcher (grouping_icon));
2312
2307
 
2313
2308
  g_assert (grouping_launcher);
 
2309
  for (i=task_icon_get_items(grouping_icon);i; i=i->next)
 
2310
  {
 
2311
    TaskItem * item = i->data;
 
2312
    if (TASK_IS_LAUNCHER(item))
 
2313
    {
 
2314
      continue;
 
2315
    }
 
2316
    if (g_list_find (priv->grouping_list,item))
 
2317
    {
 
2318
      continue;
 
2319
    }
 
2320
    priv->grouping_list = g_list_prepend (priv->grouping_list,item);
 
2321
  }
2314
2322
  for (i=priv->icons; i; i=i->next)
2315
2323
  {
2316
2324
    GtkWidget * launcher;
2333
2341
    if ( g_strcmp0 (task_launcher_get_desktop_path(TASK_LAUNCHER(grouping_launcher)),
2334
2342
                    task_launcher_get_desktop_path(TASK_LAUNCHER(launcher)) )==0)
2335
2343
    {
2336
 
      for (j=task_icon_get_items(icon);j;j=j->next)
 
2344
      for (j=task_icon_get_items(icon);j; j?j=j->next:j)
2337
2345
      {
 
2346
 
2338
2347
        TaskItem * item = j->data;
2339
2348
        if (TASK_IS_LAUNCHER(item))
2340
2349
        {
2341
2350
          continue;
2342
2351
        }
 
2352
        if (g_list_find (priv->grouping_list,item))
 
2353
        {
 
2354
          continue;
 
2355
        }
2343
2356
        task_icon_moving_item (grouping_icon,icon,item);
 
2357
        priv->grouping_list = g_list_prepend (priv->grouping_list,item);
2344
2358
        j = task_icon_get_items(icon);
2345
2359
      }
2346
2360
    }
2348
2362
}
2349
2363
 
2350
2364
static void
 
2365
task_manager_regroup_nonlauncher_icon (TaskManager * manager,TaskIcon * grouping_icon)
 
2366
{
 
2367
  g_assert (TASK_IS_ICON(grouping_icon));
 
2368
  g_assert (TASK_IS_MANAGER(manager));
 
2369
  
 
2370
  GSList * i;
 
2371
  GSList * j;
 
2372
  GSList * w; 
 
2373
  GSList * k;
 
2374
  TaskManagerPrivate * priv = manager->priv;
 
2375
  for (i=task_icon_get_items(grouping_icon);i; i=i->next)
 
2376
  {
 
2377
    TaskItem * item = i->data;
 
2378
    if (g_list_find (priv->grouping_list,item))
 
2379
    {
 
2380
      continue;
 
2381
    }
 
2382
    priv->grouping_list = g_list_prepend (priv->grouping_list,item);
 
2383
  }
 
2384
 
 
2385
  for (i=priv->icons; i; i=i->next)
 
2386
  {
 
2387
    TaskIcon  * icon;
 
2388
    icon = i->data;    
 
2389
    if (icon == grouping_icon)
 
2390
    {
 
2391
      continue;
 
2392
    }
 
2393
    if (task_icon_contains_launcher (icon) )
 
2394
    {
 
2395
      continue;
 
2396
    }
 
2397
    for (j=task_icon_get_items(icon);j;j?j=j->next:j)
 
2398
    {
 
2399
      gint match_score = 0;
 
2400
      gint max_match_score = 0;
 
2401
      TaskIcon * match = NULL;
 
2402
      TaskItem * item = j->data;
 
2403
      if (g_list_find (priv->grouping_list,item))
 
2404
      {
 
2405
        continue;
 
2406
      }      
 
2407
      for (w = priv->icons; w; w = w->next)
 
2408
      {
 
2409
        TaskIcon *taskicon = w->data;
 
2410
        /*optimization....  if the icon we're checking against has a launcher
 
2411
         then the item would have been grouped with it on open if it could have 
 
2412
         been*/
 
2413
        if ( task_icon_contains_launcher (taskicon))
 
2414
        {
 
2415
          continue;
 
2416
        }
 
2417
        match_score = task_icon_match_item (taskicon, item);
 
2418
        if (match_score > max_match_score)
 
2419
        {
 
2420
          max_match_score = match_score;
 
2421
          match = taskicon;
 
2422
        }
 
2423
      }
 
2424
      if  (
 
2425
           match && (match==grouping_icon)
 
2426
           &&
 
2427
           (priv->grouping || ( (task_icon_count_items(match)==1) && (task_icon_contains_launcher (match)) ) ) 
 
2428
           &&
 
2429
           ( max_match_score > 99-priv->match_strength))
 
2430
      {
 
2431
        /*we have one match in this icon.  dump all the other items in also and
 
2432
         get the hell out of the inner loop.  3 nested loops nasty... short 
 
2433
         circuiting as much as possible*/
 
2434
        task_icon_moving_item (grouping_icon,icon,item);
 
2435
        priv->grouping_list = g_list_prepend (priv->grouping_list,item);
 
2436
        for (k=task_icon_get_items (icon);k;k=k->next)
 
2437
        {
 
2438
          if (g_list_find (priv->grouping_list,k->data))
 
2439
          {
 
2440
            continue;
 
2441
          }                
 
2442
          task_icon_moving_item (grouping_icon,icon,k->data);
 
2443
          priv->grouping_list = g_list_prepend (priv->grouping_list,k->data);
 
2444
        }
 
2445
        j = NULL;
 
2446
      }
 
2447
    }
 
2448
  }
 
2449
}
 
2450
 
 
2451
static void
2351
2452
task_manager_regroup (TaskManager * manager)
2352
2453
{
2353
2454
  GSList * i;
2354
2455
 
2355
2456
  TaskManagerPrivate * priv = manager->priv;
2356
 
 
2357
2457
  /*
2358
2458
   find the permanent Launchers and regroup them*/
2359
2459
  for (i=priv->icons; i; i=i->next)
2380
2480
      task_manager_regroup_launcher_icon (manager,icon);      
2381
2481
    }
2382
2482
  }
 
2483
  /* Find the icons that do not have a launcher. */
 
2484
  for (i=priv->icons; i; i=i->next)
 
2485
  {
 
2486
    TaskIcon  * icon;
 
2487
    icon = i->data;
 
2488
    if ( !task_icon_contains_launcher (icon) )
 
2489
    {
 
2490
      GSList *items = task_icon_get_items(icon);
 
2491
      if (items)
 
2492
      {
 
2493
        task_manager_regroup_nonlauncher_icon (manager,icon);
 
2494
      }
 
2495
    }
 
2496
  }
 
2497
  g_list_free (priv->grouping_list);
 
2498
  priv->grouping_list = NULL;
2383
2499
}
2384
2500
 
2385
2501
static void