From 414d5d9f8a41805ecec5808ace466c37d03fa9f3 Mon Sep 17 00:00:00 2001 From: William Hua Date: Wed, 2 Apr 2014 10:24:25 +1300 Subject: Switch to non-IBus input source when screen is locked. --- lib/Makefile.am | 1 + lib/main.vala | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ lib/unity-session.vala | 24 ++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 lib/unity-session.vala diff --git a/lib/Makefile.am b/lib/Makefile.am index b99073e1..fa8f43a0 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -12,6 +12,7 @@ indicator_keyboard_service_SOURCES = main.vala \ ibus-menu.vala \ ibus-panel.vala \ window-stack.vala \ + unity-session.vala \ unity-greeter.vala indicator_keyboard_service_VALAFLAGS = $(AM_VALAFLAGS) \ --pkg gee-1.0 \ diff --git a/lib/main.vala b/lib/main.vala index 55c46b02..7cfb5fac 100644 --- a/lib/main.vala +++ b/lib/main.vala @@ -49,6 +49,9 @@ public class Indicator.Keyboard.Service : Object { private Menu? sources_menu; private IBusMenu? ibus_menu; + private UnitySession? unity_session; + private uint session_current; + private UnityGreeter? unity_greeter; private string? greeter_user; private uint lightdm_current; @@ -95,6 +98,12 @@ public class Indicator.Keyboard.Service : Object { handle_unity_greeter_name_vanished); } } else { + Bus.watch_name (BusType.SESSION, + "com.canonical.Unity", + BusNameWatcherFlags.NONE, + handle_unity_name_appeared, + handle_unity_name_vanished); + Bus.watch_name (BusType.SESSION, "com.canonical.Unity.WindowStack", BusNameWatcherFlags.NONE, @@ -923,6 +932,51 @@ public class Indicator.Keyboard.Service : Object { unity_greeter = null; } + [DBus (visible = false)] + private void handle_unity_name_appeared (DBusConnection connection, string name, string name_owner) { + try { + unity_session = Bus.get_proxy_sync (BusType.SESSION, name, "/com/canonical/Unity/Session"); + ((!) unity_session).locked.connect (() => { + session_current = source_settings.get_uint ("current"); + + var sources = get_sources (); + + if (session_current < 0) { + session_current = 0; + } else if (session_current >= sources.length) { + session_current = sources.length - 1; + } + + if (0 <= session_current && session_current < sources.length) { + var source = sources[session_current]; + + if (source.is_ibus) { + for (var i = 0; i < sources.length; i++) { + if (!sources[i].is_ibus) { + source_settings.set_uint ("current", i); + break; + } + } + } + } + }); + ((!) unity_session).unlocked.connect (() => { + var locked_current = source_settings.get_uint ("current"); + + if (locked_current != session_current) { + source_settings.set_uint ("current", session_current); + } + }); + } catch (IOError error) { + warning ("error: %s", error.message); + } + } + + [DBus (visible = false)] + private void handle_unity_name_vanished (DBusConnection connection, string name) { + unity_session = null; + } + [DBus (visible = false)] private void handle_window_stack_name_appeared (DBusConnection connection, string name, string name_owner) { try { diff --git a/lib/unity-session.vala b/lib/unity-session.vala new file mode 100644 index 00000000..04bf3349 --- /dev/null +++ b/lib/unity-session.vala @@ -0,0 +1,24 @@ +/* + * Copyright 2014 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Authors: William Hua + */ + +[DBus (name="com.canonical.Unity.Session")] +public interface UnitySession : Object { + + public signal void locked (); + public signal void unlocked (); +} -- cgit v1.2.3 From 202d1631f69e473c162c62d5e29b2ac1212390f1 Mon Sep 17 00:00:00 2001 From: William Hua Date: Fri, 4 Apr 2014 16:00:04 +1300 Subject: Add u-s-d keyboard plugin private interface. --- lib/Makefile.am | 17 +++++++++-------- lib/keyboard-plugin.vala | 23 +++++++++++++++++++++++ 2 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 lib/keyboard-plugin.vala diff --git a/lib/Makefile.am b/lib/Makefile.am index 30ad790d..a19016d9 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -6,14 +6,15 @@ AM_VALAFLAGS = --enable-experimental-non-null \ --metadatadir $(top_srcdir)/deps \ --vapidir $(top_srcdir)/deps -indicator_keyboard_service_SOURCES = main.vala \ - source.vala \ - common.vala \ - ibus-menu.vala \ - ibus-panel.vala \ - indicator-menu.vala \ - window-stack.vala \ - unity-session.vala \ +indicator_keyboard_service_SOURCES = main.vala \ + source.vala \ + common.vala \ + ibus-menu.vala \ + ibus-panel.vala \ + indicator-menu.vala \ + keyboard-plugin.vala \ + window-stack.vala \ + unity-session.vala \ unity-greeter.vala indicator_keyboard_service_VALAFLAGS = $(AM_VALAFLAGS) \ --pkg gee-1.0 \ diff --git a/lib/keyboard-plugin.vala b/lib/keyboard-plugin.vala new file mode 100644 index 00000000..5ee8ea24 --- /dev/null +++ b/lib/keyboard-plugin.vala @@ -0,0 +1,23 @@ +/* + * Copyright 2014 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Authors: William Hua + */ + +[DBus (name="com.canonical.SettingsDaemon.Keyboard.Private")] +public interface KeyboardPlugin : Object { + + public abstract void activate_input_source (uint index) throws IOError; +} -- cgit v1.2.3 From dc64a5387763dda0aae30695741dd62ee9fe8614 Mon Sep 17 00:00:00 2001 From: William Hua Date: Fri, 4 Apr 2014 16:27:41 +1300 Subject: Separate lock screen menu. --- data/Makefile.am | 2 +- lib/indicator-menu.vala | 17 +++++++++++++---- lib/main.vala | 29 +++++++++++++++++++++++++++-- 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/data/Makefile.am b/data/Makefile.am index 104d2073..03c377c7 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -57,7 +57,7 @@ com.canonical.indicator.keyboard: echo 'ObjectPath=/com/canonical/indicator/keyboard/desktop_greeter'; \ echo ''; \ echo '[desktop_lockscreen]'; \ - echo 'ObjectPath=/com/canonical/indicator/keyboard/desktop_greeter'; \ + echo 'ObjectPath=/com/canonical/indicator/keyboard/desktop_lockscreen'; \ echo ''; \ echo '[ubiquity]'; \ echo 'ObjectPath=/com/canonical/indicator/keyboard/desktop') > $@.tmp && \ diff --git a/lib/indicator-menu.vala b/lib/indicator-menu.vala index 1d92a6f6..e321a2d2 100644 --- a/lib/indicator-menu.vala +++ b/lib/indicator-menu.vala @@ -20,8 +20,9 @@ public class Indicator.Keyboard.IndicatorMenu : MenuModel { public enum Options { NONE = 0x0, - IBUS = 0x1, - SETTINGS = 0x2 + DCONF = 0x1, + IBUS = 0x2, + SETTINGS = 0x4 } private Options options; @@ -30,7 +31,7 @@ public class Indicator.Keyboard.IndicatorMenu : MenuModel { private Menu sources_section; private IBusMenu properties_section; - public IndicatorMenu (ActionMap? action_map = null, Options options = Options.IBUS | Options.SETTINGS) { + public IndicatorMenu (ActionMap? action_map = null, Options options = Options.NONE) { var submenu = new Menu (); sources_section = new Menu (); @@ -69,7 +70,15 @@ public class Indicator.Keyboard.IndicatorMenu : MenuModel { for (var i = 0; i < sources.length; i++) { if (!sources[i].is_ibus || (options & Options.IBUS) != Options.NONE) { - var item = new MenuItem (sources[i].name, "indicator.current"); + string action; + + if ((options & Options.DCONF) != Options.NONE) { + action = "indicator.current"; + } else { + action = "indicator.active"; + } + + var item = new MenuItem (sources[i].name, action); item.set_attribute (Menu.ATTRIBUTE_TARGET, "u", i); diff --git a/lib/main.vala b/lib/main.vala index d8c1f060..cc78c384 100644 --- a/lib/main.vala +++ b/lib/main.vala @@ -47,6 +47,7 @@ public class Indicator.Keyboard.Service : Object { private SimpleAction? indicator_action; private IndicatorMenu? desktop_menu; private IndicatorMenu? desktop_greeter_menu; + private IndicatorMenu? desktop_lockscreen_menu; private UnitySession? unity_session; private uint session_current; @@ -81,6 +82,10 @@ public class Indicator.Keyboard.Service : Object { get_desktop_greeter_menu ().set_sources (get_sources ()); } + if (desktop_lockscreen_menu != null) { + get_desktop_lockscreen_menu ().set_sources (get_sources ()); + } + if (indicator_action != null) { update_indicator_action (); } @@ -758,7 +763,11 @@ public class Indicator.Keyboard.Service : Object { [DBus (visible = false)] public IndicatorMenu get_desktop_menu () { if (desktop_menu == null) { - desktop_menu = new IndicatorMenu (get_action_group ()); + var options = IndicatorMenu.Options.DCONF + | IndicatorMenu.Options.IBUS + | IndicatorMenu.Options.SETTINGS; + + desktop_menu = new IndicatorMenu (get_action_group (), options); ((!) desktop_menu).set_sources (get_sources ()); ((!) desktop_menu).activate.connect ((property, state) => { var panel = get_ibus_panel (); @@ -779,13 +788,27 @@ public class Indicator.Keyboard.Service : Object { [DBus (visible = false)] public IndicatorMenu get_desktop_greeter_menu () { if (desktop_greeter_menu == null) { - desktop_greeter_menu = new IndicatorMenu (get_action_group (), IndicatorMenu.Options.NONE); + var options = IndicatorMenu.Options.DCONF; + + desktop_greeter_menu = new IndicatorMenu (get_action_group (), options); ((!) desktop_greeter_menu).set_sources (get_sources ()); } return (!) desktop_greeter_menu; } + [DBus (visible = false)] + public IndicatorMenu get_desktop_lockscreen_menu () { + if (desktop_lockscreen_menu == null) { + var options = IndicatorMenu.Options.NONE; + + desktop_lockscreen_menu = new IndicatorMenu (get_action_group (), options); + ((!) desktop_lockscreen_menu).set_sources (get_sources ()); + } + + return (!) desktop_lockscreen_menu; + } + [DBus (visible = false)] private void handle_changed_visible (string key) { update_indicator_action (); @@ -803,6 +826,7 @@ public class Indicator.Keyboard.Service : Object { get_desktop_menu ().set_sources (get_sources ()); get_desktop_greeter_menu ().set_sources (get_sources ()); + get_desktop_lockscreen_menu ().set_sources (get_sources ()); update_indicator_action (); update_login_layout (); } @@ -939,6 +963,7 @@ public class Indicator.Keyboard.Service : Object { connection.export_action_group ("/com/canonical/indicator/keyboard", get_action_group ()); connection.export_menu_model ("/com/canonical/indicator/keyboard/desktop", get_desktop_menu ()); connection.export_menu_model ("/com/canonical/indicator/keyboard/desktop_greeter", get_desktop_greeter_menu ()); + connection.export_menu_model ("/com/canonical/indicator/keyboard/desktop_lockscreen", get_desktop_lockscreen_menu ()); } catch (Error error) { warning ("error: %s", error.message); } -- cgit v1.2.3 From 32a98fdad806398885ecfeac226257e03b625966 Mon Sep 17 00:00:00 2001 From: William Hua Date: Fri, 4 Apr 2014 17:38:13 +1300 Subject: Add 'active' action that allows setting the current input source without persisting it on disk. --- lib/main.vala | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/lib/main.vala b/lib/main.vala index cc78c384..f8367c16 100644 --- a/lib/main.vala +++ b/lib/main.vala @@ -45,10 +45,13 @@ public class Indicator.Keyboard.Service : Object { private SimpleActionGroup? action_group; private SimpleAction? indicator_action; + private SimpleAction? active_action; private IndicatorMenu? desktop_menu; private IndicatorMenu? desktop_greeter_menu; private IndicatorMenu? desktop_lockscreen_menu; + private KeyboardPlugin? keyboard_plugin; + private UnitySession? unity_session; private uint session_current; @@ -106,6 +109,12 @@ public class Indicator.Keyboard.Service : Object { handle_unity_greeter_name_vanished); } } else { + Bus.watch_name (BusType.SESSION, + "org.gnome.SettingsDaemon.Keyboard", + BusNameWatcherFlags.NONE, + handle_keyboard_name_appeared, + handle_keyboard_name_vanished); + Bus.watch_name (BusType.SESSION, "com.canonical.Unity", BusNameWatcherFlags.NONE, @@ -702,6 +711,40 @@ public class Indicator.Keyboard.Service : Object { return (!) indicator_action; } + [DBus (visible = false)] + private void handle_changed_active (Variant? value) { + if (value != null) { + ((!) active_action).set_state ((!) value); + + if (keyboard_plugin != null) { + try { + ((!) keyboard_plugin).activate_input_source (((!) value).get_uint32 ()); + } catch (IOError error) { + warning ("error: %s", error.message); + } + } + } + } + + [DBus (visible = false)] + private void update_active_action () { + if (active_action != null) { + ((!) active_action).set_state (source_settings.get_value ("current")); + } + } + + [DBus (visible = false)] + private Action get_active_action () { + if (active_action == null) { + var current = source_settings.get_value ("current"); + active_action = new SimpleAction.stateful ("active", VariantType.UINT32, current); + ((!) active_action).activate.connect ((parameter) => { ((!) active_action).change_state (parameter); }); + ((!) active_action).change_state.connect (handle_changed_active); + } + + return (!) active_action; + } + [DBus (visible = false)] private void handle_middle_click (Variant? parameter) { handle_scroll_wheel (new Variant.int32 (-1)); @@ -725,7 +768,17 @@ public class Indicator.Keyboard.Service : Object { protected virtual SimpleActionGroup create_action_group (Action root_action) { var group = new SimpleActionGroup (); + /* + * The 'current' action reflects the current setting in + * GSettings and the 'active' action only exists to set the + * active input source without persisting it. + * + * The lock screen menu uses the 'active' action while the + * other menus instead persist the current input source. + */ + group.add_action (root_action); + group.add_action (get_active_action ()); group.add_action (source_settings.create_action ("current")); var action = new SimpleAction ("next", null); @@ -817,6 +870,7 @@ public class Indicator.Keyboard.Service : Object { [DBus (visible = false)] private void handle_changed_current (string key) { update_indicator_action (); + update_active_action (); update_login_layout (); } @@ -897,6 +951,20 @@ public class Indicator.Keyboard.Service : Object { unity_greeter = null; } + [DBus (visible = false)] + private void handle_keyboard_name_appeared (DBusConnection connection, string name, string name_owner) { + try { + keyboard_plugin = Bus.get_proxy_sync (BusType.SESSION, name, "/org/gnome/SettingsDaemon/Keyboard"); + } catch (IOError error) { + warning ("error: %s", error.message); + } + } + + [DBus (visible = false)] + private void handle_keyboard_name_vanished (DBusConnection connection, string name) { + keyboard_plugin = null; + } + [DBus (visible = false)] private void handle_unity_name_appeared (DBusConnection connection, string name, string name_owner) { try { -- cgit v1.2.3 From 3b4b8a3415c837dc2ad26385df5716b63350d104 Mon Sep 17 00:00:00 2001 From: William Hua Date: Fri, 4 Apr 2014 23:05:36 +1300 Subject: Don't change input source setting on lock/unlock. --- lib/main.vala | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/lib/main.vala b/lib/main.vala index f8367c16..cabc8c2a 100644 --- a/lib/main.vala +++ b/lib/main.vala @@ -51,10 +51,7 @@ public class Indicator.Keyboard.Service : Object { private IndicatorMenu? desktop_lockscreen_menu; private KeyboardPlugin? keyboard_plugin; - private UnitySession? unity_session; - private uint session_current; - private UnityGreeter? unity_greeter; private string? greeter_user; private uint lightdm_current; @@ -970,23 +967,15 @@ public class Indicator.Keyboard.Service : Object { try { unity_session = Bus.get_proxy_sync (BusType.SESSION, name, "/com/canonical/Unity/Session"); ((!) unity_session).locked.connect (() => { - session_current = source_settings.get_uint ("current"); - var sources = get_sources (); - if (session_current < 0) { - session_current = 0; - } else if (session_current >= sources.length) { - session_current = sources.length - 1; - } - - if (0 <= session_current && session_current < sources.length) { - var source = sources[session_current]; + if (sources.length > 0) { + var current = source_settings.get_uint ("current"); - if (source.is_ibus) { + if (current < sources.length && sources[current].is_ibus) { for (var i = 0; i < sources.length; i++) { if (!sources[i].is_ibus) { - source_settings.set_uint ("current", i); + get_active_action ().change_state (new Variant.uint32 (i)); break; } } @@ -994,10 +983,15 @@ public class Indicator.Keyboard.Service : Object { } }); ((!) unity_session).unlocked.connect (() => { - var locked_current = source_settings.get_uint ("current"); + if (keyboard_plugin != null) { + var current = source_settings.get_uint ("current"); - if (locked_current != session_current) { - source_settings.set_uint ("current", session_current); + try { + /* Always restore session input source on unlock. */ + ((!) keyboard_plugin).activate_input_source (current); + } catch (IOError error) { + warning ("error: %s", error.message); + } } }); } catch (IOError error) { -- cgit v1.2.3 From ef122381c53550ba4e0512e28f6b12386772f34b Mon Sep 17 00:00:00 2001 From: William Hua Date: Sat, 5 Apr 2014 00:01:23 +1300 Subject: Remember to update indicator action with active input source. --- lib/main.vala | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/main.vala b/lib/main.vala index cabc8c2a..dde166f6 100644 --- a/lib/main.vala +++ b/lib/main.vala @@ -672,20 +672,19 @@ public class Indicator.Keyboard.Service : Object { [DBus (visible = false)] private void update_indicator_action () { - var visible = indicator_settings.get_boolean ("visible"); - var current = source_settings.get_uint ("current"); - var sources = get_sources (); - Icon? icon = null; string? name = null; - if (current < sources.length) { - icon = sources[current].icon; - name = sources[current].name; + var sources = get_sources (); + var active = get_active_action ().get_state ().get_uint32 (); + + if (active < sources.length) { + icon = sources[active].icon; + name = sources[active].name; } var builder = new VariantBuilder (new VariantType ("a{sv}")); - builder.add ("{sv}", "visible", new Variant.boolean (visible)); + builder.add ("{sv}", "visible", indicator_settings.get_value ("visible")); if (name != null) { var description = _ ("%s input source").printf ((!) name); builder.add ("{sv}", "accessible-desc", new Variant.string (description)); @@ -712,6 +711,7 @@ public class Indicator.Keyboard.Service : Object { private void handle_changed_active (Variant? value) { if (value != null) { ((!) active_action).set_state ((!) value); + update_indicator_action (); if (keyboard_plugin != null) { try { @@ -727,6 +727,7 @@ public class Indicator.Keyboard.Service : Object { private void update_active_action () { if (active_action != null) { ((!) active_action).set_state (source_settings.get_value ("current")); + update_indicator_action (); } } -- cgit v1.2.3 From 969e5b55bebc4507d694b0075667c36850ea7025 Mon Sep 17 00:00:00 2001 From: William Hua Date: Sat, 5 Apr 2014 00:26:33 +1300 Subject: Remember to reset the indicator icon on unlock too. --- lib/main.vala | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/lib/main.vala b/lib/main.vala index dde166f6..bcf23209 100644 --- a/lib/main.vala +++ b/lib/main.vala @@ -984,16 +984,7 @@ public class Indicator.Keyboard.Service : Object { } }); ((!) unity_session).unlocked.connect (() => { - if (keyboard_plugin != null) { - var current = source_settings.get_uint ("current"); - - try { - /* Always restore session input source on unlock. */ - ((!) keyboard_plugin).activate_input_source (current); - } catch (IOError error) { - warning ("error: %s", error.message); - } - } + get_active_action ().change_state (source_settings.get_value ("current")); }); } catch (IOError error) { warning ("error: %s", error.message); -- cgit v1.2.3 From 3aae8264b94b808195c3647384fb20bd0e72fc17 Mon Sep 17 00:00:00 2001 From: William Hua Date: Sat, 5 Apr 2014 11:53:34 +1300 Subject: Update pot file. --- po/indicator-keyboard.pot | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/po/indicator-keyboard.pot b/po/indicator-keyboard.pot index 38d5e005..52ce3b32 100644 --- a/po/indicator-keyboard.pot +++ b/po/indicator-keyboard.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2014-03-27 23:39+1300\n" +"POT-Creation-Date: 2014-04-05 11:53+1300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,19 +17,19 @@ msgstr "" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" -#: ../lib/main.vala:670 +#: ../lib/main.vala:706 #, c-format msgid "%s input source" msgstr "" -#: ../lib/indicator-menu.vala:47 +#: ../lib/indicator-menu.vala:48 msgid "Character Map" msgstr "" -#: ../lib/indicator-menu.vala:48 +#: ../lib/indicator-menu.vala:49 msgid "Keyboard Layout Chart" msgstr "" -#: ../lib/indicator-menu.vala:49 +#: ../lib/indicator-menu.vala:50 msgid "Text Entry Settings..." msgstr "" -- cgit v1.2.3 From d4868ddeca70ce2a3a4936e5bff41e380ad61b5d Mon Sep 17 00:00:00 2001 From: William Hua Date: Thu, 10 Apr 2014 11:28:03 +1200 Subject: Use different mouse actions when locked. --- lib/indicator-menu.vala | 13 ++++++++++--- 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 @@ -779,6 +779,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); -- cgit v1.2.3