From 7fbe414c6de450874f3a72c34e4e9cc9979ca420 Mon Sep 17 00:00:00 2001 From: Shawn Anastasio Date: Sun, 11 Aug 2019 09:48:28 -0500 Subject: [PATCH] tasklist: Allow disabling grouped windows count indicator commit 36bc57e035e0 ("tasklist: Draw grouped windows count indicator") changed the behavior for window groups by displaying the window count in a cairo drawn indicator instead of showing the count as part of the label. This patch introduces a toggle to restore the previous functionality for users who prefer the previous look. --- plugins/tasklist/tasklist-dialog.glade | 18 ++++++- plugins/tasklist/tasklist-widget.c | 74 +++++++++++++++++++++++++- plugins/tasklist/tasklist.c | 2 + 3 files changed, 91 insertions(+), 3 deletions(-) diff --git a/plugins/tasklist/tasklist-dialog.glade b/plugins/tasklist/tasklist-dialog.glade index a22d24b1..19f3df7c 100644 --- a/plugins/tasklist/tasklist-dialog.glade +++ b/plugins/tasklist/tasklist-dialog.glade @@ -200,6 +200,22 @@ 2 + + + Show _count indicator + False + True + True + False + True + True + + + True + True + 3 + + True @@ -241,7 +257,7 @@ True True - 3 + 4 diff --git a/plugins/tasklist/tasklist-widget.c b/plugins/tasklist/tasklist-widget.c index 74119d1a..40a1cc20 100644 --- a/plugins/tasklist/tasklist-widget.c +++ b/plugins/tasklist/tasklist-widget.c @@ -83,6 +83,7 @@ enum PROP_INCLUDE_ALL_MONITORS, PROP_FLAT_BUTTONS, PROP_SWITCH_WORKSPACE_ON_UNMINIMIZE, + PROP_SHOW_COUNT_INDICATOR, PROP_SHOW_LABELS, PROP_SHOW_ONLY_MINIMIZED, PROP_SHOW_WIREFRAMES, @@ -123,6 +124,9 @@ struct _XfceTasklist /* classgroups of all the windows in the taskbar */ GHashTable *class_groups; + /* whether we show the count indicator for window groups */ + guint show_count_indicator : 1; + /* normal or iconbox style */ guint show_labels : 1; @@ -357,6 +361,8 @@ static void xfce_tasklist_set_include_all_monitors (XfceTa gboolean all_monitors); static void xfce_tasklist_set_button_relief (XfceTasklist *tasklist, GtkReliefStyle button_relief); +static void xfce_tasklist_set_show_count_indicator (XfceTasklist *tasklist, + gboolean show_labels); static void xfce_tasklist_set_show_labels (XfceTasklist *tasklist, gboolean show_labels); static void xfce_tasklist_set_show_only_minimized (XfceTasklist *tasklist, @@ -437,6 +443,13 @@ xfce_tasklist_class_init (XfceTasklistClass *klass) TRUE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + g_object_class_install_property (gobject_class, + PROP_SHOW_COUNT_INDICATOR, + g_param_spec_boolean ("show-count-indicator", + 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", @@ -695,6 +708,10 @@ xfce_tasklist_get_property (GObject *object, g_value_set_boolean (value, tasklist->switch_workspace); break; + case PROP_SHOW_COUNT_INDICATOR: + g_value_set_boolean (value, tasklist->show_count_indicator); + break; + case PROP_SHOW_LABELS: g_value_set_boolean (value, tasklist->show_labels); break; @@ -772,6 +789,10 @@ xfce_tasklist_set_property (GObject *object, GTK_RELIEF_NONE : GTK_RELIEF_NORMAL); break; + case PROP_SHOW_COUNT_INDICATOR: + xfce_tasklist_set_show_count_indicator (tasklist, g_value_get_boolean (value)); + break; + case PROP_SHOW_LABELS: xfce_tasklist_set_show_labels (tasklist, g_value_get_boolean (value)); break; @@ -3699,7 +3720,7 @@ xfce_tasklist_group_button_button_draw (GtkWidget *widget, cairo_t *cr, XfceTasklistChild *group_child) { - if (group_child->n_windows > 1) + if (group_child->n_windows > 1 && group_child->tasklist->show_count_indicator) { GtkStyleContext *context; GtkAllocation *allocation = g_new0 (GtkAllocation, 1); @@ -3863,7 +3884,21 @@ xfce_tasklist_group_button_name_changed (WnckClassGroup *class_group, /* create the button label */ name = wnck_class_group_get_name (group_child->class_group); - gtk_label_set_text (GTK_LABEL (group_child->label), name); + + /* add number of windows to label text if the indicator is disabled */ + if (!group_child->tasklist->show_count_indicator) + { + gchar *label; + if (!panel_str_is_empty (name)) + label = g_strdup_printf ("%s (%d)", name, group_child->n_windows); + else + label = g_strdup_printf ("(%d)", group_child->n_windows); + + gtk_label_set_text (GTK_LABEL (group_child->label), label); + g_free (label); + } + else + gtk_label_set_text (GTK_LABEL (group_child->label), name); /* don't sort if there is no need to update the sorting (ie. only number * of windows is changed or button is not inserted in the tasklist yet */ @@ -4215,6 +4250,41 @@ xfce_tasklist_set_button_relief (XfceTasklist *tasklist, } } +static void +xfce_tasklist_set_show_count_indicator (XfceTasklist *tasklist, + gboolean show_count_indicator) +{ + GList *li; + XfceTasklistChild *child; + + panel_return_if_fail (XFCE_IS_TASKLIST (tasklist)); + + show_count_indicator = !!show_count_indicator; + + if (tasklist->show_count_indicator != show_count_indicator) + { + GHashTableIter iter; + XfceTasklistChild *child; + + tasklist->show_count_indicator = show_count_indicator; + + /* don't do anything if tasklist grouping isn't enabled */ + if (tasklist->grouping == XFCE_TASKLIST_GROUPING_NEVER) + return; + + /* iterate through all buttons and redraw indicator */ + g_hash_table_iter_init (&iter, tasklist->class_groups); + while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&child)) + { + if (child == NULL) + continue; + + /* redraw this button and update label */ + gtk_widget_queue_resize (GTK_WIDGET (child->button)); + xfce_tasklist_group_button_name_changed(NULL, child); + } + } +} static void diff --git a/plugins/tasklist/tasklist.c b/plugins/tasklist/tasklist.c index 8c06596d..52303201 100644 --- a/plugins/tasklist/tasklist.c +++ b/plugins/tasklist/tasklist.c @@ -142,6 +142,7 @@ tasklist_plugin_construct (XfcePanelPlugin *panel_plugin) { "include-all-monitors", G_TYPE_BOOLEAN }, { "flat-buttons", G_TYPE_BOOLEAN }, { "switch-workspace-on-unminimize", G_TYPE_BOOLEAN }, + { "show-count-indicator", G_TYPE_BOOLEAN }, { "show-only-minimized", G_TYPE_BOOLEAN }, { "show-wireframes", G_TYPE_BOOLEAN }, { "show-handle", G_TYPE_BOOLEAN }, @@ -259,6 +260,7 @@ tasklist_plugin_configure_plugin (XfcePanelPlugin *panel_plugin) TASKLIST_DIALOG_BIND ("include-all-monitors", "active") TASKLIST_DIALOG_BIND ("flat-buttons", "active") TASKLIST_DIALOG_BIND_INV ("switch-workspace-on-unminimize", "active") + TASKLIST_DIALOG_BIND ("show-count-indicator", "active") TASKLIST_DIALOG_BIND ("show-only-minimized", "active") TASKLIST_DIALOG_BIND ("show-wireframes", "active") TASKLIST_DIALOG_BIND ("show-handle", "active") -- 2.22.0