aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2014-01-29 14:16:59 +0100
committerLars Uebernickel <lars.uebernickel@canonical.com>2014-01-29 14:16:59 +0100
commit239817c96343b70d7e655d25cf12025d9df81d55 (patch)
tree12ff89b339f7bd10222f197c2296252f1cbc6579
parent759fdd8e61a90a0c13ccd0d1f2665507fd7d00e7 (diff)
downloadlibayatana-indicator-239817c96343b70d7e655d25cf12025d9df81d55.tar.gz
libayatana-indicator-239817c96343b70d7e655d25cf12025d9df81d55.tar.bz2
libayatana-indicator-239817c96343b70d7e655d25cf12025d9df81d55.zip
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.
-rw-r--r--libindicator/indicator-ng.c34
1 files changed, 34 insertions, 0 deletions
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);
}
@@ -214,6 +216,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.