~ubuntu-branches/ubuntu/natty/avant-window-navigator/natty

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Julien Lavergne
  • Date: 2010-12-17 13:48:28 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20101217134828-l394fb03wdkxc3mq
Tags: 0.4.1~bzr803-0ubuntu1
* New upstream snapshot.
 - Fix a crash with signal 5 in _XError (LP: #612144)
 - Re-add "move to another workspace" to launcher (LP: #568555)
* debian/patches:
 - 02-ftbfs-python-2.6.patch: Refresh.
 - 03-python-import.patch: Refresh.
 - 04-lda-requierement.patch: New patch, lower desktop-agnostic requierement,
   the version in Natty is enough.
 - Drop all others patches, merged upstream.
* debian/copyright:
 - Update copyright years and upstream authors.
* debian/control:
 - Build-depends on valac-0.10 (>= 0.9.1), to force stable version of Vala.
* debian/libawn1.symbols:
 - Update with new symbols. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
#include "libawn/awn-pixbuf-cache.h"
48
48
#include "awn-desktop-lookup-cached.h"
49
49
#include "task-manager.h"
 
50
#include "task-manager-panel-connector.h"
 
51
 
50
52
#include "dock-manager-api.h"
51
53
 
52
54
#include "task-drag-indicator.h"
69
71
 
70
72
static GQuark win_quark = 0;
71
73
 
 
74
static const GtkTargetEntry drop_types[] = 
 
75
{
 
76
  { (gchar*)"text/uri-list", 0, 0 },
 
77
  { (gchar*)"STRING", 0, 0 },
 
78
  { (gchar*)"text/plain", 0,  },
 
79
  { (gchar*)"awn/task-icon", 0, 0 }
 
80
};
 
81
static const gint n_drop_types = G_N_ELEMENTS (drop_types);
 
82
 
 
83
 
 
84
typedef struct
 
85
{
 
86
  DesktopAgnosticConfigClient *panel_instance_client;
 
87
  GdkWindow * foreign_window;
 
88
  GdkRegion * foreign_region;
 
89
  TaskManagerPanelConnector * connector;
 
90
  gint        intellihide_mode;
 
91
  guint       autohide_cookie;
 
92
} TaskManagerAwnPanelInfo;
 
93
 
72
94
struct _TaskManagerPrivate
73
95
{
74
96
  DesktopAgnosticConfigClient *client;
 
97
 
 
98
  DBusGConnection *connection;
 
99
  DBusGProxy      *proxy;
 
100
  
75
101
  TaskSettings    *settings;
76
102
  WnckScreen      *screen;
77
103
 
78
 
  /*Used by Intellihide*/
79
 
  guint           autohide_cookie;
80
 
  GdkWindow       *awn_gdk_window;
81
 
  GdkRegion       * awn_gdk_region;
82
 
  
83
 
  guint           attention_cookie;
84
 
  guint           attention_source;
85
 
  
86
104
  /* Dragging properties */
87
105
  TaskIcon          *dragged_icon;
88
106
  TaskDragIndicator *drag_indicator;
97
115
  
98
116
  GHashTable *win_table;
99
117
  GHashTable *desktops_table;
 
118
  GHashTable *intellihide_panel_instances;
 
119
 
100
120
  /*
101
121
   Used during grouping configuration changes for optimization purposes
102
122
   */
103
123
  GList *grouping_list;
104
124
  /* Properties */
105
125
  GValueArray *launcher_paths;
 
126
 
 
127
  guint        attention_cookie;
 
128
  guint        attention_source;
 
129
 
106
130
  gboolean     show_all_windows;
107
131
  gboolean     only_show_launchers;
108
132
  gboolean     drag_and_drop;
109
133
  gboolean     grouping;
110
 
  gboolean     intellihide;
111
134
  gboolean     icon_grouping;
112
 
  gint         intellihide_mode;
113
135
  gint         match_strength;
114
136
  gint         attention_autohide_timer;
 
137
  gint         desktop_copy;
115
138
  
116
139
  guint        attention_required_reminder_id;
117
140
  gint         attention_required_reminder;
118
141
 
119
142
  AwnDesktopLookupCached * desktop_lookup;
120
143
  TaskManagerDispatcher *dbus_proxy;
 
144
 
 
145
  GtkWidget * add_icon;
 
146
  guint       add_icon_source;
 
147
  
121
148
};
122
149
 
123
150
typedef struct
128
155
 
129
156
enum
130
157
{
 
158
  INTELLIHIDE_NONE,
131
159
  INTELLIHIDE_WORKSPACE,
132
160
  INTELLIHIDE_APP,
133
161
  INTELLIHIDE_GROUP  
134
162
};
135
163
 
 
164
enum{
 
165
  DESKTOP_COPY_ALL=0,
 
166
  DESKTOP_COPY_OWNER,
 
167
  DESKTOP_COPY_NONE
 
168
}DesktopCopy;
 
169
 
136
170
enum
137
171
{
138
172
  PROP_0,
144
178
  PROP_GROUPING,
145
179
  PROP_ICON_GROUPING,
146
180
  PROP_MATCH_STRENGTH,
147
 
  PROP_INTELLIHIDE,
148
 
  PROP_INTELLIHIDE_MODE,
149
181
  PROP_ATTENTION_AUTOHIDE_TIMER,
150
 
  PROP_ATTENTION_REQUIRED_REMINDER,
151
 
  PROP_ATTENTION_REQUIED_REMINDER_ID
 
182
  PROP_DESKTOP_COPY,
 
183
  PROP_ATTENTION_REQUIRED_REMINDER
152
184
};
153
185
 
154
186
 
205
237
static void task_manager_active_workspace_changed_cb (WnckScreen    *screen,
206
238
                                                      WnckWorkspace *previous_space,
207
239
                                                      TaskManager * manager);
 
240
static void task_manager_check_for_intersection (TaskManager * manager,
 
241
                                                  WnckWorkspace * space,
 
242
                                                  WnckApplication * app);
 
243
 
208
244
static void task_manager_win_geom_changed_cb (WnckWindow *window, 
209
245
                                              TaskManager * manager);
210
246
static void task_manager_win_closed_cb (WnckScreen *screen,
219
255
 
220
256
static gboolean _attention_required_reminder_cb (TaskManager * manager);
221
257
 
 
258
static void task_manager_intellihide_change_cb (const char* group, 
 
259
                                    const char* key, 
 
260
                                    GValue* value, 
 
261
                                    int * user_data);
 
262
 
 
263
static void _icon_dest_drag_data_received (GtkWidget      *widget,
 
264
                                   GdkDragContext *context,
 
265
                                   gint            x,
 
266
                                   gint            y,
 
267
                                   GtkSelectionData *sdata,
 
268
                                   guint           info,
 
269
                                   guint           time_,
 
270
                                   TaskManager     *manager);
 
271
 
222
272
typedef enum 
223
273
{
224
274
  TASK_MANAGER_ERROR_UNSUPPORTED_WINDOW_TYPE,
282
332
      g_value_set_boolean (value, manager->priv->icon_grouping);
283
333
      break;
284
334
 
285
 
    case PROP_INTELLIHIDE:
286
 
      g_value_set_boolean (value, manager->priv->intellihide);
287
 
      break;
288
 
 
289
 
    case PROP_INTELLIHIDE_MODE:
290
 
      g_value_set_int (value, manager->priv->intellihide_mode);
291
 
      break;
292
 
 
293
335
    case PROP_MATCH_STRENGTH:
294
336
      g_value_set_int (value, manager->priv->match_strength);
295
337
      break;
302
344
      g_value_set_int (value, manager->priv->attention_required_reminder);
303
345
      break;
304
346
 
 
347
    case PROP_DESKTOP_COPY:
 
348
      g_value_set_int (value, manager->priv->desktop_copy);
 
349
      break;
 
350
      
305
351
    default:
306
352
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
307
353
  }
315
361
{
316
362
  TaskManager *manager = TASK_MANAGER (object);
317
363
 
 
364
  g_return_if_fail (TASK_IS_MANAGER (object));
 
365
 
318
366
  switch (prop_id)
319
367
  {
320
368
    case PROP_SHOW_ALL_WORKSPACES:
351
399
    case PROP_ICON_GROUPING:
352
400
      manager->priv->icon_grouping = g_value_get_boolean (value);
353
401
      break;
354
 
      
355
 
    case PROP_INTELLIHIDE:
356
 
      /* TODO move into a function */
357
 
      manager->priv->intellihide = g_value_get_boolean (value);
358
 
      if (!manager->priv->intellihide && manager->priv->autohide_cookie)
359
 
      {     
360
 
        awn_applet_uninhibit_autohide (AWN_APPLET(manager), manager->priv->autohide_cookie);
361
 
        manager->priv->autohide_cookie = 0;
362
 
      }
363
 
      if (manager->priv->intellihide && !manager->priv->autohide_cookie)
364
 
      {     
365
 
        manager->priv->autohide_cookie = awn_applet_inhibit_autohide (AWN_APPLET(manager),"Intellihide" );
366
 
      }      
367
 
      break;
368
 
 
369
 
    case PROP_INTELLIHIDE_MODE:
370
 
      manager->priv->intellihide_mode = g_value_get_int (value);
371
 
      break;
372
 
      
 
402
            
373
403
    case PROP_ATTENTION_AUTOHIDE_TIMER:
374
404
      manager->priv->attention_autohide_timer = g_value_get_int (value);
375
405
      break;
388
418
                                                                             object);
389
419
      }
390
420
      break;
391
 
 
 
421
    case PROP_DESKTOP_COPY:
 
422
      manager->priv->desktop_copy = g_value_get_int (value);
 
423
      break;
392
424
    default:
393
425
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
394
426
  }
395
427
}
396
428
 
397
429
static void
 
430
_delete_panel_info_cb (TaskManagerAwnPanelInfo * panel_info)
 
431
{
 
432
  g_object_unref (panel_info->connector);
 
433
  g_object_unref (panel_info->foreign_window);
 
434
  gdk_region_destroy (panel_info->foreign_region);
 
435
  g_free (panel_info);
 
436
}
 
437
 
 
438
static void
 
439
_on_panel_added (DBusGProxy *proxy,guint panel_id,TaskManager *applet)
 
440
{
 
441
  TaskManagerPrivate *priv = TASK_MANAGER_GET_PRIVATE (applet);
 
442
  GError * error = NULL;
 
443
  TaskManagerAwnPanelInfo * panel_info = NULL;
 
444
  gchar * uid = g_strdup_printf("-999%d",panel_id);
 
445
  
 
446
  g_assert (!g_hash_table_lookup (priv->intellihide_panel_instances,GINT_TO_POINTER (panel_id)));
 
447
  panel_info = g_malloc0 (sizeof (TaskManagerAwnPanelInfo) );
 
448
  panel_info->connector = task_manager_panel_connector_new (panel_id);
 
449
  g_free (uid);
 
450
  panel_info->panel_instance_client = awn_config_get_default (panel_id, NULL);
 
451
  panel_info->intellihide_mode = desktop_agnostic_config_client_get_int (
 
452
                                             panel_info->panel_instance_client, 
 
453
                                             "panel", 
 
454
                                             "intellihide_mode", 
 
455
                                              &error);
 
456
  if (error)
 
457
  {
 
458
    g_debug ("%s: error accessing intellihide_mode. \"%s\"",__func__,error->message);
 
459
    g_error_free (error);
 
460
    error = NULL;
 
461
  }
 
462
  desktop_agnostic_config_client_notify_add (panel_info->panel_instance_client, 
 
463
                                             "panel", 
 
464
                                             "intellihide_mode", 
 
465
                                             (DesktopAgnosticConfigNotifyFunc)task_manager_intellihide_change_cb, 
 
466
                                             &panel_info->intellihide_mode, 
 
467
                                             &error);
 
468
  if (error)
 
469
  {
 
470
    g_debug ("%s: error binding intellihide_mode. \"%s\"",__func__,error->message);
 
471
    g_error_free (error);
 
472
    error = NULL;
 
473
  }
 
474
 
 
475
  if (!panel_info->intellihide_mode && panel_info->autohide_cookie)
 
476
  {     
 
477
    task_manager_panel_connector_uninhibit_autohide (panel_info->connector, panel_info->autohide_cookie);
 
478
    panel_info->autohide_cookie = 0;
 
479
  }
 
480
  if (panel_info->intellihide_mode && !panel_info->autohide_cookie)
 
481
  {     
 
482
    panel_info->autohide_cookie = task_manager_panel_connector_inhibit_autohide (panel_info->connector,"Intellihide" );
 
483
  }   
 
484
 
 
485
  g_hash_table_insert (priv->intellihide_panel_instances,GINT_TO_POINTER(panel_id),panel_info);                                                                           
 
486
}
 
487
 
 
488
static void
 
489
_on_panel_removed (DBusGProxy *proxy,guint panel_id,TaskManager * applet)
 
490
{
 
491
  TaskManagerPrivate *priv = TASK_MANAGER_GET_PRIVATE (applet);
 
492
  TaskManagerAwnPanelInfo * panel_info = g_hash_table_lookup (priv->intellihide_panel_instances,GINT_TO_POINTER (panel_id));
 
493
 
 
494
  desktop_agnostic_config_client_remove_instance (panel_info->panel_instance_client);
 
495
  g_assert (g_hash_table_remove (priv->intellihide_panel_instances,GINT_TO_POINTER (panel_id)));
 
496
}
 
497
 
 
498
static void
398
499
task_manager_constructed (GObject *object)
399
500
{
400
501
  TaskManagerPrivate *priv;
401
502
  GtkWidget          *widget;
 
503
  GError             *error=NULL;
 
504
  GStrv              panel_paths;
402
505
  
403
506
  G_OBJECT_CLASS (task_manager_parent_class)->constructed (object);
404
507
  
405
508
  priv = TASK_MANAGER_GET_PRIVATE (object);
406
509
  widget = GTK_WIDGET (object);
407
510
 
 
511
  priv->proxy = dbus_g_proxy_new_for_name (priv->connection,
 
512
                                           "org.awnproject.Awn",
 
513
                                            "/org/awnproject/Awn",
 
514
                                           "org.awnproject.Awn.App");
 
515
  if (!priv->proxy)
 
516
  {
 
517
    g_warning("%s: Could not connect to mothership!\n",__func__);
 
518
  }
 
519
  else
 
520
  {
 
521
    dbus_g_proxy_add_signal (priv->proxy, "PanelAdded",
 
522
                             G_TYPE_INT, G_TYPE_INVALID);
 
523
    dbus_g_proxy_add_signal (priv->proxy, "PanelRemoved",
 
524
                             G_TYPE_INT, G_TYPE_INVALID);
 
525
    dbus_g_proxy_connect_signal (priv->proxy, "PanelAdded",
 
526
                                 G_CALLBACK (_on_panel_added), object, 
 
527
                                 NULL);
 
528
    dbus_g_proxy_connect_signal (priv->proxy, "PanelRemoved",
 
529
                                 G_CALLBACK (_on_panel_removed), object, 
 
530
                                 NULL);
 
531
 
 
532
  }    
 
533
  
408
534
  /*
409
535
   Set the cache size of our AwnPixbufCache to something a bit bigger.
410
536
 
415
541
               NULL);
416
542
 
417
543
  priv->desktops_table = g_hash_table_new_full (g_str_hash,g_str_equal,g_free,g_free);
 
544
  priv->intellihide_panel_instances = g_hash_table_new_full (g_direct_hash,g_direct_equal,
 
545
                                                             NULL,
 
546
                                                             (GDestroyNotify)_delete_panel_info_cb);                                    
418
547
 
419
548
  priv->client = awn_config_get_default_for_applet (AWN_APPLET (object), NULL);
420
 
 
 
549
  
421
550
  /* Connect up the important bits */
422
551
  desktop_agnostic_config_client_bind (priv->client,
423
552
                                       DESKTOP_AGNOSTIC_CONFIG_GROUP_DEFAULT,
454
583
                                       "icon_grouping",
455
584
                                       object, "icon_grouping", TRUE,
456
585
                                       DESKTOP_AGNOSTIC_CONFIG_BIND_METHOD_FALLBACK,
457
 
                                       NULL);
458
 
  desktop_agnostic_config_client_bind (priv->client,
459
 
                                       DESKTOP_AGNOSTIC_CONFIG_GROUP_DEFAULT,
460
 
                                       "intellihide",
461
 
                                       object, "intellihide", TRUE,
462
 
                                       DESKTOP_AGNOSTIC_CONFIG_BIND_METHOD_FALLBACK,
463
586
                                       NULL);  
464
587
  desktop_agnostic_config_client_bind (priv->client,
465
588
                                       DESKTOP_AGNOSTIC_CONFIG_GROUP_DEFAULT,
466
 
                                       "intellihide_mode",
467
 
                                       object, "intellihide_mode", TRUE,
468
 
                                       DESKTOP_AGNOSTIC_CONFIG_BIND_METHOD_FALLBACK,
469
 
                                       NULL);    
470
 
  desktop_agnostic_config_client_bind (priv->client,
471
 
                                       DESKTOP_AGNOSTIC_CONFIG_GROUP_DEFAULT,
472
589
                                       "match_strength",
473
590
                                       object, "match_strength", TRUE,
474
591
                                       DESKTOP_AGNOSTIC_CONFIG_BIND_METHOD_FALLBACK,
485
602
                                       object, "attention_required_reminder", TRUE,
486
603
                                       DESKTOP_AGNOSTIC_CONFIG_BIND_METHOD_FALLBACK,
487
604
                                       NULL);
 
605
  desktop_agnostic_config_client_bind (priv->client,
 
606
                                       DESKTOP_AGNOSTIC_CONFIG_GROUP_DEFAULT,
 
607
                                       "desktop_copy",
 
608
                                       object, "desktop copy", TRUE,
 
609
                                       DESKTOP_AGNOSTIC_CONFIG_BIND_METHOD_FALLBACK,
 
610
                                       NULL);
488
611
 
489
612
  g_signal_connect (priv->screen,"active-window-changed",
490
613
                    G_CALLBACK(task_manager_active_window_changed_cb),object);
495
618
 
496
619
  /* DBus interface */
497
620
  priv->dbus_proxy = task_manager_dispatcher_new (TASK_MANAGER (object));
 
621
 
 
622
  if (priv->proxy)
 
623
  {
 
624
    dbus_g_proxy_call (priv->proxy, "GetPanels",
 
625
                     &error,
 
626
                     G_TYPE_INVALID, 
 
627
                     G_TYPE_STRV, &panel_paths,
 
628
                     G_TYPE_INVALID);
 
629
    if (error)
 
630
    {
 
631
      g_debug ("%s: %s",__func__,error->message);
 
632
      g_error_free (error);
 
633
      error = NULL;
 
634
    }
 
635
    else
 
636
    {
 
637
      for (gint i=0; panel_paths[i];i++)
 
638
      {
 
639
        //strlen is like this as a reminder.
 
640
        _on_panel_added (priv->proxy,
 
641
                         atoi(panel_paths[i] + strlen("/org/awnproject/Awn/Panel")),
 
642
                         TASK_MANAGER(object));
 
643
        
 
644
      }
 
645
    }    
 
646
  }
 
647
  priv->add_icon = awn_themed_icon_new ();
 
648
  awn_themed_icon_set_size (AWN_THEMED_ICON(priv->add_icon),awn_applet_get_size (AWN_APPLET(object)));
 
649
  awn_themed_icon_set_info_simple (AWN_THEMED_ICON (priv->add_icon),
 
650
                                   "::no_drop::taskmanager",
 
651
                                   "dummy",
 
652
                                   "add");
 
653
  gtk_container_add (GTK_CONTAINER (priv->box),priv->add_icon);
 
654
  gtk_widget_hide (priv->add_icon);
 
655
  gtk_widget_add_events (GTK_WIDGET (priv->add_icon), GDK_ALL_EVENTS_MASK);
 
656
  gtk_drag_dest_set (GTK_WIDGET (priv->add_icon), 
 
657
                     GTK_DEST_DEFAULT_ALL & (~GTK_DEST_DEFAULT_HIGHLIGHT),
 
658
                     drop_types, n_drop_types,
 
659
                     GDK_ACTION_COPY | GDK_ACTION_MOVE);
 
660
  g_signal_connect (priv->add_icon,
 
661
                    "drag-data-received",
 
662
                     G_CALLBACK(_icon_dest_drag_data_received),
 
663
                    object);
 
664
                    
498
665
}
499
666
 
500
667
static void
555
722
                                G_PARAM_CONSTRUCT | G_PARAM_READWRITE);
