From f4fa56637405eb2112ad3516e3ac1438e79f0d41 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Mon, 9 Sep 2013 13:40:49 +0200 Subject: Support "x-canonical-scroll-action" An attribute that can be set on the root menu item. If it exists, it must point to an action that is activatable with a int32 parameter. It is activated on scroll events. The parameter signifies magnitude and direction of the scroll. --- libindicator/indicator-ng.c | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) (limited to 'libindicator') diff --git a/libindicator/indicator-ng.c b/libindicator/indicator-ng.c index d8ac840..3e63dcd 100644 --- a/libindicator/indicator-ng.c +++ b/libindicator/indicator-ng.c @@ -33,6 +33,7 @@ struct _IndicatorNg gchar *bus_name; gchar *profile; gchar *header_action; + gchar *scroll_action; gint position; guint name_watch_id; @@ -158,6 +159,7 @@ indicator_ng_finalize (GObject *object) g_free (self->bus_name); g_free (self->accessible_desc); g_free (self->header_action); + g_free (self->scroll_action); G_OBJECT_CLASS (indicator_ng_parent_class)->finalize (object); } @@ -178,6 +180,23 @@ indicator_ng_get_position (IndicatorObject *io) return self->position; } +static void +indicator_ng_entry_scrolled (IndicatorObject *io, + IndicatorObjectEntry *entry, + gint delta, + IndicatorScrollDirection direction) +{ + IndicatorNg *self = INDICATOR_NG (io); + + if (self->actions && self->scroll_action) + { + if (direction == INDICATOR_OBJECT_SCROLL_DOWN) + delta *= -1; + g_action_group_activate_action (self->actions, self->scroll_action, + g_variant_new_int32 (delta)); + } +} + static void indicator_ng_set_accessible_desc (IndicatorNg *self, const gchar *accessible_desc) @@ -332,16 +351,25 @@ indicator_ng_menu_changed (GMenuModel *menu, if (added) { g_clear_pointer (&self->header_action, g_free); + g_clear_pointer (&self->scroll_action, g_free); if (indicator_ng_menu_item_is_of_type (self->menu, 0, "com.canonical.indicator.root")) { GMenuModel *popup; gchar *action; - if (g_menu_model_get_item_attribute (self->menu, 0, G_MENU_ATTRIBUTE_ACTION, "s", &action) && - g_str_has_prefix (action, "indicator.")) + if (g_menu_model_get_item_attribute (self->menu, 0, G_MENU_ATTRIBUTE_ACTION, "s", &action)) + { + if (g_str_has_prefix (action, "indicator.")) + self->header_action = g_strdup (action + strlen ("indicator.")); + g_free (action); + } + + if (g_menu_model_get_item_attribute (self->menu, 0, "x-canonical-scroll-action", "s", &action)) { - self->header_action = g_strdup (action + strlen ("indicator.")); + if (g_str_has_prefix (action, "indicator.")) + self->scroll_action = g_strdup (action + strlen ("indicator.")); + g_free (action); } popup = g_menu_model_get_item_link (self->menu, 0, G_MENU_LINK_SUBMENU); @@ -352,8 +380,6 @@ indicator_ng_menu_changed (GMenuModel *menu, } indicator_ng_update_entry (self); - - g_free (action); } else g_warning ("indicator menu item must be of type 'com.canonical.indicator.root'"); @@ -570,6 +596,7 @@ indicator_ng_class_init (IndicatorNgClass *class) io_class->get_entries = indicator_ng_get_entries; io_class->get_position = indicator_ng_get_position; + io_class->entry_scrolled = indicator_ng_entry_scrolled; properties[PROP_SERVICE_FILE] = g_param_spec_string ("service-file", "Service file", -- cgit v1.2.3 From bb3936226c41048e4c16e9b926d6c9b23629d681 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Mon, 9 Sep 2013 14:09:57 +0200 Subject: Support x-canonical-secondary action An attribute for the root menu action may contain an action name. If it exists, the action is activated whenever the middle mouse button is pressed on the indicator. --- libindicator/indicator-ng.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'libindicator') diff --git a/libindicator/indicator-ng.c b/libindicator/indicator-ng.c index 3e63dcd..3971129 100644 --- a/libindicator/indicator-ng.c +++ b/libindicator/indicator-ng.c @@ -34,6 +34,7 @@ struct _IndicatorNg gchar *profile; gchar *header_action; gchar *scroll_action; + gchar *secondary_action; gint position; guint name_watch_id; @@ -160,6 +161,7 @@ indicator_ng_finalize (GObject *object) g_free (self->accessible_desc); g_free (self->header_action); g_free (self->scroll_action); + g_free (self->secondary_action); G_OBJECT_CLASS (indicator_ng_parent_class)->finalize (object); } @@ -197,6 +199,22 @@ indicator_ng_entry_scrolled (IndicatorObject *io, } } +void +indicator_ng_secondary_activate (IndicatorObject *io, + IndicatorObjectEntry *entry, + guint timestamp, + gpointer user_data) +{ + IndicatorNg *self = INDICATOR_NG (io); + + g_message ("secondary: %s", self->secondary_action); + + if (self->actions && self->secondary_action) + { + g_action_group_activate_action (self->actions, self->secondary_action, NULL); + } +} + static void indicator_ng_set_accessible_desc (IndicatorNg *self, const gchar *accessible_desc) @@ -352,6 +370,7 @@ indicator_ng_menu_changed (GMenuModel *menu, { g_clear_pointer (&self->header_action, g_free); g_clear_pointer (&self->scroll_action, g_free); + g_clear_pointer (&self->secondary_action, g_free); if (indicator_ng_menu_item_is_of_type (self->menu, 0, "com.canonical.indicator.root")) { @@ -372,6 +391,13 @@ indicator_ng_menu_changed (GMenuModel *menu, g_free (action); } + if (g_menu_model_get_item_attribute (self->menu, 0, "x-canonical-secondary-action", "s", &action)) + { + if (g_str_has_prefix (action, "indicator.")) + self->secondary_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) { @@ -597,6 +623,7 @@ indicator_ng_class_init (IndicatorNgClass *class) io_class->get_entries = indicator_ng_get_entries; io_class->get_position = indicator_ng_get_position; io_class->entry_scrolled = indicator_ng_entry_scrolled; + io_class->secondary_activate = indicator_ng_secondary_activate; properties[PROP_SERVICE_FILE] = g_param_spec_string ("service-file", "Service file", -- cgit v1.2.3 From 9e857c3e55be6a7f2bb30f1edbdf94f3f97c8ba7 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Mon, 9 Sep 2013 15:32:49 +0200 Subject: Remove debug message --- libindicator/indicator-ng.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'libindicator') diff --git a/libindicator/indicator-ng.c b/libindicator/indicator-ng.c index 3971129..8d3304b 100644 --- a/libindicator/indicator-ng.c +++ b/libindicator/indicator-ng.c @@ -207,8 +207,6 @@ indicator_ng_secondary_activate (IndicatorObject *io, { IndicatorNg *self = INDICATOR_NG (io); - g_message ("secondary: %s", self->secondary_action); - if (self->actions && self->secondary_action) { g_action_group_activate_action (self->actions, self->secondary_action, NULL); -- cgit v1.2.3