[Xfce4-commits] <xfce4-panel:devel> Insert sorting modes in the tasklist.
Nick Schermer
noreply at xfce.org
Fri Nov 27 14:12:03 CET 2009
Updating branch refs/heads/devel
to e380cbf0368dc9e6ed7dda40f1d5b8b1f2ce9859 (commit)
from 535862d07b90b82a62490247b6020be6eafb5253 (commit)
commit e380cbf0368dc9e6ed7dda40f1d5b8b1f2ce9859
Author: Nick Schermer <nick at xfce.org>
Date: Fri Nov 27 14:10:47 2009 +0100
Insert sorting modes in the tasklist.
plugins/tasklist/tasklist-dialog.ui | 58 ++++++++++++++++++
plugins/tasklist/tasklist-widget.c | 111 ++++++++++++++++++++++++++++++++--
plugins/tasklist/tasklist-widget.h | 25 ++++++--
plugins/tasklist/tasklist.c | 2 +
4 files changed, 183 insertions(+), 13 deletions(-)
diff --git a/plugins/tasklist/tasklist-dialog.ui b/plugins/tasklist/tasklist-dialog.ui
index 8af02a8..4bce204 100644
--- a/plugins/tasklist/tasklist-dialog.ui
+++ b/plugins/tasklist/tasklist-dialog.ui
@@ -73,6 +73,43 @@
<property name="position">2</property>
</packing>
</child>
+ <child>
+ <object class="GtkHBox" id="hbox2">
+ <property name="visible">True</property>
+ <property name="spacing">12</property>
+ <child>
+ <object class="GtkLabel" id="label5">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Sorting _order:</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">sort-order</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkComboBox" id="sort-order">
+ <property name="visible">True</property>
+ <property name="model">sort-order-model</property>
+ <child>
+ <object class="GtkCellRendererText" id="cellrenderertext1"/>
+ <attributes>
+ <attribute name="text">0</attribute>
+ </attributes>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="position">3</property>
+ </packing>
+ </child>
</object>
</child>
</object>
@@ -117,6 +154,7 @@
<property name="xalign">0</property>
<property name="label" translatable="yes">Window _grouping:</property>
<property name="use_underline">True</property>
+ <property name="mnemonic_widget">grouping</property>
</object>
<packing>
<property name="expand">False</property>
@@ -302,4 +340,24 @@
</row>
</data>
</object>
+ <object class="GtkListStore" id="sort-order-model">
+ <columns>
+ <!-- column-name title -->
+ <column type="gchararray"/>
+ </columns>
+ <data>
+ <row>
+ <col id="0" translatable="yes">Timestamp</col>
+ </row>
+ <row>
+ <col id="0" translatable="yes">Group name and timestamp</col>
+ </row>
+ <row>
+ <col id="0" translatable="yes">Window title</col>
+ </row>
+ <row>
+ <col id="0" translatable="yes">Group- and window title</col>
+ </row>
+ </data>
+ </object>
</interface>
diff --git a/plugins/tasklist/tasklist-widget.c b/plugins/tasklist/tasklist-widget.c
index ab88c39..2681612 100644
--- a/plugins/tasklist/tasklist-widget.c
+++ b/plugins/tasklist/tasklist-widget.c
@@ -52,7 +52,8 @@ enum
PROP_SHOW_LABELS,
PROP_SHOW_ONLY_MINIMIZED,
PROP_SHOW_WIREFRAMES,
- PROP_SHOW_HANDLE
+ PROP_SHOW_HANDLE,
+ PROP_SORT_ORDER
};
struct _XfceTasklistClass
@@ -107,6 +108,9 @@ struct _XfceTasklist
/* button grouping mode */
XfceTasklistGrouping grouping;
+ /* sorting order of the buttons */
+ XfceTasklistSortOrder sort_order;
+
/* dummy property */
guint show_handle : 1;
@@ -167,6 +171,8 @@ static void xfce_tasklist_viewports_changed (WnckScreen *screen, XfceTasklist *t
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);
+static void xfce_tasklist_sort (XfceTasklist *tasklist);
+static gint xfce_tasklist_button_compare (gconstpointer a, gconstpointer b, gpointer user_data);
static void xfce_tasklist_button_new (XfceTasklistChild *child);
static void xfce_tasklist_set_include_all_workspaces (XfceTasklist *tasklist, gboolean all_workspaces);
static void xfce_tasklist_set_button_relief (XfceTasklist *tasklist, GtkReliefStyle button_relief);
@@ -263,6 +269,15 @@ xfce_tasklist_class_init (XfceTasklistClass *klass)
TRUE,
EXO_PARAM_READWRITE));
+ 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,
+ EXO_PARAM_READWRITE));
+
gtk_widget_class_install_style_property (gtkwidget_class,
g_param_spec_int ("max-button-length",
NULL,
@@ -314,6 +329,7 @@ xfce_tasklist_init (XfceTasklist *tasklist)
tasklist->max_button_size = DEFAULT_BUTTON_SIZE;
tasklist->ellipsize_mode = PANGO_ELLIPSIZE_END;
tasklist->grouping = XFCE_TASKLIST_GROUPING_DEFAULT;
+ tasklist->sort_order = XFCE_TASKLIST_SORT_ORDER_DEFAULT;
}
@@ -360,6 +376,10 @@ xfce_tasklist_get_property (GObject *object,
g_value_set_boolean (value, tasklist->show_handle);
break;
+ case PROP_SORT_ORDER:
+ g_value_set_uint (value, tasklist->sort_order);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -374,7 +394,8 @@ xfce_tasklist_set_property (GObject *object,
const GValue *value,
GParamSpec *pspec)
{
- XfceTasklist *tasklist = XFCE_TASKLIST (object);
+ XfceTasklist *tasklist = XFCE_TASKLIST (object);
+ XfceTasklistSortOrder sort_order;
switch (prop_id)
{
@@ -418,6 +439,15 @@ xfce_tasklist_set_property (GObject *object,
tasklist->show_handle = 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);
+ }
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -940,7 +970,9 @@ xfce_tasklist_window_added (WnckScreen *screen,
xfce_tasklist_button_new (child);
/* insert in the internal list */
- tasklist->children = g_slist_append (tasklist->children, child);
+ tasklist->children = g_slist_insert_sorted_with_data (tasklist->children, child,
+ xfce_tasklist_button_compare,
+ tasklist);
/* set the parent */
gtk_widget_set_parent (child->button, GTK_WIDGET (tasklist));
@@ -1122,9 +1154,66 @@ xfce_tasklist_wireframe_update (XfceTasklist *tasklist,
+static void
+xfce_tasklist_sort (XfceTasklist *tasklist)
+{
+ panel_return_if_fail (XFCE_IS_TASKLIST (tasklist));
+
+ tasklist->children = g_slist_sort_with_data (tasklist->children,
+ xfce_tasklist_button_compare,
+ tasklist);
+
+ gtk_widget_queue_resize (GTK_WIDGET (tasklist));
+}
+
+
+
/**************************************************************
**************************************************************
**************************************************************/
+static gint
+xfce_tasklist_button_compare (gconstpointer child_a,
+ gconstpointer child_b,
+ gpointer user_data)
+{
+ const XfceTasklistChild *a = child_a, *b = child_b;
+ XfceTasklist *tasklist = XFCE_TASKLIST (user_data);
+ gint retval;
+
+ panel_return_val_if_fail (WNCK_IS_WINDOW (a->window), 0);
+ panel_return_val_if_fail (WNCK_IS_WINDOW (b->window), 0);
+
+ if (tasklist->all_workspaces)
+ {
+ /* todo, keep workspaces together */
+ }
+
+ if (tasklist->sort_order == XFCE_TASKLIST_SORT_ORDER_GROUP_TITLE
+ || tasklist->sort_order == XFCE_TASKLIST_SORT_ORDER_GROUP_TIMESTAMP)
+ {
+ panel_return_val_if_fail (WNCK_IS_CLASS_GROUP (a->class_group), 0);
+ panel_return_val_if_fail (WNCK_IS_CLASS_GROUP (b->class_group), 0);
+
+ retval = g_utf8_collate (wnck_class_group_get_name (a->class_group),
+ wnck_class_group_get_name (b->class_group));
+ if (retval != 0)
+ return retval;
+ }
+
+ if (tasklist->sort_order == XFCE_TASKLIST_SORT_ORDER_TIMESTAMP
+ || tasklist->sort_order == XFCE_TASKLIST_SORT_ORDER_GROUP_TIMESTAMP)
+ {
+ return a->unique_id - b->unique_id;
+ }
+ else
+ {
+ return g_utf8_collate (wnck_window_get_name (a->window),
+ wnck_window_get_name (b->window));
+ }
+}
+
+
+
static void
tasklist_button_icon_changed (WnckWindow *window,
XfceTasklistChild *child)
@@ -1194,6 +1283,9 @@ tasklist_button_name_changed (WnckWindow *window,
/* cleanup */
g_free (label);
+
+ /* sort the tasklist */
+ xfce_tasklist_sort (child->tasklist);
}
@@ -1241,10 +1333,15 @@ tasklist_button_workspace_changed (WnckWindow *window,
{
/* leave when we show application from all workspaces */
if (child->tasklist->all_workspaces)
- return;
-
- /* hide the button */
- gtk_widget_hide (child->button);
+ {
+ /* sort the tasklist */
+ xfce_tasklist_sort (child->tasklist);
+ }
+ else
+ {
+ /* hide the button */
+ gtk_widget_hide (child->button);
+ }
}
diff --git a/plugins/tasklist/tasklist-widget.h b/plugins/tasklist/tasklist-widget.h
index 077f862..48da478 100644
--- a/plugins/tasklist/tasklist-widget.h
+++ b/plugins/tasklist/tasklist-widget.h
@@ -23,11 +23,12 @@
G_BEGIN_DECLS
-typedef struct _XfceTasklistClass XfceTasklistClass;
-typedef struct _XfceTasklist XfceTasklist;
-typedef struct _XfceTasklistChild XfceTasklistChild;
-typedef enum _XfceTasklistStyle XfceTasklistStyle;
-typedef enum _XfceTasklistGrouping XfceTasklistGrouping;
+typedef struct _XfceTasklistClass XfceTasklistClass;
+typedef struct _XfceTasklist XfceTasklist;
+typedef struct _XfceTasklistChild XfceTasklistChild;
+typedef enum _XfceTasklistStyle XfceTasklistStyle;
+typedef enum _XfceTasklistGrouping XfceTasklistGrouping;
+typedef enum _XfceTasklistSortOrder XfceTasklistSortOrder;
#define XFCE_TYPE_TASKLIST (xfce_tasklist_get_type ())
#define XFCE_TASKLIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XFCE_TYPE_TASKLIST, XfceTasklist))
@@ -41,7 +42,7 @@ typedef enum _XfceTasklistGrouping XfceTasklistGrouping;
enum _XfceTasklistGrouping
{
XFCE_TASKLIST_GROUPING_NEVER,
- XFCE_TASKLIST_GROUPING_AUTO,
+ XFCE_TASKLIST_GROUPING_AUTO, /* when space is limited */
XFCE_TASKLIST_GROUPING_ALWAYS,
XFCE_TASKLIST_GROUPING_MIN = XFCE_TASKLIST_GROUPING_NEVER,
@@ -49,6 +50,18 @@ enum _XfceTasklistGrouping
XFCE_TASKLIST_GROUPING_DEFAULT = XFCE_TASKLIST_GROUPING_AUTO
};
+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_MIN = XFCE_TASKLIST_SORT_ORDER_TIMESTAMP,
+ XFCE_TASKLIST_SORT_ORDER_MAX = XFCE_TASKLIST_SORT_ORDER_GROUP_TITLE,
+ XFCE_TASKLIST_SORT_ORDER_DEFAULT = XFCE_TASKLIST_SORT_ORDER_GROUP_TIMESTAMP
+};
+
GType xfce_tasklist_get_type (void) G_GNUC_CONST;
diff --git a/plugins/tasklist/tasklist.c b/plugins/tasklist/tasklist.c
index c1a5a9d..c785817 100644
--- a/plugins/tasklist/tasklist.c
+++ b/plugins/tasklist/tasklist.c
@@ -127,6 +127,7 @@ tasklist_plugin_construct (XfcePanelPlugin *panel_plugin)
{ "show-only-minimized", G_TYPE_BOOLEAN },
{ "show-wireframes", G_TYPE_BOOLEAN },
{ "show-handle", G_TYPE_BOOLEAN },
+ { "sort-order", G_TYPE_UINT },
{ NULL }
};
@@ -209,6 +210,7 @@ tasklist_plugin_configure_plugin (XfcePanelPlugin *panel_plugin)
TASKLIST_DIALOG_BIND ("show-only-minimized", "active")
TASKLIST_DIALOG_BIND ("show-wireframes", "active")
TASKLIST_DIALOG_BIND ("show-handle", "active")
+ TASKLIST_DIALOG_BIND ("sort-order", "active")
gtk_widget_show (GTK_WIDGET (dialog));
}
More information about the Xfce4-commits
mailing list