diff options
-rw-r--r-- | src/indicator-sus.c | 102 |
1 files changed, 75 insertions, 27 deletions
diff --git a/src/indicator-sus.c b/src/indicator-sus.c index 4efc1b2..75030b3 100644 --- a/src/indicator-sus.c +++ b/src/indicator-sus.c @@ -57,24 +57,26 @@ menu_add (GtkContainer * source, GtkWidget * addee, GtkMenu * addto, guint posit } static void -status_menu_add (GtkContainer * container, GtkWidget * widget, gpointer userdata) +child_added (DbusmenuMenuitem * parent, DbusmenuMenuitem * child, guint position, guint (*posfunc) (void)) { - menu_add(container, widget, GTK_MENU(userdata), 0); - gtk_widget_show(status_separator); - return; + + } static void -users_menu_add (GtkContainer * container, GtkWidget * widget, gpointer userdata) +child_moved (DbusmenuMenuitem * parent, DbusmenuMenuitem * child, guint newpos, guint oldpos, guint (*posfunc) (void)) { - guint position = 0; - if (SEPARATOR_SHOWN(status_separator)) { - GList * location = g_list_find(GTK_MENU_SHELL(main_menu)->children, status_separator); - position = g_list_position(GTK_MENU_SHELL(main_menu)->children, location) + 1; - } - menu_add(container, widget, GTK_MENU(userdata), position); - gtk_widget_show(users_separator); + +} + + +/* Status Menu */ +static void +status_menu_add (GtkContainer * container, GtkWidget * widget, gpointer userdata) +{ + menu_add(container, widget, GTK_MENU(userdata), 0); + gtk_widget_show(status_separator); return; } @@ -110,6 +112,63 @@ build_status_menu (gpointer userdata) return FALSE; } +/* Users menu */ + +static guint +users_menu_pos_offset (void) +{ + guint position = 0; + if (SEPARATOR_SHOWN(status_separator)) { + GList * location = g_list_find(GTK_MENU_SHELL(main_menu)->children, status_separator); + position = g_list_position(GTK_MENU_SHELL(main_menu)->children, location) + 1; + } + + return position; +} + +static void +users_menu_added (DbusmenuMenuitem * root, DbusmenuMenuitem * child, guint position, gpointer user_data) +{ + gtk_widget_show(GTK_WIDGET(users_separator)); + return; +} + +static void +users_menu_removed (DbusmenuMenuitem * root, DbusmenuMenuitem * child, gpointer user_data) +{ + if (g_list_length(dbusmenu_menuitem_get_children(root)) == 0) { + gtk_widget_hide(GTK_WIDGET(users_separator)); + } + + return; +} + +static void +users_menu_root_changed(DbusmenuGtkClient * client, DbusmenuMenuitem * newroot, GtkMenu * main) +{ + if (newroot == NULL) { + gtk_widget_hide(GTK_WIDGET(users_separator)); + return; + } + + g_signal_connect(G_OBJECT(newroot), DBUSMENU_MENUITEM_SIGNAL_CHILD_ADDED, G_CALLBACK(child_added), users_menu_pos_offset); + g_signal_connect(G_OBJECT(newroot), DBUSMENU_MENUITEM_SIGNAL_CHILD_REMOVED, G_CALLBACK(users_menu_added), NULL); + g_signal_connect(G_OBJECT(newroot), DBUSMENU_MENUITEM_SIGNAL_CHILD_REMOVED, G_CALLBACK(users_menu_removed), NULL); + g_signal_connect(G_OBJECT(newroot), DBUSMENU_MENUITEM_SIGNAL_CHILD_MOVED, G_CALLBACK(child_moved), users_menu_pos_offset); + + GList * child = NULL; + guint count = 0; + for (child = dbusmenu_menuitem_get_children(newroot); child != NULL; child = g_list_next(child), count++) { + child_added(newroot, DBUSMENU_MENUITEM(child->data), count, users_menu_pos_offset); + } + + if (count > 0) { + gtk_widget_show(GTK_WIDGET(users_separator)); + } + + return; +} + static gboolean build_users_menu (gpointer userdata) { @@ -133,7 +192,7 @@ build_users_menu (gpointer userdata) } users_client = dbusmenu_gtkclient_new(INDICATOR_USERS_DBUS_NAME, INDICATOR_USERS_DBUS_OBJECT); - g_signal_connect(G_OBJECT(users_client), DBUSMENU_GTKCLIENT_SIGNAL_ROOT_CHANGED, G_CALLBACK(users_menu_add), main_menu); + g_signal_connect(G_OBJECT(users_client), DBUSMENU_GTKCLIENT_SIGNAL_ROOT_CHANGED, G_CALLBACK(users_menu_root_changed), main_menu); users_separator = gtk_separator_menu_item_new(); gtk_menu_shell_append(GTK_MENU_SHELL(main_menu), users_separator); @@ -142,20 +201,6 @@ build_users_menu (gpointer userdata) return FALSE; } -static void -child_added (DbusmenuMenuitem * parent, DbusmenuMenuitem * child, guint position, guint (*posfunc) (void)) -{ - - -} - -static void -child_moved (DbusmenuMenuitem * parent, DbusmenuMenuitem * child, guint newpos, guint oldpos, guint (*posfunc) (void)) -{ - - -} - /* Session Menu Stuff */ static guint @@ -165,6 +210,9 @@ session_menu_pos_offset (void) if (SEPARATOR_SHOWN(users_separator)) { GList * location = g_list_find(GTK_MENU_SHELL(main_menu)->children, users_separator); position = g_list_position(GTK_MENU_SHELL(main_menu)->children, location) + 1; + } else if (SEPARATOR_SHOWN(status_separator)) { + GList * location = g_list_find(GTK_MENU_SHELL(main_menu)->children, status_separator); + position = g_list_position(GTK_MENU_SHELL(main_menu)->children, location) + 1; } return position; |