556
723
  g_object_class_install_property (obj_class, PROP_ICON_GROUPING, pspec);
557
724
 
558
 
  pspec = g_param_spec_boolean ("intellihide",
559
 
                                "intellihide",
560
 
                                "Intellihide",
561
 
                                TRUE,
562
 
                                G_PARAM_READWRITE);
563
 
  g_object_class_install_property (obj_class, PROP_INTELLIHIDE, pspec);
564
 
 
565
 
  pspec = g_param_spec_int ("intellihide_mode",
566
 
                                "intellihide mode",
567
 
                                "Intellihide mode",
568
 
                                0,
569
 
                                2,
570
 
                                1,
571
 
                                G_PARAM_CONSTRUCT | G_PARAM_READWRITE);
572
 
  g_object_class_install_property (obj_class, PROP_INTELLIHIDE_MODE, pspec);
573
 
 
574
725
  pspec = g_param_spec_int ("match_strength",
575
726
                            "match_strength",
576
727
                            "How radical matching is applied for grouping items",
598
749
                            G_PARAM_READWRITE);
599
750
  g_object_class_install_property (obj_class, PROP_ATTENTION_REQUIRED_REMINDER, pspec);
600
751
 
 
752
  pspec = g_param_spec_int ("desktop_copy",
 
753
                            "When/if to copy desktop files",
 
754
                            "When/if to copy desktop files",
 
755
                            DESKTOP_COPY_ALL,
 
756
                            DESKTOP_COPY_NONE,
 
757
                            DESKTOP_COPY_OWNER,
 
758
                            G_PARAM_CONSTRUCT | G_PARAM_READWRITE);
 
