diff options
author | William Hua <william.hua@canonical.com> | 2014-04-10 11:28:03 +1200 |
---|---|---|
committer | William Hua <william.hua@canonical.com> | 2014-04-10 11:28:03 +1200 |
commit | d4868ddeca70ce2a3a4936e5bff41e380ad61b5d (patch) | |
tree | 10ca420d9a74e08946e0e73b81740dc805dd3062 | |
parent | f442bede4bd7ed4f455f2714b93b2b71f20540da (diff) | |
download | ayatana-indicator-keyboard-d4868ddeca70ce2a3a4936e5bff41e380ad61b5d.tar.gz ayatana-indicator-keyboard-d4868ddeca70ce2a3a4936e5bff41e380ad61b5d.tar.bz2 ayatana-indicator-keyboard-d4868ddeca70ce2a3a4936e5bff41e380ad61b5d.zip |
Use different mouse actions when locked.
-rw-r--r-- | lib/indicator-menu.vala | 13 | ||||
-rw-r--r-- | lib/main.vala | 50 |
2 files changed, 60 insertions, 3 deletions
diff --git a/lib/indicator-menu.vala b/lib/indicator-menu.vala index e321a2d2..8e5661e2 100644 --- a/lib/indicator-menu.vala +++ b/lib/indicator-menu.vala @@ -52,10 +52,17 @@ public class Indicator.Keyboard.IndicatorMenu : MenuModel { } var indicator = new MenuItem.submenu (null, submenu); - indicator.set_attribute ("x-canonical-type", "s", "com.canonical.indicator.root"); - indicator.set_attribute ("x-canonical-secondary-action", "s", "indicator.next"); - indicator.set_attribute ("x-canonical-scroll-action", "s", "indicator.scroll"); indicator.set_detailed_action ("indicator.indicator"); + indicator.set_attribute ("x-canonical-type", "s", "com.canonical.indicator.root"); + + /* We need special mouse actions on the lock screen. */ + if ((options & Options.DCONF) != Options.NONE) { + indicator.set_attribute ("x-canonical-secondary-action", "s", "indicator.next"); + indicator.set_attribute ("x-canonical-scroll-action", "s", "indicator.scroll"); + } else { + indicator.set_attribute ("x-canonical-secondary-action", "s", "indicator.locked_next"); + indicator.set_attribute ("x-canonical-scroll-action", "s", "indicator.locked_scroll"); + } indicator_menu = new Menu (); indicator_menu.append_item (indicator); diff --git a/lib/main.vala b/lib/main.vala index 8279b561..8d39d757 100644 --- a/lib/main.vala +++ b/lib/main.vala @@ -780,6 +780,48 @@ public class Indicator.Keyboard.Service : Object { } [DBus (visible = false)] + private void handle_middle_click_when_locked (Variant? parameter) { + handle_scroll_wheel_when_locked (new Variant.int32 (-1)); + } + + [DBus (visible = false)] + private void handle_scroll_wheel_when_locked (Variant? parameter) { + if (parameter != null) { + var sources = get_sources (); + var non_ibus_length = 0; + + /* Figure out how many non-IBus sources we have. */ + foreach (var source in sources) { + if (!source.is_ibus) { + non_ibus_length++; + } + } + + if (non_ibus_length > 1) { + var active_action = get_active_action (); + var active = active_action.state.get_uint32 (); + var offset = -((!) parameter).get_int32 () % non_ibus_length; + + /* Make offset positive modulo non_ibus_length. */ + if (offset < 0) { + offset += non_ibus_length; + } + + /* We need to cycle through non-IBus sources only. */ + while (offset > 0) { + do { + active = (active + 1) % sources.length; + } while (sources[active].is_ibus); + + offset--; + } + + active_action.change_state (new Variant.uint32 (active)); + } + } + } + + [DBus (visible = false)] protected virtual SimpleActionGroup create_action_group (Action root_action) { var group = new SimpleActionGroup (); @@ -804,6 +846,14 @@ public class Indicator.Keyboard.Service : Object { action.activate.connect (handle_scroll_wheel); group.add_action (action); + action = new SimpleAction ("locked_next", null); + action.activate.connect (handle_middle_click_when_locked); + group.add_action (action); + + action = new SimpleAction ("locked_scroll", VariantType.INT32); + action.activate.connect (handle_scroll_wheel_when_locked); + group.add_action (action); + action = new SimpleAction ("map", null); action.activate.connect (handle_activate_map); group.add_action (action); |