[Xfce4-commits] <xfce4-indicator-plugin:andrzejr/tmp2> Support for indicator ordering.
Andrzej
noreply at xfce.org
Thu Mar 29 18:58:04 CEST 2012
Updating branch refs/heads/andrzejr/tmp2
to 1b13cca086cf1259b3d427c5121201de1a778c17 (commit)
from d59fbfc202bd55d0821037b250e89cb31100457e (commit)
commit 1b13cca086cf1259b3d427c5121201de1a778c17
Author: Andrzej <ndrwrdck at gmail.com>
Date: Fri Mar 30 01:56:45 2012 +0900
Support for indicator ordering.
Use entry ordering as specified by indicator object class. Unfortunately,
the order is often ambiguous (e.g. most entries are assigned position "0").
panel-plugin/indicator-box.c | 41 ++++++++++++++++++++++++++++++++++++++++-
panel-plugin/indicator-box.h | 2 ++
panel-plugin/indicator.c | 12 ++++++++++++
3 files changed, 54 insertions(+), 1 deletions(-)
diff --git a/panel-plugin/indicator-box.c b/panel-plugin/indicator-box.c
index 700a218..63f648d 100644
--- a/panel-plugin/indicator-box.c
+++ b/panel-plugin/indicator-box.c
@@ -47,6 +47,8 @@ static void xfce_indicator_box_size_request (GtkWidget
static void xfce_indicator_box_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
static gint xfce_indicator_box_get_row_size (XfceIndicatorBox *box);
+static gint xfce_indicator_box_compare_func (gconstpointer a,
+ gconstpointer b);
enum
@@ -284,7 +286,7 @@ xfce_indicator_box_add (GtkContainer *container,
g_return_if_fail (GTK_IS_WIDGET (child));
g_return_if_fail (child->parent == NULL);
- box->children = g_slist_append (box->children, child);
+ box->children = g_slist_insert_sorted (box->children, child, xfce_indicator_box_compare_func);
gtk_widget_set_parent (child, GTK_WIDGET (box));
xfce_indicator_button_set_orientation (button, box->panel_orientation, box->orientation);
@@ -542,3 +544,40 @@ xfce_indicator_box_get_button (XfceIndicatorBox *box,
}
return NULL;
}
+
+
+void
+xfce_indicator_box_sort (XfceIndicatorBox *box)
+{
+ GSList *li;
+
+ g_return_if_fail (XFCE_IS_INDICATOR_BOX (box));
+
+ li = g_slist_sort (box->children, xfce_indicator_box_compare_func);
+ g_object_unref (G_OBJECT (box->children));
+ box->children = li;
+
+ gtk_widget_queue_resize (GTK_WIDGET (box));
+}
+
+
+static gint
+xfce_indicator_box_compare_func (gconstpointer a,
+ gconstpointer b)
+{
+ XfceIndicatorButton *button_a, *button_b;
+ gint pos_a, pos_b;
+
+ g_return_val_if_fail (XFCE_IS_INDICATOR_BUTTON (a), 0);
+ g_return_val_if_fail (XFCE_IS_INDICATOR_BUTTON (b), 0);
+
+ button_a = XFCE_INDICATOR_BUTTON (a);
+ button_b = XFCE_INDICATOR_BUTTON (b);
+
+ pos_a = indicator_object_get_location (xfce_indicator_button_get_io (button_a),
+ xfce_indicator_button_get_entry (button_a));
+ pos_b = indicator_object_get_location (xfce_indicator_button_get_io (button_b),
+ xfce_indicator_button_get_entry (button_b));
+
+ return pos_a - pos_b;
+}
diff --git a/panel-plugin/indicator-box.h b/panel-plugin/indicator-box.h
index e302279..3743a42 100644
--- a/panel-plugin/indicator-box.h
+++ b/panel-plugin/indicator-box.h
@@ -67,6 +67,8 @@ void xfce_indicator_box_set_size (XfceIndicatorBox *box,
XfceIndicatorButton *xfce_indicator_box_get_button (XfceIndicatorBox *box,
IndicatorObjectEntry *entry);
+void xfce_indicator_box_sort (XfceIndicatorBox *box);
+
GtkWidget *xfce_indicator_box_new ();
G_END_DECLS
diff --git a/panel-plugin/indicator.c b/panel-plugin/indicator.c
index e1047cc..8dd017e 100644
--- a/panel-plugin/indicator.c
+++ b/panel-plugin/indicator.c
@@ -361,6 +361,16 @@ entry_added (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_d
static void
+entry_moved (IndicatorObject * io, IndicatorObjectEntry * entry, gint old, gint new, gpointer user_data)
+{
+ XfceIndicatorBox *box;
+
+ box = XFCE_INDICATOR_BOX (((IndicatorPlugin *)user_data)->buttonbox);
+ xfce_indicator_box_sort(box);
+}
+
+
+static void
entry_removed (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_data)
{
XfceIndicatorButton *button;
@@ -391,6 +401,8 @@ load_module (const gchar * name, IndicatorPlugin * indicator)
G_CALLBACK(entry_added), indicator);
g_signal_connect(G_OBJECT(io), INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED,
G_CALLBACK(entry_removed), indicator->buttonbox);
+ g_signal_connect(G_OBJECT(io), INDICATOR_OBJECT_SIGNAL_ENTRY_MOVED,
+ G_CALLBACK(entry_moved), indicator->buttonbox);
GList * entries = indicator_object_get_entries(io);
GList * entry = NULL;
More information about the Xfce4-commits
mailing list