759
  g_object_class_install_property (obj_class, PROP_DESKTOP_COPY, pspec);
 
760
  
601
761
  /* Install signals */
602
762
  _taskman_signals[GROUPING_CHANGED] =
603
763
                g_signal_new ("grouping_changed",
619
779
task_manager_init (TaskManager *manager)
620
780
{
621
781
  TaskManagerPrivate *priv;
622
 
        
 
782
  GError         *error = NULL;
623
783
  priv = manager->priv = TASK_MANAGER_GET_PRIVATE (manager);
624
 
 
 
784
  
625
785
  priv->screen = wnck_screen_get_default ();
626
786
  priv->launcher_paths = NULL;
627
 
  priv->hidden_list = NULL;
628
 
 
 
787
  priv->hidden_list = NULL; 
 
788
  priv->add_icon_source = 0;
 
789
  priv->add_icon = NULL;
 
790
  
629
791
  wnck_set_client_type (WNCK_CLIENT_TYPE_PAGER);
630
792
 
631
793
  win_quark = g_quark_from_string ("task-window-quark");
632
794
 
633
795
  priv->settings = task_settings_get_default (AWN_APPLET(manager));
634
 
  
635
796
  /* Create the icon box */
636
797
  priv->box = awn_icon_box_new_for_applet (AWN_APPLET (manager));
637
798
  gtk_container_add (GTK_CONTAINER (manager), priv->box);
641
802
  priv->drag_indicator = TASK_DRAG_INDICATOR(task_drag_indicator_new());
642
803
  gtk_container_add (GTK_CONTAINER (priv->box), GTK_WIDGET(priv->drag_indicator));
643
804
  gtk_widget_hide (GTK_WIDGET(priv->drag_indicator));
 
805
 
644
806
  if(priv->drag_and_drop)
645
807
    _drag_add_signals(manager, GTK_WIDGET(priv->drag_indicator));
646
808
  /* TODO: free !!! */
647
809
  priv->dragged_icon = NULL;
648
810
  priv->drag_timeout = 0;
649
811
 
 
812
  priv->connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
 
813
  priv->proxy = NULL;  
 
814
  if (error)
 
815
  {
 
816
    g_warning ("%s", error->message);
 
817
    g_error_free(error);
 
818
  }
 
819
 
650
820
  /* connect to the relevent WnckScreen signals */
651
821
  g_signal_connect (priv->screen, "window-opened", 
652
822
                    G_CALLBACK (on_window_opened), manager);
755
925
  desktop_agnostic_config_client_unbind_all_for_object (priv->client,
756
926
                                                        object,
757
927
                                                        NULL);
 
928
  if (priv->connection)
 
929
  {
 
930
    if (priv->proxy) g_object_unref (priv->proxy);
 
931
    dbus_g_connection_unref (priv->connection);
 
932
    priv->connection = NULL;
 
933
    priv->proxy = NULL;
 
934
  }
 
935
  
 
936
  /*
758
937
  if (priv->autohide_cookie)
759
938
  {     
760
939
    awn_applet_uninhibit_autohide (AWN_APPLET(object), priv->autohide_cookie);
761
940
    priv->autohide_cookie = 0;
762
 
  }
763
 
  if (priv->awn_gdk_window)
 
941
  }*/
 
942
/*  if (priv->awn_gdk_window)
764
943
  {
765
944
    g_object_unref (priv->awn_gdk_window);
766
945
    priv->awn_gdk_window = NULL;
767
 
  }
 
946
  }*/
768
947
 
769
948
  G_OBJECT_CLASS (task_manager_parent_class)->dispose (object);
770
949
}
997
1176
   a better visual cue of what has changed*/
998
1177
  gboolean do_hide_animation = FALSE;
999
1178
 
 
1179
 
1000
1180
  g_return_if_fail (TASK_IS_MANAGER (manager));
1001
1181
 
1002
1182
  priv = manager->priv;
1003
 
  
1004
 
  if ( task_icon_is_visible (icon) && ( !priv->only_show_launchers || 
1005
 
        (task_icon_contains_launcher (icon) && !task_icon_count_ephemeral_items(icon))))
 
1183
  if ( task_icon_is_visible (icon) && 
 
1184
      ( !priv->only_show_launchers || !task_icon_is_ephemeral (icon))
 
1185
      )
1006
1186
  {
1007
1187
    visible = TRUE;
1008
1188
  }
1009
 
 
 
1189
  
1010
1190
  if ( !task_icon_contains_launcher (icon) )
1011
1191
  {
1012
1192
    if (task_icon_count_items(icon)==0)
1078
1258
    }
1079
1259
    else
1080
1260
    {
1081
 
      if (task_icon_count_items (icon) <= task_icon_count_ephemeral_items (icon))
 
1261
      if (task_icon_count_items (icon)==1)
1082
1262
      {
1083
1263
        destroy = TRUE;
1084
1264
      }
1102
1282
    {
1103
1283
      gtk_widget_hide (GTK_WIDGET(icon));
1104
1284
    }
 
1285
    else
 
1286
    {
 
1287
      gtk_widget_show (GTK_WIDGET(icon));
 
1288
    }
1105
1289
  }
1106
1290
}
1107
1291
 
