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/indicator-ng.c') 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