From 239817c96343b70d7e655d25cf12025d9df81d55 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Wed, 29 Jan 2014 14:16:59 +0100 Subject: indicator-ng: support "submenu-action" on root menu items Treat "submenu-action" attributes on the root menu item in the same way that gtk+ does. If that attribute exists, it must reference an action with boolean state that is set to 'true' whenever a corresponding indicator menu is open. We need this for root items because they are not handled by gtk's menu tracker. Nested submenus already get this. --- libindicator/indicator-ng.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/libindicator/indicator-ng.c b/libindicator/indicator-ng.c index c7a4899..d83a2b5 100644 --- a/libindicator/indicator-ng.c +++ b/libindicator/indicator-ng.c @@ -35,6 +35,7 @@ struct _IndicatorNg gchar *header_action; gchar *scroll_action; gchar *secondary_action; + gchar *submenu_action; gint position; guint name_watch_id; @@ -162,6 +163,7 @@ indicator_ng_finalize (GObject *object) g_free (self->header_action); g_free (self->scroll_action); g_free (self->secondary_action); + g_free (self->submenu_action); G_OBJECT_CLASS (indicator_ng_parent_class)->finalize (object); } @@ -213,6 +215,28 @@ indicator_ng_secondary_activate (IndicatorObject *io, } } +static void +indicator_ng_menu_shown (GtkWidget *widget, + gpointer user_data) +{ + IndicatorNg *self = user_data; + + if (self->submenu_action) + g_action_group_change_action_state (self->actions, self->submenu_action, + g_variant_new_boolean (TRUE)); +} + +static void +indicator_ng_menu_hidden (GtkWidget *widget, + gpointer user_data) +{ + IndicatorNg *self = user_data; + + if (self->submenu_action) + g_action_group_change_action_state (self->actions, self->submenu_action, + g_variant_new_boolean (FALSE)); +} + static void indicator_ng_set_accessible_desc (IndicatorNg *self, const gchar *accessible_desc) @@ -390,6 +414,13 @@ indicator_ng_menu_changed (GMenuModel *menu, g_free (action); } + if (g_menu_model_get_item_attribute (self->menu, 0, "submenu-action", "s", &action)) + { + if (g_str_has_prefix (action, "indicator.")) + self->submenu_action = g_strdup (action + strlen ("indicator.")); + g_free (action); + } + popup = g_menu_model_get_item_link (self->menu, 0, G_MENU_LINK_SUBMENU); if (popup) { @@ -657,6 +688,9 @@ indicator_ng_init (IndicatorNg *self) self->entry.menu = g_object_ref_sink (gtk_menu_new ()); + g_signal_connect (self->entry.menu, "show", G_CALLBACK (indicator_ng_menu_shown), self); + g_signal_connect (self->entry.menu, "hide", G_CALLBACK (indicator_ng_menu_hidden), self); + /* work around IndicatorObject's warning that the accessible * description is missing. We never set it on construction, but when * the menu model has arrived on the bus. -- cgit v1.2.3