1363
1547
    {
1364
1548
      TaskManager * manager = TASK_MANAGER(task_icon_get_applet (icon));
1365
1549
      TaskItem * launcher = get_launcher (manager,found_desktop);
 
1550
 
1366
1551
      if (launcher)
1367
1552
      {
1368
 
        task_icon_append_ephemeral_item (TASK_ICON (icon), launcher);
1369
 
      }
 
1553
        task_icon_append_item (TASK_ICON (icon), launcher);
 
1554
      }      
1370
1555
    }          
1371
1556
  }
1372
1557
}
1451
1636
    return;
1452
1637
  }
1453
1638
 
 
1639
  if (wnck_window_is_skip_pager (window))
 
1640
  {
 
1641
    return;
 
1642
  }
 
1643
 
1454
1644
  g_signal_connect (window, "state-changed", 
1455
1645
                    G_CALLBACK (check_attention_requested), manager);    
1456
1646
  
1457
1647
  /* create a new TaskWindow containing the WnckWindow*/
1458
 
  item = task_window_new (AWN_APPLET(manager), window);
 
1648
  item = task_window_new (AWN_APPLET(manager), NULL, window);
1459
1649
  g_object_set_qdata (G_OBJECT (window), win_quark, TASK_WINDOW (item));
1460
1650
 
1461
1651
  priv->windows = g_slist_append (priv->windows, item);
1474
1664
#ifdef DEBUG
1475
1665
    g_debug ("contains launcher is %d",task_icon_contains_launcher (taskicon) );
1476
1666
#endif
 
1667
    /*
 
1668
     is the task icon in the midst of disappearing?
 
1669
     */
 
1670
    if (!task_icon_get_proxy (taskicon) )
 
1671
    {
 
1672
      continue;
 
1673
    }
1477
1674
    match_score = task_icon_match_item (taskicon, item);
1478
1675
    if (match_score > max_match_score)
1479
1676
    {
1499
1696
       &&
1500
1697
       ( max_match_score > 99-priv->match_strength))
1501
1698
  {
1502
 
    task_icon_append_item (match, item);
 
1699
    if (TASK_IS_ICON (match))
 
1700
    {
 
1701
      GObject * p = task_icon_get_proxy (match);
 
1702
      if (p && G_IS_OBJECT(p))
 
1703
      {
 
1704
        g_object_set (item,
 
1705
                      "proxy",task_icon_get_proxy(match),
 
1706
                      NULL);
 
1707
        task_icon_append_item (match, item);
 
1708
      }
 
1709
      else
 
1710
      {
 
1711
        g_warning ("TaskIcon: Window closed before match");
 
1712
        return;
 
1713
      }
 
1714
    }
 
1715
    else
 
1716
    {
 
1717
      g_warning ("TaskIcon: not an icon... bailing");
 
1718
      return;
 
1719
    }
1503
1720
  }
1504
1721
  else
1505
1722
  {
1507
1724
    icon = task_icon_new (AWN_APPLET (manager));
1508
1725
 
1509
1726
    found_desktop = search_for_desktop (TASK_ICON(icon),item,TRUE);
 
1727
    g_object_set (item,
 
1728
              "proxy",task_icon_get_proxy(TASK_ICON(icon)),
 
1729
              NULL);
1510
1730
    if (found_desktop)
1511
1731
    {
1512
1732
      TaskItem * launcher = get_launcher (manager,found_desktop);
1513
1733
      if (launcher)
1514
1734
      {
1515
 
        task_icon_append_ephemeral_item (TASK_ICON (icon), launcher);
1516
 
      }
 
1735
        if (task_icon_count_items (TASK_ICON (icon))==0)
 
1736
        {
 
1737
          g_object_unref (task_icon_get_proxy(TASK_ICON(icon)));
 
1738
        }                                 
 
1739
        task_icon_append_item (TASK_ICON (icon), launcher);
 
1740
        task_icon_append_item (TASK_ICON (icon), item);
 
1741
      }
 
1742
      else
 
1743
      {
 
1744
        task_icon_append_item (TASK_ICON (icon), item);
 
1745
      }
 
1746
    }
 
1747
    else
 
1748
    {
 
1749
      task_icon_append_item (TASK_ICON (icon), item);
1517
1750
    }
1518
1751
    
1519
1752
    if ( !found_desktop)
1520
1753
    {
1521
1754
      g_signal_connect (item,"name-changed",G_CALLBACK(window_name_changed_cb), icon);
1522
1755
    }
1523
 
    task_icon_append_item (TASK_ICON (icon), item);
1524
1756
    task_manager_add_icon (manager,TASK_ICON (icon));
1525
1757
  }
1526
1758
}
1573
1805
 
1574
1806
  _wnck_get_wmclass (wnck_window_get_xid (window),
1575
1807
                     &res_name, &class_name);
1576
 
  if (get_special_wait_from_window_data (res_name, 
1577
 
                                         class_name,
1578
 
                                         wnck_window_get_name(window) ) )
