aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2013-09-09 13:40:49 +0200
committerLars Uebernickel <lars.uebernickel@canonical.com>2013-09-09 13:40:49 +0200
commitf4fa56637405eb2112ad3516e3ac1438e79f0d41 (patch)
tree4c0fbd4d7a833e879e9fcf1fdd23c8d7547520cc
parent86f3d9e211daa64c99047734cd81f7d75ad7ed09 (diff)
downloadlibayatana-indicator-f4fa56637405eb2112ad3516e3ac1438e79f0d41.tar.gz
libayatana-indicator-f4fa56637405eb2112ad3516e3ac1438e79f0d41.tar.bz2
libayatana-indicator-f4fa56637405eb2112ad3516e3ac1438e79f0d41.zip
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.
-rw-r--r--libindicator/indicator-ng.c37
1 files changed, 32 insertions, 5 deletions
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);
}
@@ -179,6 +181,23 @@ indicator_ng_get_position (IndicatorObject *io)
}
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",