[PATCH] tasklist: Introduce option to disable count indicator

Shawn Anastasio shawn at anastas.io
Thu Jul 11 00:59:31 CEST 2019


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 lablel.

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 @@
                             <property name="position">2</property>
                           </packing>
                         </child>
+                        <child>
+                          <object class="GtkCheckButton" id="show-count-indicator">
+                            <property name="label" translatable="yes">Show _count indicator</property>
+                            <property name="use_action_appearance">False</property>
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="receives_default">False</property>
+                            <property name="use_underline">True</property>
+                            <property name="draw_indicator">True</property>
+                          </object>
+                          <packing>
+                            <property name="expand">True</property>
+                            <property name="fill">True</property>
+                            <property name="position">3</property>
+                          </packing>
+                        </child>
                         <child>
                           <object class="GtkBox" id="hbox2">
                             <property name="visible">True</property>
@@ -241,7 +257,7 @@
                           <packing>
                             <property name="expand">True</property>
                             <property name="fill">True</property>
-                            <property name="position">3</property>
+                            <property name="position">4</property>
                           </packing>
                         </child>
                       </object>
diff --git a/plugins/tasklist/tasklist-widget.c b/plugins/tasklist/tasklist-widget.c
index fc919b5b..bcdb4603 100644
--- a/plugins/tasklist/tasklist-widget.c
+++ b/plugins/tasklist/tasklist-widget.c
@@ -82,6 +82,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,
@@ -122,6 +123,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;
 
@@ -356,6 +360,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,
@@ -436,6 +442,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",
@@ -694,6 +707,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;
@@ -771,6 +788,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;
@@ -3664,7 +3685,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);
@@ -3815,7 +3836,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 */
@@ -4167,6 +4202,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



More information about the Xfce4-dev mailing list