1579
 
  {
1580
 
    win_timeout_data = g_malloc (sizeof (WindowOpenTimeoutData));
1581
 
    win_timeout_data->window = window;
1582
 
    win_timeout_data->manager = manager;    
1583
 
    g_signal_connect (window,"name-changed",G_CALLBACK(process_window_opened),manager);
1584
 
    g_timeout_add (2000,(GSourceFunc)_wait_for_name_change_timeout,win_timeout_data);
1585
 
  }
1586
 
  else
1587
 
  {
1588
 
    process_window_opened (window,manager);
 
1808
  if ( g_strcmp0(res_name,"awn-applet") != 0)
 
1809
  {
 
1810
    if (get_special_wait_from_window_data (res_name, 
 
1811
                                           class_name,
 
1812
                                           wnck_window_get_name(window) ) )
 
1813
    {
 
1814
      win_timeout_data = g_malloc (sizeof (WindowOpenTimeoutData));
 
1815
      win_timeout_data->window = window;
 
1816
      win_timeout_data->manager = manager;    
 
1817
      g_signal_connect (window,"name-changed",G_CALLBACK(process_window_opened),manager);
 
1818
      g_timeout_add (2000,(GSourceFunc)_wait_for_name_change_timeout,win_timeout_data);
 
1819
    }
 
1820
    else
 
1821
    {
 
1822
      process_window_opened (window,manager);
 
1823
    }
1589
1824
  }
1590
1825
  g_free (res_name);
1591
1826
  g_free (class_name);  
1734
1969
  g_value_array_free (launcher_paths);
1735
1970
}
1736
1971
 
 
1972
static void
 
1973
task_manager_intellihide_change_cb (const char* group, 
 
1974
                                    const char* key, 
 
1975
                                    GValue* value, 
 
1976
                                    int * user_data)
 
1977
{
 
1978
  *user_data = g_value_get_int (value);
 
1979
}
 
1980
 
1737
1981
/*
1738
1982
 * Checks when launchers got added/removed in the list in gconf/file.
1739
1983
 * It removes the launchers from the task-icons and add those
1740
1984
 * that aren't already on the bar.
1741
1985
 */
1742
1986
static void
1743
 
task_manager_refresh_launcher_paths (TaskManager *manager,
1744
 
                                     GValueArray *list)
 
1987
task_manager_refresh_launcher_paths (TaskManager *manager, GValueArray *list)
1745
1988
{
1746
1989
  TaskManagerPrivate *priv;
 
1990
  gboolean ephemeral = TRUE;
1747
1991
 
1748
1992
  g_return_if_fail (TASK_IS_MANAGER (manager));
1749
1993
  priv = manager->priv;
 
1994
 
 
1995
  task_manager_add_icon_hide (manager);
1750
1996
  /*
1751
1997
   Find launchers in the the launcher list do not yet have a TaskIcon and 
1752
1998
   add them
1764
2010
         icon_iter = icon_iter->next)
1765
2011
    {
1766
2012
      GSList *items = task_icon_get_items (TASK_ICON (icon_iter->data));
1767
 
 
 
2013
      TaskItem  *launcher = NULL;
 
2014
      
1768
2015
      for (GSList *item_iter = items;
1769
2016
           item_iter != NULL;
1770
2017
           item_iter = item_iter->next)
1776
2023
                       path) == 0)
1777
2024
        {
1778
2025
          gint cur_pos;
 
2026
          launcher = item;
1779
2027
          found = TRUE;
1780
2028
          cur_pos = g_slist_position (priv->icons,icon_iter);
1781
2029
          if (cur_pos != (gint)idx)
1788
2036
          break;
1789
2037
        }
1790
2038
      }
1791
 
      if (found)
 
2039
      if (found && launcher)
1792
2040
      {
 
2041
        ephemeral = task_icon_is_ephemeral (icon_iter->data);
 
2042
        if (ephemeral) /*then it shouldn't be*/
 
2043
        {
 
2044
          g_object_set (G_OBJECT(task_icon_get_launcher (icon_iter->data)),
 
2045
                          "proxy",task_icon_get_proxy (icon_iter->data),
 
2046
                          NULL);
 
2047
          icon_iter = priv->icons;
 
2048
        }
1793
2049
        break;
1794
2050
      }
1795
2051
    }
1796
2052
    if (!found)
1797
 
    {
1798
 
      TaskItem  *launcher = NULL;
 
2053
    {      
1799
2054
      GtkWidget *icon;
1800
2055
 
1801
2056
      if (usable_desktop_file_from_path (path) )
1802
2057
      {
 
2058
        TaskItem  *launcher = NULL;
1803
2059
        launcher = task_launcher_new_for_desktop_file (AWN_APPLET(manager),path);
1804
2060
        if (launcher)
1805
2061
        {
1806
2062
          icon = task_icon_new (AWN_APPLET (manager));
 
2063
          g_object_set (G_OBJECT(launcher),
 
2064
                        "proxy",task_icon_get_proxy (TASK_ICON(icon)),
 
2065
                        NULL);
1807
2066
          task_icon_append_item (TASK_ICON (icon), launcher);
1808
2067
          gtk_container_add (GTK_CONTAINER (priv->box), icon);
1809
2068
          gtk_box_reorder_child (GTK_BOX (priv->box), icon, idx);
1865
2124
    } 
1866
2125
    if (launcher && !found)
1867
2126
    {
1868
 
      if ( !task_icon_count_ephemeral_items (icon_iter->data) )
 
2127
      ephemeral = task_icon_is_ephemeral (icon_iter->data);
 
2128
      if (!ephemeral) /*then it should be*/
1869
2129
      {
1870
 
        /*if there are only ephemeral items in the icon then it will 
1871
 
         trigger it's removal.  Otherwise the it will be removed when it is
1872
 
         no longer managing ay TaskWindows*/        
1873
 
        task_icon_increment_ephemeral_count (icon_iter->data);
 
2130
        g_object_set (G_OBJECT(task_icon_get_launcher (icon_iter->data)),
 
2131
                        "proxy",NULL,
 
2132
                        NULL);
1874
2133
        icon_iter = priv->icons;
1875
2134
      }
1876
2135
    }
1964
2223
    if (!launcher ) /* no launcher...  need to do matches on these eventually TODO */
1965
2224
    {
1966
2225
      continue;
1967
 
    }/* Is i an existing permanent launcher... if so then ignore.*/
1968
 
    else if ( task_icon_count_ephemeral_items (icon) == 0)
 
2226
    }
 
2227
    /* Is i an existing permanent launcher... if so then ignore.*/
 
2228
    else if ( !task_icon_is_ephemeral (icon))
1969
2229
    {
1970
2230
      continue;
1971
2231
    }
2094
2354
    TaskIcon  * icon;
2095
2355
    icon = i->data;
2096
2356
    launcher = GTK_WIDGET(task_icon_get_launcher (icon));
2097
 
    if (launcher && (task_icon_count_ephemeral_items (icon) == 0) )
 
2357
 
 
2358
    if (launcher)
2098
2359
    {
2099
2360
      task_manager_regroup_launcher_icon (manager,icon);      
2100
 
    }
 
2361
    }    
2101
2362
  }
2102
2363
 
2103
2364
  /* Find the ephemeral launchers and regroup them */
2107
2368
    TaskIcon  * icon;
2108
2369
    icon = i->data;
2109
2370
    launcher = GTK_WIDGET(task_icon_get_launcher (icon));
2110
 
    if (launcher && (task_icon_count_ephemeral_items (icon) != 0) )
 
2371
    if (launcher )
2111
2372
    {
2112
2373
      task_manager_regroup_launcher_icon (manager,icon);      
2113
2374
    }
2434
2695
  return region;
2435
2696
}
2436
2697
 
2437
 
/* 
2438
 
 Governs the panel autohide when Intellihide is enabled.
2439
 
 If a window in the relevant window list intersects with the awn panel then
2440
 
 autohide will be uninhibited otherwise it will be inhibited.
2441
 
 */
2442
 
 
2443
2698
static void
2444
 
