-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtaskbar-widget.c
2893 lines (2378 loc) · 104 KB
/
taskbar-widget.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#ifdef HAVE_MATH_H
#include <math.h>
#endif
#define WNCK_I_KNOW_THIS_IS_UNSTABLE
#include <gtk/gtk.h>
#include <exo/exo.h>
#include <libwnck/libwnck.h>
#include <libxfce4panel/libxfce4panel.h>
#include <panel-private.h>
#include <panel-debug.h>
#ifdef GDK_WINDOWING_X11
#include <X11/Xlib.h>
#include <gdk/gdkx.h>
#include <X11/extensions/shape.h>
#endif
#include "taskbar-widget.h"
#include "hotkeys.h"
#define DEFAULT_BUTTON_SIZE (25)
#define DEFAULT_MAX_BUTTON_LENGTH (400)
#define DEFAULT_MENU_ICON_SIZE (16)
#define DEFAULT_MIN_BUTTON_LENGTH (DEFAULT_MAX_BUTTON_LENGTH / 4)
#define DEFAULT_ICON_LUCENCY (50)
#define DEFAULT_ELLIPSIZE_MODE (PANGO_ELLIPSIZE_END)
#define DEFAULT_MENU_MAX_WIDTH_CHARS (50)
#define ARROW_BUTTON_SIZE (20)
#define WIREFRAME_SIZE (5) /* same as xfwm4 */
#define DRAG_ACTIVATE_TIMEOUT (500)
#define command_SIZE (512)
#define TOKEN_BUFFER_SIZE (32)
/* locking helpers for taskbar->locked */
#define xfce_taskbar_lock(taskbar) G_STMT_START { XFCE_taskbar (taskbar)->locked++; } G_STMT_END
#define xfce_taskbar_unlock(taskbar) G_STMT_START { \
if (XFCE_taskbar (taskbar)->locked > 0) \
XFCE_taskbar (taskbar)->locked--; \
else \
panel_assert_not_reached (); \
} G_STMT_END
#define xfce_taskbar_is_locked(taskbar) (XFCE_taskbar (taskbar)->locked > 0)
#define xfce_taskbar_get_panel_plugin(taskbar) gtk_widget_get_ancestor (GTK_WIDGET (taskbar), XFCE_TYPE_PANEL_PLUGIN)
#define xfce_taskbar_horizontal(taskbar) ((taskbar)->horizontal)
#define xfce_taskbar_filter_monitors(taskbar) (!(taskbar)->all_monitors && (taskbar)->monitor_geometry.width != -1)
#define xfce_taskbar_geometry_set_invalid(taskbar) ((taskbar)->monitor_geometry.width = -1)
#define xfce_taskbar_geometry_has_point(taskbar, x, y) ( \
(x) >= ((taskbar)->monitor_geometry.x) \
&& (x) < ((taskbar)->monitor_geometry.x + (taskbar)->monitor_geometry.width) \
&& (y) >= ((taskbar)->monitor_geometry.y) \
&& (y) < ((taskbar)->monitor_geometry.y + (taskbar)->monitor_geometry.height))
enum
{
PROP_0,
PROP_INCLUDE_ALL_WORKSPACES,
PROP_INCLUDE_ALL_MONITORS,
PROP_SWITCH_WORKSPACE_ON_UNMINIMIZE,
PROP_SHOW_ONLY_MINIMIZED,
PROP_SHOW_WIREFRAMES,
PROP_SHOW_HANDLE,
PROP_SHOW_INSTANCES_HOVER,
PROP_DRAG_BUTTON,
PROP_FLAT_BUTTONS,
};
enum {LEFTMOUSE=1, MIDMOUSE=2, RIGHTMOUSE=3} ;
enum { HOVER_DISPLAY_COOLOFF=200, GROUP_ICON_HOVER_TIMEOUT=250 } ;
struct _XfceTaskBarClass
{
GtkContainerClass __parent__;
};
struct _XfceTaskBar
{
GtkContainer __parent__;
/* lock counter */
gint locked;
/* the screen of this taskbar */
WnckScreen *screen;
GdkScreen *gdk_screen;
/* window children in the taskbar */
GList *wgroups;
/* windows we monitor, but that are excluded from the taskbar */
GSList *skipped_windows;
/* classgroups of all the windows in the taskbar */
GHashTable *groups;
/* flag to indicate in-progress drag */
gboolean dragactive ;
/* timestamp for filtering glitchy enter events generated during drag and drop */
guint dragtimestamp ;
/* size of the panel plugin */
gint size;
/* orientation of the taskbar */
guint horizontal : 1;
/* whether we show windows from all workspaces or
* only the active workspace */
guint all_workspaces : 1;
/* whether we switch to another workspace when we try to
* unminimize a window on another workspace */
guint switch_workspace : 1;
/* whether we only show monimized windows in the
* taskbar */
guint only_minimized : 1;
/* whether we only show windows that are in the geometry of
* the monitor the taskbar is on */
guint all_monitors : 1;
GdkRectangle monitor_geometry;
/* whether we show wireframes when hovering a button in
* the taskbar */
guint show_wireframes : 1;
/* icon geometries update timeout */
guint update_icon_geometries_id;
/* idle monitor geometry update */
guint update_monitor_geometry_id;
/* dummy properties */
guint show_handle : 1;
guint show_instances_hover : 1;
guint drag_button; /* Middle */
guint flat_buttons : 1;
guint unique_id_counter ;
gchar *rc_path ;
HotkeysHandler *hotkeys_handler;
#ifdef GDK_WINDOWING_X11
// wireframe window
Window wireframe_window;
#endif
// gtk style properties
gint max_button_length;
gint min_button_length;
gint max_button_size;
PangoEllipsizeMode ellipsize_mode;
gint minimized_icon_lucency;
gint menu_icon_size;
gint menu_max_width_chars;
gint n_group_icons;
};
typedef struct _XfceTaskBarGroup XfceTaskBarGroup;
typedef struct _XfceTaskBarWNode XfceTaskBarWNode;
struct _XfceTaskBarWNode
{
XfceTaskBar *taskbar;
GtkWidget *icon;
GtkWidget *label;
WnckWindow *window;
gchar *group_name;
XfceTaskBarGroup *group ;
gboolean visible ;
/* last activated */
guint64 timestamp;
};
struct _XfceTaskBarGroup
{
XfceTaskBar *taskbar;
GtkWidget *button;
GtkWidget *align;
GtkWidget *icon;
GdkPixbuf *pixbuf ;
GSList *wnodes;
gchar *window_class_name ;
guint unique_id ;
gboolean pinned ;
gchar *command ;
guint hover_timeout ;
guint hover_visible_timestamp ;
};
#define DISABLE_HOVER_TIMEOUT(group) if(group->hover_timeout != 0) {g_source_remove(group->hover_timeout); group->hover_timeout=0;}
static const GtkTargetEntry source_targets[] =
{
{ "application/x-wnck-window-id", 0, 0 }
};
static void xfce_taskbar_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
static void xfce_taskbar_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
static void xfce_taskbar_finalize (GObject *object);
static void xfce_taskbar_size_request (GtkWidget *widget, GtkRequisition *requisition);
static void xfce_taskbar_size_allocate (GtkWidget *widget, GtkAllocation *allocation);
static void xfce_taskbar_style_set (GtkWidget *widget, GtkStyle *previous_style);
static void xfce_taskbar_realize (GtkWidget *widget);
static void xfce_taskbar_unrealize (GtkWidget *widget);
static void xfce_taskbar_remove (GtkContainer *container, GtkWidget *widget);
static void xfce_taskbar_forall (GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data);
static GType xfce_taskbar_child_type (GtkContainer *container);
static void xfce_taskbar_connect_screen (XfceTaskBar*taskbar);
static void xfce_taskbar_disconnect_screen (XfceTaskBar *taskbar);
static void xfce_taskbar_gdk_screen_changed (GdkScreen *gdk_screen, XfceTaskBar *taskbar);
static void xfce_taskbar_active_window_changed (WnckScreen *screen, WnckWindow *previous_window, XfceTaskBar *taskbar);
static void xfce_taskbar_active_workspace_changed (WnckScreen *screen, WnckWorkspace *previous_workspace, XfceTaskBar *taskbar);
static void xfce_taskbar_window_added (WnckScreen *screen, WnckWindow *window, XfceTaskBar *taskbar);
static void xfce_taskbar_window_removed (WnckScreen *screen, WnckWindow *window, XfceTaskBar *taskbar);
static void xfce_taskbar_viewports_changed (WnckScreen *screen, XfceTaskBar *taskbar);
static gboolean xfce_taskbar_update_icon_geometries (gpointer data);
static void xfce_taskbar_skipped_windows_state_changed (WnckWindow *window, WnckWindowState changed_state, WnckWindowState new_state, XfceTaskBar *taskbar);
static void xfce_taskbar_update_icon_geometries_destroyed (gpointer data);
// wireframe
#ifdef GDK_WINDOWING_X11
static void xfce_taskbar_wireframe_hide (XfceTaskBar *taskbar);
static void xfce_taskbar_wireframe_destroy (XfceTaskBar *taskbar);
static void xfce_taskbar_wireframe_update (XfceTaskBar *taskbar, XfceTaskBarWNode *child);
#endif
// taskbar buttons
static inline gboolean xfce_taskbar_button_visible (XfceTaskBarWNode *child, WnckWorkspace *active_ws);
static GtkWidget* xfce_taskbar_button_proxy_menu_item (XfceTaskBarWNode *child, gboolean allow_wireframe);
static void xfce_taskbar_button_activate (XfceTaskBarWNode *child, guint32 timestamp);
static XfceTaskBarWNode* xfce_taskbar_wnode_new (WnckWindow *window, XfceTaskBar *taskbar);
static void xfce_taskbar_wnode_del (XfceTaskBarWNode *wnode);
// taskbar group buttons
static int xfce_taskbar_group_visible_count (XfceTaskBarGroup *group, WnckWorkspace *active_ws);
static void xfce_taskbar_group_update_visibility (XfceTaskBarGroup *group);
static void xfce_taskbar_group_button_remove (XfceTaskBarGroup *group);
static void xfce_taskbar_group_button_add_window (XfceTaskBarGroup *group, XfceTaskBarWNode *window_child);
static gboolean xfce_taskbar_group_button_enter_event (GtkWidget *button, GdkEvent *event, XfceTaskBarGroup *group);
static gboolean xfce_taskbar_group_button_leave_event (GtkWidget *button, GdkEvent *event, XfceTaskBarGroup *group);
static void xfce_taskbar_group_button_menu_destroy (GtkWidget *menu_widget, XfceTaskBarGroup *group);
static void xfce_taskbar_disable_group_enter_event(XfceTaskBar *taskbar);
static void xfce_taskbar_enable_group_enter_event(XfceTaskBar *taskbar);
static XfceTaskBarGroup* xfce_taskbar_group_button_new (const char *, XfceTaskBar *taskbar);
// pinning functions
static void xfce_taskbar_group_button_toggle_pinned (XfceTaskBarGroup *group);
static void xfce_taskbar_group_button_launch_pinned (XfceTaskBarGroup *group);
static void xfce_taskbar_group_button_build_launch_menu (XfceTaskBarGroup *group, GtkWidget *menu, gboolean use_sep);
static void xfce_taskbar_group_button_build_pin_menu (XfceTaskBarGroup *group, GtkWidget *menu);
static void cache_pinned_configuration (XfceTaskBar *taskbar);
//hover menu functions
static gboolean trigger_hover_menu_timeout(GtkWidget *widget, GdkEvent *event, gpointer menu_ptr);
static gboolean xfce_taskbar_hover_menu_leave(GtkWidget *widget, GdkEvent *event, gpointer menu_ptr);
static gboolean xfce_taskbar_hover_menu_enter(GtkWidget *widget, GdkEvent *event, gpointer menu_ptr);
static gboolean xfce_taskbar_hover_menu_timeout(gpointer menu_ptr);
static gboolean xfce_taskbar_group_button_hover_timeout(gpointer group_ptr);
static void xfce_taskbar_activate_hover_menu(GtkWidget *widget, XfceTaskBarGroup *group, size_t mouse_button);
static void xfce_taskbar_disable_hover_menu_timeout(GtkWidget *menu_widget);
// potential public functions
static void xfce_taskbar_set_include_all_workspaces (XfceTaskBar *taskbar, gboolean all_workspaces);
static void xfce_taskbar_set_include_all_monitors (XfceTaskBar *taskbar, gboolean all_monitors);
static void xfce_taskbar_set_show_only_minimized (XfceTaskBar *taskbar, gboolean only_minimized);
static void xfce_taskbar_set_show_wireframes (XfceTaskBar *taskbar, gboolean show_wireframes);
G_DEFINE_TYPE (XfceTaskBar, xfce_taskbar, GTK_TYPE_CONTAINER)
static GtkIconSize menu_icon_size = GTK_ICON_SIZE_INVALID;
static void xfce_taskbar_class_init (XfceTaskBarClass *klass)
{
GObjectClass *gobject_class;
GtkWidgetClass *gtkwidget_class;
GtkContainerClass *gtkcontainer_class;
gobject_class = G_OBJECT_CLASS (klass);
gobject_class->get_property = xfce_taskbar_get_property;
gobject_class->set_property = xfce_taskbar_set_property;
gobject_class->finalize = xfce_taskbar_finalize;
gtkwidget_class = GTK_WIDGET_CLASS (klass);
gtkwidget_class->size_request = xfce_taskbar_size_request;
gtkwidget_class->size_allocate = xfce_taskbar_size_allocate;
gtkwidget_class->style_set = xfce_taskbar_style_set;
gtkwidget_class->realize = xfce_taskbar_realize;
gtkwidget_class->unrealize = xfce_taskbar_unrealize;
gtkcontainer_class = GTK_CONTAINER_CLASS (klass);
gtkcontainer_class->add = NULL;
gtkcontainer_class->remove = xfce_taskbar_remove;
gtkcontainer_class->forall = xfce_taskbar_forall;
gtkcontainer_class->child_type = xfce_taskbar_child_type;
g_object_class_install_property (gobject_class, PROP_INCLUDE_ALL_WORKSPACES, g_param_spec_boolean ("include-all-workspaces", NULL, NULL, FALSE, EXO_PARAM_READWRITE));
g_object_class_install_property (gobject_class, PROP_INCLUDE_ALL_MONITORS, g_param_spec_boolean ("include-all-monitors", NULL, NULL, TRUE, EXO_PARAM_READWRITE));
g_object_class_install_property (gobject_class, PROP_SWITCH_WORKSPACE_ON_UNMINIMIZE, g_param_spec_boolean ("switch-workspace-on-unminimize", NULL, NULL, TRUE, EXO_PARAM_READWRITE));
g_object_class_install_property (gobject_class, PROP_SHOW_ONLY_MINIMIZED, g_param_spec_boolean ("show-only-minimized", NULL, NULL, FALSE, EXO_PARAM_READWRITE));
g_object_class_install_property (gobject_class, PROP_SHOW_WIREFRAMES, g_param_spec_boolean ("show-wireframes", NULL, NULL, FALSE, EXO_PARAM_READWRITE));
g_object_class_install_property (gobject_class, PROP_SHOW_HANDLE, g_param_spec_boolean ("show-handle", NULL, NULL, TRUE, EXO_PARAM_READWRITE));
g_object_class_install_property (gobject_class, PROP_SHOW_INSTANCES_HOVER, g_param_spec_boolean ("show-instances-on-hover", NULL, NULL, TRUE, EXO_PARAM_READWRITE));
g_object_class_install_property (gobject_class, PROP_DRAG_BUTTON, g_param_spec_int ("drag-button", NULL, NULL, -1, G_MAXINT, 0, EXO_PARAM_READWRITE));
g_object_class_install_property (gobject_class, PROP_FLAT_BUTTONS, g_param_spec_boolean ("flat-buttons", NULL, NULL, TRUE, EXO_PARAM_READWRITE));
gtk_widget_class_install_style_property (gtkwidget_class, g_param_spec_int ("max-button-length", NULL, "The maximum length of a window button", -1, G_MAXINT, DEFAULT_MAX_BUTTON_LENGTH, EXO_PARAM_READABLE));
gtk_widget_class_install_style_property (gtkwidget_class, g_param_spec_int ("min-button-length", NULL, "The minumum length of a window button", 1, G_MAXINT, DEFAULT_MIN_BUTTON_LENGTH, EXO_PARAM_READABLE));
gtk_widget_class_install_style_property (gtkwidget_class, g_param_spec_int ("max-button-size", NULL, "The maximum size of a window button", 1, G_MAXINT, DEFAULT_BUTTON_SIZE, EXO_PARAM_READABLE));
gtk_widget_class_install_style_property (gtkwidget_class, g_param_spec_enum ("ellipsize-mode", NULL, "The ellipsize mode used for the button label", PANGO_TYPE_ELLIPSIZE_MODE, DEFAULT_ELLIPSIZE_MODE,EXO_PARAM_READABLE));
gtk_widget_class_install_style_property (gtkwidget_class, g_param_spec_int ("minimized-icon-lucency", NULL, "Lucent percentage of minimized icons", 0, 100, DEFAULT_ICON_LUCENCY, EXO_PARAM_READABLE));
gtk_widget_class_install_style_property (gtkwidget_class, g_param_spec_int ("menu-max-width-chars", NULL, "Maximum chars in the overflow menu labels", 0, G_MAXINT, DEFAULT_MENU_MAX_WIDTH_CHARS, EXO_PARAM_READABLE));
menu_icon_size = gtk_icon_size_from_name ("panel-taskbar-menu");
if (menu_icon_size == GTK_ICON_SIZE_INVALID)
{
menu_icon_size = gtk_icon_size_register ("panel-taskbar-menu", DEFAULT_MENU_ICON_SIZE, DEFAULT_MENU_ICON_SIZE);
}
}
static void xfce_taskbar_init (XfceTaskBar *taskbar)
{
GTK_WIDGET_SET_FLAGS (taskbar, GTK_NO_WINDOW);
taskbar->locked = 0;
taskbar->screen = NULL;
taskbar->wgroups = NULL;
taskbar->skipped_windows = NULL;
taskbar->hotkeys_handler = NULL;
taskbar->horizontal = TRUE;
taskbar->all_workspaces = TRUE;
taskbar->switch_workspace = TRUE;
taskbar->only_minimized = FALSE;
taskbar->show_wireframes = TRUE;
taskbar->show_handle = TRUE;
taskbar->show_instances_hover = FALSE;
taskbar->drag_button = 1; /* Middle */
taskbar->flat_buttons = 0;
taskbar->all_monitors = TRUE;
taskbar->unique_id_counter = 0x0 ;
xfce_taskbar_geometry_set_invalid (taskbar);
#ifdef GDK_WINDOWING_X11
taskbar->wireframe_window = 0;
#endif
taskbar->update_icon_geometries_id = 0;
taskbar->update_monitor_geometry_id = 0;
taskbar->max_button_length = DEFAULT_MAX_BUTTON_LENGTH;
taskbar->min_button_length = DEFAULT_MIN_BUTTON_LENGTH;
taskbar->max_button_size = DEFAULT_BUTTON_SIZE;
taskbar->minimized_icon_lucency = DEFAULT_ICON_LUCENCY;
taskbar->ellipsize_mode = DEFAULT_ELLIPSIZE_MODE;
taskbar->menu_icon_size = DEFAULT_MENU_ICON_SIZE;
taskbar->menu_max_width_chars = DEFAULT_MENU_MAX_WIDTH_CHARS;
//taskbar->groups = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify) g_free, NULL);
taskbar->groups = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
taskbar->dragactive = FALSE ;
taskbar->dragtimestamp = 0 ;
}
static void xfce_taskbar_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
{
XfceTaskBar *taskbar = XFCE_taskbar (object);
switch (prop_id)
{
case PROP_INCLUDE_ALL_WORKSPACES:
g_value_set_boolean (value, taskbar->all_workspaces);
break;
case PROP_INCLUDE_ALL_MONITORS:
g_value_set_boolean (value, taskbar->all_monitors);
break;
case PROP_SWITCH_WORKSPACE_ON_UNMINIMIZE:
g_value_set_boolean (value, taskbar->switch_workspace);
break;
case PROP_SHOW_ONLY_MINIMIZED:
g_value_set_boolean (value, taskbar->only_minimized);
break;
case PROP_SHOW_WIREFRAMES:
g_value_set_boolean (value, taskbar->show_wireframes);
break;
case PROP_SHOW_HANDLE:
g_value_set_boolean (value, taskbar->show_handle);
break;
case PROP_SHOW_INSTANCES_HOVER:
g_value_set_boolean (value, taskbar->show_instances_hover);
break;
case PROP_DRAG_BUTTON:
g_value_set_int (value, taskbar->drag_button);
break;
case PROP_FLAT_BUTTONS:
g_value_set_boolean (value, taskbar->flat_buttons);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void xfce_taskbar_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
{
XfceTaskBar *taskbar = XFCE_taskbar (object);
GList *gi ;
switch (prop_id)
{
case PROP_INCLUDE_ALL_WORKSPACES:
xfce_taskbar_set_include_all_workspaces (taskbar, g_value_get_boolean (value));
break;
case PROP_INCLUDE_ALL_MONITORS:
xfce_taskbar_set_include_all_monitors (taskbar, g_value_get_boolean (value));
break;
case PROP_SWITCH_WORKSPACE_ON_UNMINIMIZE:
taskbar->switch_workspace = g_value_get_boolean (value);
break;
case PROP_SHOW_ONLY_MINIMIZED:
xfce_taskbar_set_show_only_minimized (taskbar, g_value_get_boolean (value));
break;
case PROP_SHOW_WIREFRAMES:
xfce_taskbar_set_show_wireframes (taskbar, g_value_get_boolean (value));
break;
case PROP_SHOW_HANDLE:
taskbar->show_handle = g_value_get_boolean (value);
break;
case PROP_SHOW_INSTANCES_HOVER:
taskbar->show_instances_hover = g_value_get_boolean (value);
break;
case PROP_DRAG_BUTTON:
taskbar->drag_button = g_value_get_int (value);
g_debug("drag_button=%d", taskbar->drag_button);
for(gi=taskbar->wgroups; gi!=NULL; gi=gi->next)
{
XfceTaskBarGroup *group =gi->data ;
gtk_drag_source_set (group->button, taskbar->drag_button ? GDK_BUTTON2_MASK : GDK_BUTTON1_MASK, source_targets, G_N_ELEMENTS (source_targets), GDK_ACTION_MOVE);
}
break;
case PROP_FLAT_BUTTONS:
taskbar->flat_buttons = g_value_get_boolean (value);
for(gi=taskbar->wgroups; gi!=NULL; gi=gi->next)
{
XfceTaskBarGroup *group =gi->data ;
xfce_taskbar_group_update_visibility(group);
}
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
void xfce_taskbar_load_pinned_config (XfceTaskBar *taskbar)
{
char rc_path [256] ;
int group_index=0x0 ;
gchar **groups ;
XfceRc *rc;
sprintf(rc_path, "%s/.config/xfce4/panel/taskbar/taskbar.rc", getenv("HOME"));
rc = xfce_rc_simple_open (rc_path, TRUE);
if(!rc)
{
return ;
}
groups = xfce_rc_get_groups(rc);
//the first group is a dud, wtf?
group_index = 1;
while(groups[group_index])
{
GError *err = NULL;
cairo_surface_t *surface ;
char png_path [512] ;
char *group_name = groups[group_index] ;
const char *command_string ;
xfce_rc_set_group (rc, group_name);
XfceTaskBarGroup *group = xfce_taskbar_group_button_new (group_name, taskbar);
sprintf(png_path, "%s/.config/xfce4/panel/taskbar/%s.png", getenv("HOME"), group_name);
group->pixbuf = gdk_pixbuf_new_from_file(png_path, &err);
if(!group->pixbuf)
{
//FIXME: free the residual memory in the group structure
xfce_dialog_show_error (NULL, err, _("Failed to load the icon \"%s\""), png_path);
return ;
}
g_object_ref(group->pixbuf);
command_string = xfce_rc_read_entry (rc, "command", NULL) ;
if(!command_string)
{
xfce_dialog_show_error (NULL, NULL, "TaskBar plugin failed to load the pinned command string!");
return ;
}
group->command = g_strdup(command_string);
group->pinned = TRUE ;
//add in the icon and add it to the list of groups
xfce_panel_image_set_from_pixbuf (XFCE_PANEL_IMAGE (group->icon), group->pixbuf);
g_hash_table_insert (taskbar->groups, (gpointer)group->window_class_name, group);
xfce_taskbar_group_update_visibility(group);
group_index += 1 ;
}
xfce_rc_close (rc);
gtk_widget_queue_resize (GTK_WIDGET (taskbar));
}
void xfce_taskbar_save_pinned_config (XfceTaskBar *taskbar)
{
char rc_path [256] ;
GList *gi ;
XfceRc *rc;
sprintf(rc_path, "%s/.config/xfce4/panel/taskbar", getenv("HOME"));
if(!xfce_mkdirhier(rc_path, 0700, NULL))
{
xfce_dialog_show_error (NULL, NULL, "TaskBar plugin failed to create the rc config directory");
return ;
}
sprintf(rc_path, "%s/.config/xfce4/panel/taskbar/taskbar.rc", getenv("HOME"));
//flush the previous resouce file...
remove(rc_path);
rc = xfce_rc_simple_open (rc_path, FALSE);
if(!rc)
{
xfce_dialog_show_error (NULL, NULL, "TaskBar plugin failed to create a configuration file");
return ;
}
for(gi=taskbar->wgroups; gi!=NULL; gi=gi->next)
{
XfceTaskBarGroup *group =gi->data ;
if(group->pinned == FALSE)
continue ;
xfce_rc_set_group (rc, group->window_class_name);
xfce_rc_write_entry (rc, "command", group->command);
// Now save the icon in the cache
{
char png_path [512] ;
sprintf(png_path, "%s/.config/xfce4/panel/taskbar/%s.png", getenv("HOME"), group->window_class_name);
if(!gdk_pixbuf_save (group->pixbuf, png_path, "png", NULL, NULL))
{
xfce_dialog_show_error (NULL, NULL, "TaskBar plugin failed to save the icon pixbuf!");
return ;
}
}
}
xfce_rc_close (rc);
}
static void xfce_taskbar_finalize (GObject *object)
{
g_debug("taskbar finalize");
XfceTaskBar *taskbar = XFCE_taskbar (object);
// data that should already be freed when disconnecting the screen
panel_return_if_fail (taskbar->wgroups == NULL);
panel_return_if_fail (taskbar->skipped_windows == NULL);
panel_return_if_fail (taskbar->screen == NULL);
// stop pending timeouts
if (taskbar->update_icon_geometries_id != 0)
{
g_source_remove (taskbar->update_icon_geometries_id);
}
if (taskbar->update_monitor_geometry_id != 0)
{
g_source_remove (taskbar->update_monitor_geometry_id);
}
// free the class group hash table
g_hash_table_destroy (taskbar->groups);
#ifdef GDK_WINDOWING_X11
// destroy the wireframe window
xfce_taskbar_wireframe_destroy (taskbar);
#endif
if(taskbar->hotkeys_handler)
finish_global_hotkeys(taskbar->hotkeys_handler);
(*G_OBJECT_CLASS (xfce_taskbar_parent_class)->finalize) (object);
}
static void xfce_taskbar_size_request (GtkWidget *widget, GtkRequisition *requisition)
{
XfceTaskBar *taskbar = XFCE_taskbar (widget);
gint rows, cols;
gint n_group_icons;
GtkRequisition child_req;
gint length;
GList *li;
XfceTaskBarGroup *group;
gint child_height = 0;
for (li = taskbar->wgroups, n_group_icons = 0; li != NULL; li = li->next)
{
group = li->data;
if (GTK_WIDGET_VISIBLE (group->button))
{
gtk_widget_size_request (group->button, &child_req);
child_height = MAX (child_height, child_req.height);
n_group_icons++;
}
}
taskbar->n_group_icons = n_group_icons;
if (n_group_icons == 0)
{
length = 0;
}
else
{
rows = taskbar->size / taskbar->max_button_size;
rows = CLAMP (rows, 1, n_group_icons);
cols = n_group_icons / rows;
if (cols * rows < n_group_icons)
cols++;
length = (taskbar->size / rows) * cols;
}
/* set the requested sizes */
if (xfce_taskbar_horizontal (taskbar))
{
if (taskbar->horizontal != xfce_taskbar_horizontal (taskbar))
{
requisition->height = child_height * n_group_icons;
requisition->width = taskbar->size;
}
else
{
requisition->width = length;
requisition->height = taskbar->size;
}
}
else
{
requisition->width = taskbar->size;
requisition->height = length;
}
}
static void xfce_taskbar_size_layout (XfceTaskBar *taskbar, GtkAllocation *alloc, gint *n_rows, gint *n_cols)
{
gint rows;
gint min_button_length;
gint cols;
// if we're in the opposite vertical mode, there are no columns
if (taskbar->horizontal != xfce_taskbar_horizontal (taskbar))
rows = taskbar->n_group_icons;
else
rows = alloc->height / taskbar->max_button_size;
if (rows < 1)
rows = 1;
cols = taskbar->n_group_icons / rows;
if (cols * rows < taskbar->n_group_icons)
cols++;
min_button_length = alloc->height / rows;
// jam all the icons in, lets see what happens
*n_rows = rows;
*n_cols = cols;
}
static void xfce_taskbar_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
{
XfceTaskBar *taskbar = XFCE_taskbar (widget);
gint rows, cols;
gint row;
GtkAllocation area = *allocation;
GList *li;
XfceTaskBarGroup *group;
gint i;
GtkAllocation child_alloc;
gboolean direction_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
gint w, x, y, h;
gint area_x, area_width;
GtkRequisition child_req;
//set widget allocation
widget->allocation = *allocation;
// swap integers with vertical orientation
if (!xfce_taskbar_horizontal (taskbar))
TRANSPOSE_AREA (area);
// TODO if we compare the allocation with the requisition we can
// do a fast path to the child allocation, i think
// useless but hides compiler warning
w = h = x = y = rows = cols = 0;
xfce_taskbar_size_layout (taskbar, &area, &rows, &cols);
// allocate the arrow button for the overflow menu
child_alloc.width = area.height;
child_alloc.height = area.height;
child_alloc.x = child_alloc.y = -9999;
area_x = area.x;
area_width = area.width;
// allocate all the children
for (li = taskbar->wgroups, i = 0; li != NULL; li = li->next)
{
group = li->data;
// skip hidden buttons
if (!GTK_WIDGET_VISIBLE (group->button))
continue;
row = (i % rows);
if (row == 0)
{
x = area_x;
y = area.y;
h = area.height;
w = h / (rows - row);
area_width -= w;
area_x += w;
}
child_alloc.y = y;
child_alloc.x = x;
child_alloc.width = MAX (w, 1); // TODO this is a workaround
child_alloc.height = h / (rows - row);
if (!taskbar->horizontal && xfce_taskbar_horizontal (taskbar))
{
gtk_widget_get_child_requisition (group->button, &child_req);
child_alloc.height = child_req.height;
}
h -= child_alloc.height;
y += child_alloc.height;
if (direction_rtl)
child_alloc.x = area.x + area.width - (child_alloc.x - area.x) - child_alloc.width;
// allocate the group
if (!xfce_taskbar_horizontal (taskbar))
TRANSPOSE_AREA (child_alloc);
// increase the position counter
i++;
gtk_widget_size_allocate (group->button, &child_alloc);
}
// update icon geometries
if (taskbar->update_icon_geometries_id == 0)
{
taskbar->update_icon_geometries_id = g_idle_add_full(G_PRIORITY_LOW, xfce_taskbar_update_icon_geometries,
taskbar, xfce_taskbar_update_icon_geometries_destroyed);
}
}
static void xfce_taskbar_style_set (GtkWidget *widget, GtkStyle *previous_style)
{
XfceTaskBar *taskbar = XFCE_taskbar (widget);
gint max_button_length;
gint max_button_size;
gint min_button_length;
gint w, h;
// let gtk update the widget style
(*GTK_WIDGET_CLASS (xfce_taskbar_parent_class)->style_set) (widget, previous_style);
// read the style properties
gtk_widget_style_get (GTK_WIDGET (taskbar),
"max-button-length", &max_button_length,
"min-button-length", &min_button_length,
"ellipsize-mode", &taskbar->ellipsize_mode,
"max-button-size", &max_button_size,
"minimized-icon-lucency", &taskbar->minimized_icon_lucency,
"menu-max-width-chars", &taskbar->menu_max_width_chars,
NULL);
if (gtk_icon_size_lookup (menu_icon_size, &w, &h))
taskbar->menu_icon_size = MIN (w, h);
// update the widget
if (taskbar->max_button_length != max_button_length
|| taskbar->max_button_size != max_button_size
|| taskbar->min_button_length != min_button_length)
{
if (max_button_length > 0)
{
// prevent abuse of the min/max button length
taskbar->max_button_length = MAX (min_button_length, max_button_length);
taskbar->min_button_length = MIN (min_button_length, max_button_length);
}
else
{
taskbar->max_button_length = max_button_length;
taskbar->min_button_length = min_button_length;
}
taskbar->max_button_size = max_button_size;
gtk_widget_queue_resize (widget);
}
}
static void xfce_taskbar_realize (GtkWidget *widget)
{
XfceTaskBar *taskbar = XFCE_taskbar (widget);
(*GTK_WIDGET_CLASS (xfce_taskbar_parent_class)->realize) (widget);
xfce_taskbar_connect_screen (taskbar);
}
static void xfce_taskbar_unrealize (GtkWidget *widget)
{
XfceTaskBar *taskbar = XFCE_taskbar (widget);
xfce_taskbar_disconnect_screen (taskbar);
(*GTK_WIDGET_CLASS (xfce_taskbar_parent_class)->unrealize) (widget);
}
// we handle the memory frees elsewhere..
static void xfce_taskbar_remove (GtkContainer *container, GtkWidget *widget)
{
XfceTaskBar *taskbar = XFCE_taskbar (container);
gtk_widget_queue_resize (GTK_WIDGET (container));
}
static void xfce_taskbar_forall (GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data)
{
XfceTaskBar *taskbar = XFCE_taskbar (container);
GList *children = taskbar->wgroups;
XfceTaskBarGroup *group;
while (children != NULL)
{
group = children->data;
children = children->next;
(* callback) (group->button, callback_data);
}
}
static GType xfce_taskbar_child_type (GtkContainer *container)
{
return GTK_TYPE_WIDGET;
}
static void xfce_taskbar_connect_screen (XfceTaskBar *taskbar)
{
GList *windows, *li;
panel_return_if_fail (XFCE_IS_taskbar (taskbar));
panel_return_if_fail (taskbar->screen == NULL);
panel_return_if_fail (taskbar->gdk_screen == NULL);
// set the new screen
taskbar->gdk_screen = gtk_widget_get_screen (GTK_WIDGET (taskbar));
taskbar->screen = wnck_screen_get (gdk_screen_get_number (taskbar->gdk_screen));
// initialize global hotkeys
taskbar->hotkeys_handler = init_global_hotkeys(taskbar);
// add all existing windows on this screen
windows = wnck_screen_get_windows (taskbar->screen);
for (li = windows; li != NULL; li = li->next)
{
xfce_taskbar_window_added (taskbar->screen, li->data, taskbar);
}
// load the pinned items
xfce_taskbar_load_pinned_config (taskbar);
// monitor gdk changes
g_signal_connect (G_OBJECT (taskbar->gdk_screen), "monitors-changed", G_CALLBACK (xfce_taskbar_gdk_screen_changed), taskbar);
g_signal_connect (G_OBJECT (taskbar->gdk_screen), "size-changed", G_CALLBACK (xfce_taskbar_gdk_screen_changed), taskbar);
// monitor screen changes
g_signal_connect (G_OBJECT (taskbar->screen), "active-window-changed", G_CALLBACK (xfce_taskbar_active_window_changed), taskbar);
g_signal_connect (G_OBJECT (taskbar->screen), "active-workspace-changed", G_CALLBACK (xfce_taskbar_active_workspace_changed), taskbar);
g_signal_connect (G_OBJECT (taskbar->screen), "window-opened", G_CALLBACK (xfce_taskbar_window_added), taskbar);
g_signal_connect (G_OBJECT (taskbar->screen), "window-closed", G_CALLBACK (xfce_taskbar_window_removed), taskbar);
g_signal_connect (G_OBJECT (taskbar->screen), "viewports-changed", G_CALLBACK (xfce_taskbar_viewports_changed), taskbar);
// update the viewport if not all monitors are shown
xfce_taskbar_gdk_screen_changed (taskbar->gdk_screen, taskbar);
}
static void xfce_taskbar_disconnect_screen (XfceTaskBar *taskbar)
{
GSList *li, *lnext;
GList *wi, *wnext;
XfceTaskBarGroup *group;
guint n;
panel_return_if_fail (XFCE_IS_taskbar (taskbar));
panel_return_if_fail (WNCK_IS_SCREEN (taskbar->screen));
panel_return_if_fail (GDK_IS_SCREEN (taskbar->gdk_screen));
// disconnect monitor signals
n = g_signal_handlers_disconnect_matched (G_OBJECT (taskbar->screen), G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, taskbar);
panel_return_if_fail (n == 5);
// disconnect geometry changed signals
g_signal_handlers_disconnect_by_func (G_OBJECT (taskbar->gdk_screen), G_CALLBACK (xfce_taskbar_gdk_screen_changed), taskbar);
// delete all known class groups (and their buttons)
g_hash_table_remove_all (taskbar->groups);
// disconnect from all skipped windows
for (li = taskbar->skipped_windows; li != NULL; li = lnext)
{
lnext = li->next;
panel_return_if_fail (wnck_window_is_skip_tasklist (WNCK_WINDOW (li->data)));
xfce_taskbar_window_removed (taskbar->screen, li->data, taskbar);
}
for (wi = taskbar->wgroups; wi != NULL; wi = wnext)
{
wnext = wi->next;
group = wi->data;
xfce_taskbar_group_button_remove(group);
}
panel_assert (taskbar->wgroups == NULL);
panel_assert (taskbar->skipped_windows == NULL);
taskbar->screen = NULL;
taskbar->gdk_screen = NULL;
}
static void xfce_taskbar_gdk_screen_changed (GdkScreen *gdk_screen, XfceTaskBar *taskbar)
{
panel_return_if_fail (XFCE_IS_taskbar (taskbar));
panel_return_if_fail (GDK_IS_SCREEN (gdk_screen));
panel_return_if_fail (taskbar->gdk_screen == gdk_screen);
if (!taskbar->all_monitors)
{
// update the monitor geometry
xfce_taskbar_update_monitor_geometry (taskbar);