From 5d5353c5b761b0adc272e4826690d90984b9413f Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Mon, 9 Sep 2013 13:34:02 +0200 Subject: Change volume when scrolling on the indicator This depends on a new root menu property: x-canonical-scroll-action. It points to an action that gets activated whenever the user scrolls the mouse over the indicator. The parameter of that action signifies the magnitude and direction of the scroll. --- src/service.vala | 14 ++++++++++++++ src/sound-menu.vala | 1 + 2 files changed, 15 insertions(+) (limited to 'src') diff --git a/src/service.vala b/src/service.vala index 4d64502..0651c0e 100644 --- a/src/service.vala +++ b/src/service.vala @@ -64,6 +64,7 @@ public class IndicatorSound.Service { const ActionEntry[] action_entries = { { "root", null, null, "@a{sv} {}", null }, + { "scroll", activate_scroll_action, "i", null, null }, { "desktop-settings", activate_desktop_settings, null, null, null }, { "phone-settings", activate_phone_settings, null, null, null }, }; @@ -76,6 +77,19 @@ public class IndicatorSound.Service { MediaPlayerList players; uint player_action_update_id; + void activate_scroll_action (SimpleAction action, Variant? param) { + const double volume_step_percentage = 0.06; + int delta = param.get_int32(); /* positive for up, negative for down */ + + double v = this.volume_control.get_volume () + volume_step_percentage * delta; + if (v > 1.0) + v = 1.0; + else if (v < 0.0) + v = 0.0; + + this.volume_control.set_volume (v); + } + void activate_desktop_settings (SimpleAction action, Variant? param) { var env = Environment.get_variable ("DESKTOP_SESSION"); string cmd; diff --git a/src/sound-menu.vala b/src/sound-menu.vala index 415a5be..7ac8930 100644 --- a/src/sound-menu.vala +++ b/src/sound-menu.vala @@ -40,6 +40,7 @@ class SoundMenu: Object var root_item = new MenuItem (null, "indicator.root"); root_item.set_attribute ("x-canonical-type", "s", "com.canonical.indicator.root"); + root_item.set_attribute ("x-canonical-scroll-action", "s", "indicator.scroll"); root_item.set_submenu (this.menu); this.root = new Menu (); -- cgit v1.2.3