task_manager_check_for_intersection (TaskManager * manager,
 
2699
task_manager_check_for_panel_instance_intersection (TaskManager * manager,
 
2700
                                     TaskManagerAwnPanelInfo * panel_info,
2445
2701
                                     WnckWorkspace * space,
2446
2702
                                     WnckApplication * app)
2447
2703
{
2450
2706
  GList * iter;
2451
2707
  gboolean  intersect = FALSE;
2452
2708
  GdkRectangle awn_rect;
2453
 
  gint depth;
2454
 
  gint64 xid; 
2455
2709
  GdkRegion * updated_region;
2456
 
  
2457
2710
  g_return_if_fail (TASK_IS_MANAGER (manager));
2458
2711
  priv = manager->priv;
2459
2712
 
2460
 
  /*
2461
 
   Generate a GdkRegion for the awn panel_size
2462
 
   */
2463
 
  if (!priv->awn_gdk_window)
2464
 
  {
2465
 
    g_object_get (manager, "panel-xid", &xid, NULL);    
2466
 
    priv->awn_gdk_window = gdk_window_foreign_new ( xid);
2467
 
  }
2468
 
  g_return_if_fail (priv->awn_gdk_window);
2469
 
  gdk_window_get_geometry (priv->awn_gdk_window,&awn_rect.x,
2470
 
                           &awn_rect.y,&awn_rect.width,
2471
 
                           &awn_rect.height,&depth);  
 
2713
  gdk_error_trap_push ();
 
2714
 
 
2715
  gdk_window_get_position (panel_info->foreign_window,&awn_rect.x,&awn_rect.y);
 
2716
  gdk_drawable_get_size (panel_info->foreign_window,&awn_rect.width,&awn_rect.height);
2472
2717
  /*
2473
2718
   gdk_window_get_geometry gives us an x,y or 0,0
2474
2719
   Fix that using get root origin.
2475
2720
   */
2476
 
  gdk_window_get_root_origin (priv->awn_gdk_window,&awn_rect.x,&awn_rect.y);
 
2721
  gdk_window_get_root_origin (panel_info->foreign_window,&awn_rect.x,&awn_rect.y);
2477
2722
  /*
2478
2723
   We cache the region for reuse for situations where the input mask is an empty
2479
2724
   region when the panel is hidden.  In that case we reuse the last good 
2480
2725
   region.
2481
2726
   */
2482
 
  updated_region = xutils_get_input_shape (priv->awn_gdk_window);
 
2727
  updated_region = xutils_get_input_shape (panel_info->foreign_window);
2483
2728
  g_return_if_fail (updated_region);
2484
2729
  if (gdk_region_empty(updated_region))
2485
2730
  {
2487
2732
  }
2488
2733
  else
2489
2734
  {
2490
 
    if (priv->awn_gdk_region)
 
2735
    if (panel_info->foreign_region)
2491
2736
    {
2492
 
      gdk_region_destroy (priv->awn_gdk_region);
 
2737
      gdk_region_destroy (panel_info->foreign_region);
2493
2738
    }
2494
 
    priv->awn_gdk_region = updated_region; 
2495
 
    gdk_region_offset (priv->awn_gdk_region,awn_rect.x,awn_rect.y);    
 
2739
    panel_info->foreign_region = updated_region; 
 
2740
    gdk_region_offset (panel_info->foreign_region,awn_rect.x,awn_rect.y);    
2496
2741
  }
2497
2742
  
2498
2743
  /*
2499
2744
   Get the list of windows to check for intersection
2500
2745
   */
2501
 
  switch (priv->intellihide_mode)
 
2746
  switch (panel_info->intellihide_mode)
2502
2747
  {
2503
2748
    case INTELLIHIDE_WORKSPACE:
2504
2749
      windows = wnck_screen_get_windows (priv->screen);
2506
2751
    case INTELLIHIDE_GROUP:  /*TODO... Implement this for now same as app*/
2507
2752
    case INTELLIHIDE_APP:
2508
2753
    default:
2509
 
      windows = wnck_application_get_windows (app);
 
2754
      if (app)
 
2755
      {
 
2756
        windows = wnck_application_get_windows (app);
 
2757
      }
 
2758
      else
 
2759
      {
 
2760
        windows = wnck_screen_get_windows (priv->screen);
 
2761
      }
2510
2762
      break;
2511
2763
  }
2512
2764
  
2543
2795
                              &win_rect.y,&win_rect.width,
2544
2796
                              &win_rect.height);
2545
2797
 
2546
 
    if (gdk_region_rect_in (priv->awn_gdk_region, &win_rect) != 
 
2798
    if (gdk_region_rect_in (panel_info->foreign_region, &win_rect) != 
2547
2799
          GDK_OVERLAP_RECTANGLE_OUT)
2548
2800
    {
2549
2801
#ifdef DEBUG
2558
2810
  /*
2559
2811
   Allow panel to hide (if necessary)
2560
2812
   */
2561
 
  if (intersect && priv->autohide_cookie)
 
2813
  if (intersect && panel_info->autohide_cookie)
2562
2814
  {     
2563
 
    awn_applet_uninhibit_autohide (AWN_APPLET(manager), priv->autohide_cookie);
 
2815
    task_manager_panel_connector_uninhibit_autohide (panel_info->connector, panel_info->autohide_cookie);
2564
2816
#ifdef DEBUG
2565
 
    g_debug ("me eat cookie: %u",priv->autohide_cookie);
 
2817
    g_debug ("me eat cookie: %u",panel_info->autohide_cookie);
2566
2818
#endif
2567
 
    priv->autohide_cookie = 0;
 
2819
    panel_info->autohide_cookie = 0;
2568
2820
  }
2569
2821
  
2570
2822
  /*
2571
2823
   Inhibit Hide if not already doing so
2572
2824
   */
2573
 
  if (!intersect && !priv->autohide_cookie)
 
2825
  if (!intersect && !panel_info->autohide_cookie)
2574
2826
  {
2575
 
    priv->autohide_cookie = awn_applet_inhibit_autohide (AWN_APPLET(manager), "Intellihide");
 
2827
    gchar * identifier = g_strdup_printf ("Intellihide:applet_conector=%p",panel_info->connector);
 
2828
    panel_info->autohide_cookie = task_manager_panel_connector_inhibit_autohide (panel_info->connector, identifier);
 
2829
    g_free (identifier);
2576
2830
#ifdef DEBUG    
2577
 
    g_debug ("cookie is %u",priv->autohide_cookie);
 
2831
    g_debug ("cookie is %u",panel_info->autohide_cookie);
2578
2832
#endif
2579
2833
  }
2580
 
 
 
2834
  gdk_error_trap_pop();
 
2835
}
 
2836
 
 
2837
static gboolean
 
2838
_waiting_for_panel_dbus (TaskManager * manager)
 
2839
{
 
2840
  TaskManagerPrivate  *priv;
 
2841
  
 
2842
  g_return_val_if_fail (TASK_IS_MANAGER (manager),FALSE);
 
2843
  priv = manager->priv;
 
2844
  
 
2845
  task_manager_check_for_intersection (manager,
 
2846
                                       wnck_screen_get_active_workspace (priv->screen),
 
2847
                                       wnck_application_get (wnck_window_get_xid(wnck_screen_get_active_window (priv->screen))));
 
2848
  return FALSE;
 
2849
}
 
2850
/* 
 
2851
 Governs the panel autohide when Intellihide is enabled.
 
2852
 If a window in the relevant window list intersects with the awn panel then
 
2853
 autohide will be uninhibited otherwise it will be inhibited.
 
2854
 */
 
2855
 
 
2856
static void
 
2857
task_manager_check_for_intersection (TaskManager * manager,
 
2858
                                     WnckWorkspace * space,
 
2859
                                     WnckApplication * app)
 
2860
{
 
2861
  TaskManagerPrivate  *priv;
 
2862
  gint64 xid;
 
2863
  GHashTableIter iter;
 
2864
  gpointer key,value;
 
2865
  
 
2866
  g_return_if_fail (TASK_IS_MANAGER (manager));
 
2867
  priv = manager->priv;
 
2868
 
 
2869
  g_hash_table_iter_init (&iter, priv->intellihide_panel_instances);
 
2870
  while (g_hash_table_iter_next (&iter, &key, &value) )
 
2871
  {
 
2872
    TaskManagerAwnPanelInfo * panel_info = value;
 
2873
    g_object_get (panel_info->connector, "panel-xid", &xid, NULL);
 
2874
    if (!xid)
 
2875
    {
 
2876
      g_timeout_add (1000,(GSourceFunc)_waiting_for_panel_dbus,manager);
 
2877
    }
 
2878
    else
 
2879
    {
 
2880
      if (!panel_info->foreign_window)
 
2881
      {
 
2882
        panel_info->foreign_window = gdk_window_foreign_new ( xid);
 
2883
      }
 
2884
      if (panel_info->intellihide_mode)
 
2885
      {
 
2886
        task_manager_check_for_panel_instance_intersection(manager,
 
2887
                                                         panel_info,
 
2888
                                                         space,
 
2889
                                                         app);
 
2890
      }
 
2891
      else if ( !panel_info->intellihide_mode && panel_info->autohide_cookie)
 
2892
      {
 
2893
        task_manager_panel_connector_uninhibit_autohide (panel_info->connector, panel_info->autohide_cookie);
 
2894
        panel_info->autohide_cookie = 0;
 
2895
      }
 
2896
    }                                                           
 
2897
  }
 
2898
  return;
2581
2899
}
2582
2900
 
2583
2901
/*
2596
2914
 
2597
2915
  g_return_if_fail (TASK_IS_MANAGER (manager));
2598
2916
  priv = manager->priv;
2599
 
 
2600
 
  if (!priv->intellihide)
2601
 
  {
2602
 
/*    g_warning ("%s: Intellihide callback invoked with Intellihide off",__func__);*/
2603
 
    return;
2604
 
  }
2605
2917
  
2606
2918
  win = wnck_screen_get_active_window (screen);
2607
2919
  if (!win)
2612
2924
     we had intersection and the panel was hidden, it will continue hide.
2613
2925
     So inhibit the autohide if there is no active window.
2614
2926
     */
 
2927
    task_manager_check_for_intersection (manager,
 
2928
                                         wnck_screen_get_active_workspace(screen),
 
2929
                                         NULL);
 
2930
/*
2615
2931
    if (!priv->autohide_cookie)
2616
2932
    {
2617
2933
      priv->autohide_cookie = awn_applet_inhibit_autohide (AWN_APPLET(manager), "Intellihide");
2618
2934
#ifdef DEBUG    
2619
2935
      g_debug ("%s: cookie is %u",__func__,priv->autohide_cookie);
2620
2936
#endif
2621
 
    }
 
2937
    }*/
2622
2938
    return;
2623
2939
  }
