/
tasklist-widget.c
4866 lines (3922 loc) · 161 KB
/
tasklist-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
/*
* Copyright (C) 2008-2010 Nick Schermer <nick@xfce.org>
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "tasklist-widget.h"
#include "common/panel-debug.h"
#include "common/panel-private.h"
#include "common/panel-utils.h"
#include <libxfce4ui/libxfce4ui.h>
#include <libxfce4windowing/libxfce4windowing.h>
#include <libxfce4windowingui/libxfce4windowingui.h>
#ifdef ENABLE_X11
#include <X11/Xlib.h>
#include <X11/extensions/shape.h>
#include <libxfce4windowing/xfw-x11.h>
#define tasklist_window_get_xid(window) \
(xfw_windowing_get () == XFW_WINDOWING_X11 ? xfw_window_x11_get_xid (window) : 0LU)
#else
#define tasklist_window_get_xid(window) 0LU
#endif
#ifdef HAVE_MATH_H
#include <math.h>
#endif
#define MIN_MAX_BUTTON_SIZE (-1)
#define MAX_MAX_BUTTON_SIZE (G_MAXINT)
#define DEFAULT_MAX_BUTTON_SIZE (32)
#define MIN_MAX_BUTTON_LENGTH (-1)
#define MAX_MAX_BUTTON_LENGTH (G_MAXINT)
#define DEFAULT_MAX_BUTTON_LENGTH (200)
#define MIN_MIN_BUTTON_LENGTH (0)
#define MAX_MIN_BUTTON_LENGTH (G_MAXINT)
#define DEFAULT_MIN_BUTTON_LENGTH (DEFAULT_MAX_BUTTON_LENGTH)
#define MIN_MINIMIZED_ICON_LUCENCY (0)
#define MAX_MINIMIZED_ICON_LUCENCY (100)
#define DEFAULT_MINIMIZED_ICON_LUCENCY (50)
#define DEFAULT_ELLIPSIZE_MODE (PANGO_ELLIPSIZE_END)
#define MIN_MENU_MAX_WIDTH_CHARS (-1)
#define MAX_MENU_MAX_WIDTH_CHARS (G_MAXINT)
#define DEFAULT_MENU_MAX_WIDTH_CHARS (24)
#define ARROW_BUTTON_SIZE (20)
#define WIREFRAME_SIZE (5) /* same as xfwm4 */
#define DRAG_ACTIVATE_TIMEOUT (500)
/* locking helpers for tasklist->locked */
#define xfce_taskbar_lock(tasklist) \
G_STMT_START { XFCE_TASKLIST (tasklist)->locked++; } \
G_STMT_END
#define xfce_taskbar_unlock(tasklist) \
G_STMT_START \
{ \
if (XFCE_TASKLIST (tasklist)->locked > 0) \
XFCE_TASKLIST (tasklist)->locked--; \
else \
panel_assert_not_reached (); \
} \
G_STMT_END
#define xfce_taskbar_is_locked(tasklist) (XFCE_TASKLIST (tasklist)->locked > 0)
#define xfce_tasklist_get_panel_plugin(tasklist) XFCE_PANEL_PLUGIN (gtk_widget_get_ancestor (GTK_WIDGET (tasklist), XFCE_TYPE_PANEL_PLUGIN))
#define xfce_tasklist_horizontal(tasklist) ((tasklist)->mode == XFCE_PANEL_PLUGIN_MODE_HORIZONTAL)
#define xfce_tasklist_vertical(tasklist) ((tasklist)->mode == XFCE_PANEL_PLUGIN_MODE_VERTICAL)
#define xfce_tasklist_deskbar(tasklist) ((tasklist)->mode == XFCE_PANEL_PLUGIN_MODE_DESKBAR)
#define xfce_tasklist_filter_monitors(tasklist) (!(tasklist)->all_monitors && (tasklist)->n_monitors > 1)
typedef enum _XfceTasklistSortOrder
{
XFCE_TASKLIST_SORT_ORDER_TIMESTAMP, /* sort by unique_id */
XFCE_TASKLIST_SORT_ORDER_GROUP_TIMESTAMP, /* sort by group and then by timestamp */
XFCE_TASKLIST_SORT_ORDER_TITLE, /* sort by window title */
XFCE_TASKLIST_SORT_ORDER_GROUP_TITLE, /* sort by group and then by title */
XFCE_TASKLIST_SORT_ORDER_DND, /* append and support dnd */
XFCE_TASKLIST_SORT_ORDER_MIN = XFCE_TASKLIST_SORT_ORDER_TIMESTAMP,
XFCE_TASKLIST_SORT_ORDER_MAX = XFCE_TASKLIST_SORT_ORDER_DND,
XFCE_TASKLIST_SORT_ORDER_DEFAULT = XFCE_TASKLIST_SORT_ORDER_GROUP_TIMESTAMP
} XfceTasklistSortOrder;
typedef enum _XfceTasklistMClick
{
XFCE_TASKLIST_MIDDLE_CLICK_NOTHING, /* do nothing */
XFCE_TASKLIST_MIDDLE_CLICK_CLOSE_WINDOW, /* close the window */
XFCE_TASKLIST_MIDDLE_CLICK_MINIMIZE_WINDOW, /* minimize, never minimize with button 1 */
XFCE_TASKLIST_MIDDLE_CLICK_NEW_INSTANCE, /* launches a new instance of the window */
XFCE_TASKLIST_MIDDLE_CLICK_MIN = XFCE_TASKLIST_MIDDLE_CLICK_NOTHING,
XFCE_TASKLIST_MIDDLE_CLICK_MAX = XFCE_TASKLIST_MIDDLE_CLICK_NEW_INSTANCE,
XFCE_TASKLIST_MIDDLE_CLICK_DEFAULT = XFCE_TASKLIST_MIDDLE_CLICK_NOTHING
} XfceTasklistMClick;
enum
{
PROP_0,
PROP_GROUPING,
PROP_INCLUDE_ALL_WORKSPACES,
PROP_INCLUDE_ALL_MONITORS,
PROP_FLAT_BUTTONS,
PROP_SWITCH_WORKSPACE_ON_UNMINIMIZE,
PROP_SHOW_LABELS,
PROP_SHOW_ONLY_MINIMIZED,
PROP_SHOW_WIREFRAMES,
PROP_SHOW_HANDLE,
PROP_SHOW_TOOLTIPS,
PROP_SORT_ORDER,
PROP_WINDOW_SCROLLING,
PROP_WRAP_WINDOWS,
PROP_INCLUDE_ALL_BLINKING,
PROP_MIDDLE_CLICK,
PROP_LABEL_DECORATIONS
};
struct _XfceTasklist
{
GtkContainer __parent__;
/* lock counter */
gint locked;
/* the screen of this tasklist */
XfwScreen *screen;
XfwWorkspaceGroup *workspace_group;
GdkDisplay *display;
/* window children in the tasklist */
GList *windows;
/* windows we monitor, but that are excluded from the tasklist */
GSList *skipped_windows;
/* arrow button of the overflow menu */
GtkWidget *arrow_button;
/* applications of all the windows in the taskbar */
GHashTable *apps;
/* normal or iconbox style */
guint show_labels : 1;
/* size of the panel pluin */
gint size;
/* mode (orientation) of the tasklist */
XfcePanelPluginMode mode;
/* relief of the tasklist buttons */
GtkReliefStyle button_relief;
/* 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
* tasklist */
guint only_minimized : 1;
/* number of rows of window buttons */
gint nrows;
gdouble nrows_ratio;
/* switch window with the mouse wheel */
guint window_scrolling : 1;
guint wrap_windows : 1;
/* whether we show blinking windows from all workspaces
* or only the active workspace */
guint all_blinking : 1;
/* action to preform when middle clicking */
XfceTasklistMClick middle_click;
/* whether decorate labels when window is not visible */
guint label_decorations : 1;
/* whether we only show windows that are in the geometry of
* the monitor the tasklist is on */
guint all_monitors : 1;
guint n_monitors;
/* whether we show wireframes when hovering a button in
* the tasklist */
guint show_wireframes : 1;
/* icon geometries update timeout */
guint update_icon_geometries_id;
/* idle monitor geometry update */
guint update_monitor_geometry_id;
/* button grouping */
guint grouping : 1;
/* sorting order of the buttons */
XfceTasklistSortOrder sort_order;
/* dummy properties */
guint show_handle : 1;
guint show_tooltips : 1;
#ifdef ENABLE_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_max_width_chars;
gint n_windows;
};
typedef enum
{
CHILD_TYPE_WINDOW,
CHILD_TYPE_GROUP,
CHILD_TYPE_OVERFLOW_MENU,
CHILD_TYPE_GROUP_MENU
} XfceTasklistChildType;
typedef struct _XfceTasklistChild
{
/* type of this button */
XfceTasklistChildType type;
/* pointer to the tasklist */
XfceTasklist *tasklist;
/* button widgets */
GtkWidget *button;
GtkWidget *box;
GtkWidget *icon;
GtkWidget *label;
/* we use a surface for icon rendering so keep original pixbuf around */
GdkPixbuf *pixbuf;
/* drag motion window activate */
guint motion_timeout_id;
guint motion_timestamp;
/* unique id for sorting by insert time,
* simply increased for each new button */
guint unique_id;
/* last time this window was focused */
gint64 last_focused;
/* list of windows in case of a group button */
GSList *windows;
gint n_windows;
/* xfw information */
XfwWindow *window;
XfwApplication *app;
} XfceTasklistChild;
static const GtkTargetEntry source_targets[] = {
{ "application/x-wnck-window-id", 0, 0 }
};
static void
xfce_tasklist_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static void
xfce_tasklist_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void
xfce_tasklist_finalize (GObject *object);
static void
xfce_tasklist_get_preferred_length (GtkWidget *widget,
gint *minimum_length,
gint *natural_length);
static void
xfce_tasklist_get_preferred_width (GtkWidget *widget,
gint *minimum_width,
gint *natural_width);
static void
xfce_tasklist_get_preferred_height (GtkWidget *widget,
gint *minimum_height,
gint *natural_height);
static void
xfce_tasklist_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
static void
xfce_tasklist_style_updated (GtkWidget *widget);
static void
xfce_tasklist_realize (GtkWidget *widget);
static void
xfce_tasklist_unrealize (GtkWidget *widget);
static gboolean
xfce_tasklist_scroll_event (GtkWidget *widget,
GdkEventScroll *event);
static void
xfce_tasklist_remove (GtkContainer *container,
GtkWidget *widget);
static void
xfce_tasklist_forall (GtkContainer *container,
gboolean include_internals,
GtkCallback callback,
gpointer callback_data);
static GType
xfce_tasklist_child_type (GtkContainer *container);
static void
xfce_tasklist_arrow_button_toggled (GtkWidget *button,
XfceTasklist *tasklist);
static void
xfce_tasklist_connect_screen (XfceTasklist *tasklist);
static void
xfce_tasklist_disconnect_screen (XfceTasklist *tasklist);
static gboolean
xfce_tasklist_configure_event (GtkWidget *widget,
GdkEvent *event,
XfceTasklist *tasklist);
static void
xfce_tasklist_active_window_changed (XfwScreen *screen,
XfwWindow *previous_window,
XfceTasklist *tasklist);
static void
xfce_tasklist_active_workspace_changed (XfwWorkspaceGroup *group,
XfwWorkspace *previous_workspace,
XfceTasklist *tasklist);
static void
xfce_tasklist_window_added (XfwScreen *screen,
XfwWindow *window,
XfceTasklist *tasklist);
static void
xfce_tasklist_window_removed (XfwScreen *screen,
XfwWindow *window,
XfceTasklist *tasklist);
static void
xfce_tasklist_viewports_changed (XfwWorkspaceGroup *group,
XfceTasklist *tasklist);
static void
xfce_tasklist_button_state_changed (XfwWindow *window,
XfwWindowState changed_state,
XfwWindowState new_state,
XfceTasklistChild *child);
static void
xfce_tasklist_skipped_windows_state_changed (XfwWindow *window,
XfwWindowState changed_state,
XfwWindowState new_state,
XfceTasklist *tasklist);
static void
xfce_tasklist_sort (XfceTasklist *tasklist,
gboolean sort_groups);
static void
xfce_tasklist_group_button_sort (XfceTasklistChild *group_child);
static gboolean
xfce_tasklist_update_icon_geometries (gpointer data);
static void
xfce_tasklist_update_icon_geometries_destroyed (gpointer data);
/* wireframe */
#ifdef ENABLE_X11
static void
xfce_tasklist_wireframe_hide (XfceTasklist *tasklist);
static void
xfce_tasklist_wireframe_destroy (XfceTasklist *tasklist);
static void
xfce_tasklist_wireframe_update (XfceTasklist *tasklist,
XfceTasklistChild *child);
#endif
/* tasklist buttons */
static inline gboolean
xfce_tasklist_button_visible (XfceTasklistChild *child,
XfwWorkspace *active_ws);
static gint
xfce_tasklist_button_compare (gconstpointer child_a,
gconstpointer child_b,
gpointer user_data);
static GtkWidget *
xfce_tasklist_button_proxy_menu_item (XfceTasklistChild *child,
gboolean allow_wireframe);
static gboolean
xfce_tasklist_button_activate (XfceTasklistChild *child,
guint32 timestamp);
static XfceTasklistChild *
xfce_tasklist_button_new (XfwWindow *window,
XfceTasklist *tasklist);
/* tasklist group buttons */
static void
xfce_tasklist_group_button_menu_close (GtkWidget *menuitem,
XfceTasklistChild *child,
guint32 time);
static gboolean
xfce_tasklist_group_button_button_draw (GtkWidget *widget,
cairo_t *cr,
XfceTasklistChild *group_child);
static void
xfce_tasklist_group_button_remove (XfceTasklistChild *group_child);
static void
xfce_tasklist_group_button_add_window (XfceTasklistChild *group_child,
XfceTasklistChild *window_child);
static void
xfce_tasklist_button_icon_changed (XfwWindow *window,
XfceTasklistChild *child);
static void
xfce_tasklist_group_button_icon_changed (XfwApplication *app,
XfceTasklistChild *group_child);
static XfceTasklistChild *
xfce_tasklist_group_button_new (XfwApplication *app,
XfceTasklist *tasklist);
/* potential public functions */
static void
xfce_tasklist_set_include_all_workspaces (XfceTasklist *tasklist,
gboolean all_workspaces);
static void
xfce_tasklist_set_include_all_monitors (XfceTasklist *tasklist,
gboolean all_monitors);
static void
xfce_tasklist_set_button_relief (XfceTasklist *tasklist,
GtkReliefStyle button_relief);
static void
xfce_tasklist_set_show_labels (XfceTasklist *tasklist,
gboolean show_labels);
static void
xfce_tasklist_set_show_only_minimized (XfceTasklist *tasklist,
gboolean only_minimized);
static void
xfce_tasklist_set_show_wireframes (XfceTasklist *tasklist,
gboolean show_wireframes);
static void
xfce_tasklist_set_label_decorations (XfceTasklist *tasklist,
gboolean label_decorations);
static void
xfce_tasklist_set_grouping (XfceTasklist *tasklist,
gboolean grouping);
G_DEFINE_FINAL_TYPE (XfceTasklist, xfce_tasklist, GTK_TYPE_CONTAINER)
static void
xfce_tasklist_class_init (XfceTasklistClass *klass)
{
GObjectClass *gobject_class;
GtkWidgetClass *gtkwidget_class;
GtkContainerClass *gtkcontainer_class;
gobject_class = G_OBJECT_CLASS (klass);
gobject_class->get_property = xfce_tasklist_get_property;
gobject_class->set_property = xfce_tasklist_set_property;
gobject_class->finalize = xfce_tasklist_finalize;
gtkwidget_class = GTK_WIDGET_CLASS (klass);
gtkwidget_class->get_preferred_width = xfce_tasklist_get_preferred_width;
gtkwidget_class->get_preferred_height = xfce_tasklist_get_preferred_height;
gtkwidget_class->size_allocate = xfce_tasklist_size_allocate;
gtkwidget_class->style_updated = xfce_tasklist_style_updated;
gtkwidget_class->realize = xfce_tasklist_realize;
gtkwidget_class->unrealize = xfce_tasklist_unrealize;
gtkwidget_class->scroll_event = xfce_tasklist_scroll_event;
gtkcontainer_class = GTK_CONTAINER_CLASS (klass);
gtkcontainer_class->add = NULL;
gtkcontainer_class->remove = xfce_tasklist_remove;
gtkcontainer_class->forall = xfce_tasklist_forall;
gtkcontainer_class->child_type = xfce_tasklist_child_type;
g_object_class_install_property (gobject_class,
PROP_GROUPING,
g_param_spec_boolean ("grouping",
NULL, NULL,
FALSE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class,
PROP_INCLUDE_ALL_WORKSPACES,
g_param_spec_boolean ("include-all-workspaces",
NULL, NULL,
FALSE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class,
PROP_INCLUDE_ALL_MONITORS,
g_param_spec_boolean ("include-all-monitors",
NULL, NULL,
TRUE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class,
PROP_FLAT_BUTTONS,
g_param_spec_boolean ("flat-buttons",
NULL, NULL,
FALSE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class,
PROP_SWITCH_WORKSPACE_ON_UNMINIMIZE,
g_param_spec_boolean ("switch-workspace-on-unminimize",
NULL, NULL,
TRUE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class,
PROP_SHOW_LABELS,
g_param_spec_boolean ("show-labels",
NULL, NULL,
TRUE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class,
PROP_SHOW_ONLY_MINIMIZED,
g_param_spec_boolean ("show-only-minimized",
NULL, NULL,
FALSE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class,
PROP_SHOW_WIREFRAMES,
g_param_spec_boolean ("show-wireframes",
NULL, NULL,
FALSE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class,
PROP_SHOW_HANDLE,
g_param_spec_boolean ("show-handle",
NULL, NULL,
TRUE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class,
PROP_SHOW_TOOLTIPS,
g_param_spec_boolean ("show-tooltips",
NULL, NULL,
TRUE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class,
PROP_SORT_ORDER,
g_param_spec_uint ("sort-order",
NULL, NULL,
XFCE_TASKLIST_SORT_ORDER_MIN,
XFCE_TASKLIST_SORT_ORDER_MAX,
XFCE_TASKLIST_SORT_ORDER_DEFAULT,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class,
PROP_WINDOW_SCROLLING,
g_param_spec_boolean ("window-scrolling",
NULL, NULL,
TRUE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class,
PROP_WRAP_WINDOWS,
g_param_spec_boolean ("wrap-windows",
NULL, NULL,
FALSE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class,
PROP_INCLUDE_ALL_BLINKING,
g_param_spec_boolean ("include-all-blinking",
NULL, NULL,
TRUE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class,
PROP_MIDDLE_CLICK,
g_param_spec_uint ("middle-click",
NULL, NULL,
XFCE_TASKLIST_MIDDLE_CLICK_MIN,
XFCE_TASKLIST_MIDDLE_CLICK_MAX,
XFCE_TASKLIST_MIDDLE_CLICK_DEFAULT,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class,
PROP_LABEL_DECORATIONS,
g_param_spec_boolean ("label-decorations",
NULL, NULL,
FALSE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
gtk_widget_class_install_style_property (gtkwidget_class,
g_param_spec_int ("max-button-length",
NULL,
"The maximum length of a window button",
MIN_MAX_BUTTON_LENGTH, MAX_MAX_BUTTON_LENGTH,
DEFAULT_MAX_BUTTON_LENGTH,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
gtk_widget_class_install_style_property (gtkwidget_class,
g_param_spec_int ("min-button-length",
NULL,
"The minimum length of a window button",
MIN_MIN_BUTTON_LENGTH, MAX_MIN_BUTTON_LENGTH,
DEFAULT_MIN_BUTTON_LENGTH,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
gtk_widget_class_install_style_property (gtkwidget_class,
g_param_spec_int ("max-button-size",
NULL,
"The maximum size of a window button",
MIN_MAX_BUTTON_SIZE, MAX_MAX_BUTTON_SIZE,
DEFAULT_MAX_BUTTON_SIZE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
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,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
gtk_widget_class_install_style_property (gtkwidget_class,
g_param_spec_int ("minimized-icon-lucency",
NULL,
"Lucent percentage of minimized icons",
MIN_MINIMIZED_ICON_LUCENCY, MAX_MINIMIZED_ICON_LUCENCY,
DEFAULT_MINIMIZED_ICON_LUCENCY,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
gtk_widget_class_install_style_property (gtkwidget_class,
g_param_spec_int ("menu-max-width-chars",
NULL,
"Maximum chars in the overflow menu labels",
MIN_MENU_MAX_WIDTH_CHARS, MAX_MENU_MAX_WIDTH_CHARS,
DEFAULT_MENU_MAX_WIDTH_CHARS,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
}
static void
xfce_tasklist_init (XfceTasklist *tasklist)
{
GtkStyleContext *context;
gtk_widget_set_has_window (GTK_WIDGET (tasklist), FALSE);
tasklist->locked = 0;
tasklist->screen = NULL;
tasklist->windows = NULL;
tasklist->skipped_windows = NULL;
tasklist->mode = XFCE_PANEL_PLUGIN_MODE_HORIZONTAL;
tasklist->nrows = 1;
tasklist->nrows_ratio = 1;
tasklist->all_workspaces = FALSE;
tasklist->button_relief = GTK_RELIEF_NORMAL;
tasklist->switch_workspace = TRUE;
tasklist->only_minimized = FALSE;
tasklist->show_labels = TRUE;
tasklist->show_wireframes = FALSE;
tasklist->show_handle = TRUE;
tasklist->show_tooltips = TRUE;
tasklist->all_monitors = TRUE;
tasklist->n_monitors = 0;
tasklist->window_scrolling = TRUE;
tasklist->wrap_windows = FALSE;
tasklist->all_blinking = TRUE;
tasklist->middle_click = XFCE_TASKLIST_MIDDLE_CLICK_DEFAULT;
tasklist->label_decorations = FALSE;
#ifdef ENABLE_X11
tasklist->wireframe_window = 0;
#endif
tasklist->update_icon_geometries_id = 0;
tasklist->update_monitor_geometry_id = 0;
tasklist->max_button_length = DEFAULT_MAX_BUTTON_LENGTH;
tasklist->min_button_length = DEFAULT_MIN_BUTTON_LENGTH;
tasklist->max_button_size = DEFAULT_MAX_BUTTON_SIZE;
tasklist->minimized_icon_lucency = DEFAULT_MINIMIZED_ICON_LUCENCY;
tasklist->ellipsize_mode = DEFAULT_ELLIPSIZE_MODE;
tasklist->grouping = FALSE;
tasklist->sort_order = XFCE_TASKLIST_SORT_ORDER_DEFAULT;
tasklist->menu_max_width_chars = DEFAULT_MENU_MAX_WIDTH_CHARS;
/* add style class for the tasklist widget */
context = gtk_widget_get_style_context (GTK_WIDGET (tasklist));
gtk_style_context_add_class (context, "tasklist");
/* widgets for the overflow menu */
/* TODO support drag-motion and drag-leave */
tasklist->arrow_button = xfce_arrow_button_new (GTK_ARROW_DOWN);
gtk_widget_set_parent (tasklist->arrow_button, GTK_WIDGET (tasklist));
gtk_widget_set_name (tasklist->arrow_button, "panel-tasklist-arrow");
gtk_button_set_relief (GTK_BUTTON (tasklist->arrow_button), tasklist->button_relief);
g_signal_connect (G_OBJECT (tasklist->arrow_button), "toggled",
G_CALLBACK (xfce_tasklist_arrow_button_toggled), tasklist);
gtk_widget_show (tasklist->arrow_button);
}
static void
xfce_tasklist_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
XfceTasklist *tasklist = XFCE_TASKLIST (object);
switch (prop_id)
{
case PROP_GROUPING:
g_value_set_boolean (value, tasklist->grouping);
break;
case PROP_INCLUDE_ALL_WORKSPACES:
g_value_set_boolean (value, tasklist->all_workspaces);
break;
case PROP_INCLUDE_ALL_MONITORS:
g_value_set_boolean (value, tasklist->all_monitors);
break;
case PROP_FLAT_BUTTONS:
g_value_set_boolean (value, !!(tasklist->button_relief == GTK_RELIEF_NONE));
break;
case PROP_SWITCH_WORKSPACE_ON_UNMINIMIZE:
g_value_set_boolean (value, tasklist->switch_workspace);
break;
case PROP_SHOW_LABELS:
g_value_set_boolean (value, tasklist->show_labels);
break;
case PROP_SHOW_ONLY_MINIMIZED:
g_value_set_boolean (value, tasklist->only_minimized);
break;
case PROP_SHOW_WIREFRAMES:
g_value_set_boolean (value, tasklist->show_wireframes);
break;
case PROP_SHOW_HANDLE:
g_value_set_boolean (value, tasklist->show_handle);
break;
case PROP_SHOW_TOOLTIPS:
g_value_set_boolean (value, tasklist->show_tooltips);
break;
case PROP_SORT_ORDER:
g_value_set_uint (value, tasklist->sort_order);
break;
case PROP_WINDOW_SCROLLING:
g_value_set_boolean (value, tasklist->window_scrolling);
break;
case PROP_WRAP_WINDOWS:
g_value_set_boolean (value, tasklist->wrap_windows);
break;
case PROP_INCLUDE_ALL_BLINKING:
g_value_set_boolean (value, tasklist->all_blinking);
break;
case PROP_MIDDLE_CLICK:
g_value_set_uint (value, tasklist->middle_click);
break;
case PROP_LABEL_DECORATIONS:
g_value_set_boolean (value, tasklist->label_decorations);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
xfce_tasklist_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
XfceTasklist *tasklist = XFCE_TASKLIST (object);
XfceTasklistSortOrder sort_order;
switch (prop_id)
{
case PROP_GROUPING:
xfce_tasklist_set_grouping (tasklist, g_value_get_boolean (value));
break;
case PROP_INCLUDE_ALL_WORKSPACES:
xfce_tasklist_set_include_all_workspaces (tasklist, g_value_get_boolean (value));
break;
case PROP_INCLUDE_ALL_MONITORS:
xfce_tasklist_set_include_all_monitors (tasklist, g_value_get_boolean (value));
break;
case PROP_FLAT_BUTTONS:
xfce_tasklist_set_button_relief (tasklist,
g_value_get_boolean (value) ? GTK_RELIEF_NONE : GTK_RELIEF_NORMAL);
break;
case PROP_SHOW_LABELS:
xfce_tasklist_set_show_labels (tasklist, g_value_get_boolean (value));
break;
case PROP_SWITCH_WORKSPACE_ON_UNMINIMIZE:
tasklist->switch_workspace = g_value_get_boolean (value);
break;
case PROP_SHOW_ONLY_MINIMIZED:
xfce_tasklist_set_show_only_minimized (tasklist, g_value_get_boolean (value));
break;
case PROP_SHOW_WIREFRAMES:
xfce_tasklist_set_show_wireframes (tasklist, WINDOWING_IS_X11 () && g_value_get_boolean (value));
break;
case PROP_SHOW_HANDLE:
tasklist->show_handle = g_value_get_boolean (value);
break;
case PROP_SHOW_TOOLTIPS:
tasklist->show_tooltips = g_value_get_boolean (value);
break;
case PROP_SORT_ORDER:
sort_order = g_value_get_uint (value);
if (tasklist->sort_order != sort_order)
{
tasklist->sort_order = sort_order;
xfce_tasklist_sort (tasklist, TRUE);
}
break;
case PROP_WINDOW_SCROLLING:
tasklist->window_scrolling = g_value_get_boolean (value);
break;
case PROP_WRAP_WINDOWS:
tasklist->wrap_windows = g_value_get_boolean (value);
break;
case PROP_INCLUDE_ALL_BLINKING:
tasklist->all_blinking = g_value_get_boolean (value);
break;
case PROP_MIDDLE_CLICK:
tasklist->middle_click = g_value_get_uint (value);
break;
case PROP_LABEL_DECORATIONS:
xfce_tasklist_set_label_decorations (tasklist, g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
xfce_tasklist_finalize (GObject *object)
{
XfceTasklist *tasklist = XFCE_TASKLIST (object);
/* data that should already be freed when disconnecting the screen */
panel_return_if_fail (tasklist->windows == NULL);
panel_return_if_fail (tasklist->skipped_windows == NULL);
panel_return_if_fail (tasklist->screen == NULL);
/* stop pending timeouts */
if (tasklist->update_icon_geometries_id != 0)
g_source_remove (tasklist->update_icon_geometries_id);
if (tasklist->update_monitor_geometry_id != 0)
g_source_remove (tasklist->update_monitor_geometry_id);
#ifdef ENABLE_X11
/* destroy the wireframe window */
xfce_tasklist_wireframe_destroy (tasklist);
#endif
(*G_OBJECT_CLASS (xfce_tasklist_parent_class)->finalize) (object);
}
static void
xfce_tasklist_get_preferred_width (GtkWidget *widget,
gint *minimum_width,
gint *natural_width)
{
XfceTasklist *tasklist = XFCE_TASKLIST (widget);
if (xfce_tasklist_horizontal (tasklist))
{
xfce_tasklist_get_preferred_length (widget, minimum_width, natural_width);
}
else
{
if (minimum_width != NULL)
*minimum_width = tasklist->size;
if (natural_width != NULL)
*natural_width = tasklist->size;
}
}
static void
xfce_tasklist_get_preferred_height (GtkWidget *widget,
gint *minimum_height,
gint *natural_height)
{
XfceTasklist *tasklist = XFCE_TASKLIST (widget);
if (!xfce_tasklist_horizontal (tasklist))
{
xfce_tasklist_get_preferred_length (widget, minimum_height, natural_height);
}
else
{
if (minimum_height != NULL)
*minimum_height = tasklist->size;
if (natural_height != NULL)
*natural_height = tasklist->size;
}
}
static void
xfce_tasklist_get_preferred_length (GtkWidget *widget,
gint *minimum_length,
gint *natural_length)
{
XfceTasklist *tasklist = XFCE_TASKLIST (widget);
gint rows, cols;
gint n_windows;
GtkRequisition child_req;
gint length = 0;
GList *li;
XfceTasklistChild *child;
gint child_size = tasklist->size / tasklist->nrows;
gint child_length = 0;
gdouble nrows_ratio = tasklist->nrows_ratio;
for (li = tasklist->windows, n_windows = 0; li != NULL; li = li->next)
{
child = li->data;
if (gtk_widget_get_visible (child->button))
{
gtk_widget_get_preferred_size (child->button, NULL, &child_req);
child_length = MAX (child_length, xfce_tasklist_horizontal (tasklist) ? child_req.width : child_req.height);
if (child->type == CHILD_TYPE_GROUP_MENU)
continue;
n_windows++;