From 7198caabc88b0027dcefa4dd3edfabb2fffbfed2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 4 Oct 2009 16:52:41 -0500 Subject: Switching from positioning items to having a major resort function to reposition everything. This should be a little overkill, but should work nicely with the new async startup. --- src/indicator-session.c | 52 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 6 deletions(-) (limited to 'src/indicator-session.c') diff --git a/src/indicator-session.c b/src/indicator-session.c index a4bb5e1..c367e3a 100644 --- a/src/indicator-session.c +++ b/src/indicator-session.c @@ -84,10 +84,52 @@ get_icon (void) typedef struct _realized_data_t realized_data_t; struct _realized_data_t { - guint position; section_t section; }; +static void +resort_menu (void) +{ + guint location = 0; + guint clientnum; + + for (clientnum = 0; clientnum < 3; clientnum++) { + DbusmenuGtkClient * client = NULL; + if (clientnum == 0) client = status_client; + if (clientnum == 1) client = users_client; + if (clientnum == 2) client = session_client; + + if (client == NULL) continue; + + DbusmenuMenuitem * root = dbusmenu_client_get_root(DBUSMENU_CLIENT(client)); + + GList * children = dbusmenu_menuitem_get_children(root); + if (children == NULL) { + continue; + } + + GList * child; + for (child = children; child != NULL; child = g_list_next(child)) { + GtkMenuItem * widget = dbusmenu_gtkclient_menuitem_get(client, DBUSMENU_MENUITEM(child->data)); + if (widget != NULL) { + gtk_menu_reorder_child(main_menu, GTK_WIDGET(widget), location); + location++; + } + } + + if (clientnum == 0) { + gtk_menu_reorder_child(main_menu, status_separator, location); + location++; + } + if (clientnum == 1) { + gtk_menu_reorder_child(main_menu, users_separator, location); + location++; + } + } + + return; +} + static void child_added (DbusmenuMenuitem * parent, DbusmenuMenuitem * child, guint position, gpointer section) { @@ -97,7 +139,6 @@ child_added (DbusmenuMenuitem * parent, DbusmenuMenuitem * child, guint position return; } - data->position = position; data->section = GPOINTER_TO_UINT(section); g_signal_connect(G_OBJECT(child), DBUSMENU_MENUITEM_SIGNAL_REALIZED, G_CALLBACK(child_realized), data); @@ -111,7 +152,6 @@ child_realized (DbusmenuMenuitem * child, gpointer userdata) g_return_if_fail(DBUSMENU_IS_MENUITEM(child)); realized_data_t * data = (realized_data_t *)userdata; - guint position = data->position; section_t section = data->section; g_free(data); @@ -145,8 +185,6 @@ child_realized (DbusmenuMenuitem * child, gpointer userdata) return; } - position += posfunc(); - g_debug("SUS: Adding child: %d", position); GtkMenuItem * widget = dbusmenu_gtkclient_menuitem_get(client, child); if (widget == NULL) { @@ -154,9 +192,11 @@ child_realized (DbusmenuMenuitem * child, gpointer userdata) return; } - gtk_menu_insert(main_menu, GTK_WIDGET(widget), position); + gtk_menu_append(main_menu, GTK_WIDGET(widget)); gtk_widget_show(GTK_WIDGET(widget)); + resort_menu(); + gtk_widget_hide(loading_item); return; -- cgit v1.2.3