2624
2940
  app = wnck_window_get_application (win);
2641
2957
 
2642
2958
  g_return_if_fail (TASK_IS_MANAGER (manager));
2643
2959
  priv = manager->priv;
2644
 
  if (!priv->intellihide)
2645
 
  {
2646
 
/*    g_warning ("%s: Intellihide callback invoked with Intellihide off",__func__);    */
2647
 
    return;
2648
 
  }
 
2960
 
2649
2961
  win = wnck_screen_get_active_window (screen);
2650
2962
  if (!win)
2651
2963
  {
2652
 
    if (!priv->autohide_cookie)
2653
 
    {
2654
 
      priv->autohide_cookie = awn_applet_inhibit_autohide (AWN_APPLET(manager), "Intellihide");
2655
 
#ifdef DEBUG    
2656
 
      g_debug ("%s: cookie is %u",__func__,priv->autohide_cookie);
2657
 
#endif
2658
 
    }    
 
2964
    task_manager_check_for_intersection (manager,
 
2965
                                         wnck_screen_get_active_workspace(screen),
 
2966
                                         NULL);
2659
2967
    return;
2660
2968
  }
2661
2969
  
2671
2979
  WnckWindow          *win;
2672
2980
  WnckApplication     *app;
2673
2981
  WnckWorkspace       *space;
 
2982
  
2674
2983
  g_return_if_fail (TASK_IS_MANAGER (manager));
2675
2984
  priv = manager->priv;
2676
 
  if (!priv->intellihide)
2677
 
  {
2678
 
/*    g_warning ("%s: Intellihide callback invoked with Intellihide off",__func__);*/
2679
 
    return;
2680
 
  }
2681
2985
  win = wnck_screen_get_active_window (priv->screen);
2682
2986
  if (!win)
2683
2987
  {
2703
3007
  WnckWorkspace       *space;
2704
3008
  g_return_if_fail (TASK_IS_MANAGER (manager));
2705
3009
  priv = manager->priv;
2706
 
  if (!priv->intellihide)
2707
 
  {
2708
 
/*    g_warning ("%s: Intellihide callback invoked with Intellihide off",__func__);*/
2709
 
    return;
2710
 
  }
2711
3010
  win = wnck_screen_get_active_window (priv->screen);
2712
3011
  if (!win)
2713
3012
  {
2730
3029
  g_return_if_fail (TASK_IS_MANAGER (manager));
2731
3030
  priv = manager->priv;
2732
3031
   
2733
 
  if (!priv->intellihide)
2734
 
  {
2735
 
    return;
2736
 
  }
2737
3032
  win = wnck_screen_get_active_window (priv->screen);
2738
3033
  if (!win)
2739
3034
  {
2944
3239
  }
2945
3240
}
2946
3241
 
 
3242
void
 
3243
task_manager_add_icon_show ( TaskManager * manager)
 
3244
{
 
3245
  TaskManagerPrivate *priv;
 
3246
  g_return_if_fail (TASK_IS_MANAGER (manager));
 
3247
  
 
3248
  priv = manager->priv;
 
3249
 
 
3250
  if (priv->add_icon)
 
3251
  {
 
3252
    gtk_box_reorder_child (GTK_BOX(priv->box),priv->add_icon,-1);
 
3253
    gtk_widget_show_all (priv->add_icon);
 
3254
  }
 
3255
}
 
3256
 
 
3257
gboolean
 
3258
task_manager_add_icon_hide ( TaskManager * manager)
 
3259
{
 
3260
  TaskManagerPrivate *priv;
 
3261
  g_return_val_if_fail (TASK_IS_MANAGER (manager),FALSE);
 
3262
  
 
3263
  priv = manager->priv;
 
3264
  if (priv->add_icon)
 
3265
  {
 
3266
    gtk_widget_hide (priv->add_icon);
 
3267
    if (priv->add_icon_source)
 
3268
    {
 
3269
      g_source_remove (priv->add_icon_source);
 
3270
      priv->add_icon_source = 0;
 
3271
    }
 
3272
  }
 
3273
  return FALSE;
 
3274
}
2947
3275
 
2948
3276
/*
2949
3277
 * Position Icons through dragging
2963
3291
 
2964
3292
  priv = TASK_MANAGER_GET_PRIVATE (manager);
2965
3293
 
 
3294
  if (priv->add_icon_source)
 
3295
  {
 
3296
    g_source_remove (priv->add_icon_source);
 
3297
    priv->add_icon_source = 0;
 
3298
  }
 
3299
 
2966
3300
  g_return_if_fail(priv->dragged_icon != NULL);
2967
3301
 
2968
3302
  /* There was a timeout to check if the cursor left the bar */
3051
3385
_drag_dest_leave (TaskManager *manager, GtkWidget *icon)
3052
3386
{
3053
3387
  g_return_if_fail (TASK_IS_MANAGER (manager));
3054
 
 
 
3388
  TaskManagerPrivate *priv = TASK_MANAGER_GET_PRIVATE (manager);
 
3389
  if (priv->add_icon_source)
 
3390
  {
 
3391
    g_source_remove (priv->add_icon_source);
 
3392
  }
 
3393
  
 
3394
  priv->add_icon_source = g_timeout_add (4000,(GSourceFunc)task_manager_add_icon_hide,manager);
3055
3395
  /*
3056
 
  TaskManagerPrivate *priv = TASK_MANAGER_GET_PRIVATE (manager);
 
3396
  
3057
3397
 
3058
3398
  //FIXME: REMOVE OLD TIMER AND SET NEW ONE
3059
3399
  if(!priv->drag_timeout)
3129
3469
    Search the launcherlist for the following desktop file
3130
3470
    Place the moved desktop in front of it.
3131
3471
   */
3132
 
  if ( priv->dragged_icon && !task_icon_count_ephemeral_items (priv->dragged_icon))
3133
 
  {
3134
 
    g_assert (TASK_IS_ICON (priv->dragged_icon) );
 
3472
 
 
3473
  if (task_icon_is_ephemeral (priv->dragged_icon) )
 
3474
  {
 
3475
    priv->dragged_icon = NULL;
 
3476
    return;
 
3477
  }
 
3478
  
 
3479
  if ( priv->dragged_icon)
 
3480
  {
3135
3481
    launcher = TASK_LAUNCHER(task_icon_get_launcher (priv->dragged_icon));
3136
 
  }
3137
 
      
 
3482
  }  
 
3483
  
3138
3484
  if (launcher)
3139
3485
  {
3140
3486
    g_assert (TASK_IS_LAUNCHER(launcher));
3161
3507
            continue;
3162
3508
          }
3163
3509
          g_assert (TASK_IS_ICON (iter->data) );
 
3510
          if (task_icon_is_ephemeral (iter->data) )
 
3511
          {
 
3512
            continue;
 
3513
          }
3164
3514
          const TaskItem * item = task_icon_get_launcher (iter->data);
3165
 
          if (!item || task_icon_count_ephemeral_items (iter->data))
 
3515
 
 
3516
          if (!item )
3166
3517
          {
3167
3518
            continue;
3168
3519
          }
3182
3533
      path = g_value_dup_string (g_value_array_get_nth (launcher_paths, idx));
3183
3534
      if (g_strcmp0 (path,moved_desktop_file)==0)
3184
3535
      {
3185
 
        g_free (path);        
 
3536
        g_free (path);
3186
3537
        g_value_array_remove (launcher_paths,idx);
3187
3538
        if (!following_desktop_file)
3188
3539
        {
3249
3600
  g_signal_handlers_disconnect_by_func(icon, G_CALLBACK (_drag_dest_motion), manager);
3250
3601
  g_signal_handlers_disconnect_by_func(icon, G_CALLBACK (_drag_dest_leave), manager);
3251
3602
}
 
3603
 
 
3604
 
 
3605
static void 
 
3606
copy_over (const gchar *src, const gchar *dest)
 
3607
{
 
3608
  DesktopAgnosticVFSFile *from = NULL;
 
3609
  DesktopAgnosticVFSFile *to = NULL;
 
3610
  GError                 *error = NULL;
 
3611
 
 
3612
  from = desktop_agnostic_vfs_file_new_for_path (src, &error);
 
3613
  if (error)
 
3614
  {
 
3615
    goto copy_over_error;
 
3616
  }
 
3617
  to = desktop_agnostic_vfs_file_new_for_path (dest, &error);
 
3618
  if (error)
 
3619
  {
 
3620
    goto copy_over_error;
 
3621
  }
 
3622
 
 
3623
  desktop_agnostic_vfs_file_copy (from, to, TRUE, &error);
 
3624
 
 
3625
copy_over_error:
 
3626
 
 
3627
  if (error)
 
3628
  {
 
3629
    g_warning ("Unable to copy %s to %s: %s", src, dest, error->message);
 
3630
    g_error_free (error);
 
3631
  }
 
3632
 
 
3633
  if (to)
 
3634
  {
 
3635
    g_object_unref (to);
 
3636
  }
 
3637
  if (from)
 
3638
  {
 
3639
    g_object_unref (from);
 
3640
  }
 
3641
}
 
3642
 
 
3643
static void
 
3644
_icon_dest_drag_data_received (GtkWidget      *widget,
 
3645
                                   GdkDragContext *context,
 
3646
                                   gint            x,
 
3647
                                   gint            y,
 
3648
                                   GtkSelectionData *sdata,
 
3649
                                   guint           info,
 
3650
                                   guint           time_,
 
3651
                                   TaskManager     *manager)
 
3652
{
 
3653
  TaskManagerPrivate * priv;
 
3654
  GError          *error;
 
3655
  GdkAtom         target;
 
3656
  gchar           *target_name;
 
3657
  gchar           *sdata_data;
 
3658
  GStrv           tokens = NULL;
 
3659
  gchar           ** i;  
 
3660
 
 
3661
  g_return_if_fail (AWN_IS_THEMED_ICON (widget) );
 
3662
 
 
3663
  priv = TASK_MANAGER_GET_PRIVATE (manager);
 
3664
  task_manager_add_icon_hide (TASK_MANAGER(manager));
 
3665
  
 
3666
  target = gtk_drag_dest_find_target (widget, context, NULL);
 
3667
  target_name = gdk_atom_name (target);
 
3668
 
 
3669
  /* If it is dragging of the task icon, there is actually no data */
 
3670
  if (g_strcmp0("awn/task-icon", target_name) == 0)
 
3671
  {
 
3672
    gtk_drag_finish (context, TRUE, TRUE, time_);
 
3673
    return;
 
3674
  }
 
3675
  sdata_data = (gchar*)gtk_selection_data_get_data (sdata);
 
3676
 
 
3677
  /* If we are dealing with a desktop file, then we want to do something else
 
3678
   * FIXME: This is a crude way of checking
 
3679
   */
 
3680
  if (strstr (sdata_data, ".desktop"))
 
3681
  {
 
3682
    /*TODO move into a separate function */
 
3683
    tokens = g_strsplit  (sdata_data, "\n",-1);    
 
3684
    for (i=tokens; *i;i++)
 
3685
    {
 
3686
      gchar * filename = g_filename_from_uri ((gchar*) *i,NULL,NULL);
 
3687
      if (!filename && ((gchar *)*i))
 
3688
      {
 
3689
        filename = g_strdup ((gchar*)*i);
 
3690
      }
 
3691
      if (filename)
 
3692
      {
 
3693
        g_strstrip(filename);
 
3694
      }
 
3695
      if (filename && strlen(filename) && strstr (filename,".desktop"))
 
3696
      {
 
3697
        if (filename)
 
3698
        {
 
3699
          gboolean make_copy = FALSE;
 
3700
          struct stat stat_buf;
 
3701
          switch (priv->desktop_copy)
 
3702
          {
 
3703
            case DESKTOP_COPY_ALL:
 
3704
              make_copy = TRUE;
 
3705
              break;
 
3706
            case DESKTOP_COPY_OWNER:
 
3707
              g_stat (filename,&stat_buf);
 
3708
              if ( stat_buf.st_uid == getuid())
 
3709
              {
 
3710
                make_copy = TRUE;
 
3711
              }
 
3712
              break;
 
3713
            case DESKTOP_COPY_NONE:
 
3714
            default:
 
3715
              break;
 
3716
          }
 
3717
          if (make_copy)
 
3718
          {
 
3719
            gchar * launcher_dir = NULL;
 
3720
            gchar * file_basename;
 
3721
            gchar * dest;
 
3722
            launcher_dir = g_strdup_printf ("%s/.config/awn/launchers", 
 
3723
                                              g_get_home_dir ());
 
3724
            g_mkdir_with_parents (launcher_dir,0755); 
 
3725
            file_basename = g_path_get_basename (filename);
 
3726
            dest = g_strdup_printf("%s/%lu-%s",launcher_dir,(gulong)time(NULL),file_basename);
 
3727
            copy_over (filename,dest);
 
3728
            g_free (file_basename);
 
3729
            g_free (filename);
 
3730
            g_free (launcher_dir);
 
3731
            filename = dest;
 
3732
          }
 
3733
          task_manager_append_launcher (TASK_MANAGER(manager),filename);
 
3734
        }
 
3735
      }
 
3736
      if (filename)
 
3737
      {
 
3738
        g_free (filename);
 
3739
      }
 
3740
    }
 
3741
    g_strfreev (tokens);
 
3742
    gtk_drag_finish (context, TRUE, FALSE, time_);
 
3743
    return;
 
3744
  }
 
3745
 
 
3746
  error = NULL;
 
3747
  gtk_drag_finish (context, TRUE, FALSE, time_);
 
3748
}