From 292ca060720c47dabfe938ea64abcf0ea243887b Mon Sep 17 00:00:00 2001 From: William Hua Date: Mon, 30 Sep 2013 09:45:06 -0400 Subject: Set initial layout whenever user is switched in unity-greeter. --- lib/Makefile.am | 7 +++-- lib/greeter.vala | 25 ++++++++++++++++ lib/main.vala | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+), 3 deletions(-) create mode 100644 lib/greeter.vala diff --git a/lib/Makefile.am b/lib/Makefile.am index 0e6c70d1..fd8a945e 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -6,9 +6,10 @@ AM_VALAFLAGS = --enable-experimental-non-null \ --metadatadir $(top_srcdir)/deps \ --vapidir $(top_srcdir)/deps -indicator_keyboard_service_SOURCES = main.vala \ - source.vala \ - common.vala +indicator_keyboard_service_SOURCES = main.vala \ + source.vala \ + common.vala \ + greeter.vala indicator_keyboard_service_VALAFLAGS = $(AM_VALAFLAGS) \ --pkg gee-1.0 \ --pkg posix \ diff --git a/lib/greeter.vala b/lib/greeter.vala new file mode 100644 index 00000000..43c1531d --- /dev/null +++ b/lib/greeter.vala @@ -0,0 +1,25 @@ +/* + * Copyright 2013 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.UnityGreeter.List")] +public interface Greeter : Object { + + public abstract void set_active_entry (string entry_name) throws IOError; + + public signal void entry_selected (string entry_name); +} diff --git a/lib/main.vala b/lib/main.vala index a0315590..1319c534 100644 --- a/lib/main.vala +++ b/lib/main.vala @@ -41,7 +41,9 @@ public class Indicator.Keyboard.Service : Object { private MenuModel? menu_model; private Menu? sources_menu; + private Greeter greeter; private uint lightdm_current; + private string? greeter_user; [DBus (visible = false)] public Service (ref unowned string[] args) { @@ -55,6 +57,15 @@ public class Indicator.Keyboard.Service : Object { Gdk.init (ref args); } + if (is_login_user ()) { + try { + greeter = Bus.get_proxy_sync (BusType.SESSION, "com.canonical.UnityGreeter.List", "/list"); + greeter.entry_selected.connect (handle_entry_selected); + } catch (IOError error) { + warning ("error: %s", error.message); + } + } + indicator_settings = new Settings ("com.canonical.indicator.keyboard"); indicator_settings.changed["visible"].connect (handle_changed_visible); @@ -111,6 +122,82 @@ public class Indicator.Keyboard.Service : Object { handle_name_lost); } + [DBus (visible = false)] + private void update_greeter_user () { + if (greeter_user != null) { + var manager = Act.UserManager.get_default (); + + if (manager.is_loaded) { + Act.User? user = manager.get_user ((!) greeter_user); + + if (user != null && ((!) user).is_loaded) { + string? source = null; + + VariantIter outer; + VariantIter inner; + + var sources = ((!) user).input_sources; + sources.get ("aa{ss}", out outer); + + if (outer.next ("a{ss}", out inner)) { + unowned string key; + unowned string value; + + while (inner.next ("{&s&s}", out key, out value)) { + if (key == "xkb") { + source = value; + } + } + } + + if (source == null) { + var layouts = ((!) user).xkeyboard_layouts; + + if (layouts.length == 0) { + var user_list = LightDM.UserList.get_instance (); + LightDM.User? light_user = user_list.get_user_by_name ((!) greeter_user); + + if (light_user != null) { + layouts = ((!) light_user).get_layouts (); + } + } + + if (layouts.length > 0) { + source = layouts[0]; + source = ((!) source).replace (" ", "+"); + source = ((!) source).replace ("\t", "+"); + } + } + + if (source != null) { + var array = source_settings.get_value ("sources"); + + for (int i = 0; i < array.n_children (); i++) { + unowned string type; + unowned string name; + + array.get_child (i, "(&s&s)", out type, out name); + + if (type == "xkb" && name == (!) source) { + source_settings.set_uint ("current", i); + break; + } + } + } + } + } + } + } + + [DBus (visible = false)] + private void handle_entry_selected (string entry_name) { + if (greeter_user == null || entry_name != (!) greeter_user) { + greeter_user = entry_name; + + update_greeter_user (); + } + } + [DBus (visible = false)] private void migrate_keyboard_layouts () { if (is_login_user ()) { @@ -309,6 +396,8 @@ public class Indicator.Keyboard.Service : Object { } source_settings.set_value ("sources", builder.end ()); + + update_greeter_user (); } [DBus (visible = false)] -- cgit v1.2.3 From 3e10c675a8a43678ab6b9bd7dc1197a6da246bc0 Mon Sep 17 00:00:00 2001 From: William Hua Date: Tue, 1 Oct 2013 16:17:16 -0400 Subject: Connect properly and handle edge cases. --- lib/greeter.vala | 1 + lib/main.vala | 45 ++++++++++++++++++++++++++++++++++++--------- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/lib/greeter.vala b/lib/greeter.vala index 43c1531d..c378bbd5 100644 --- a/lib/greeter.vala +++ b/lib/greeter.vala @@ -19,6 +19,7 @@ [DBus (name="com.canonical.UnityGreeter.List")] public interface Greeter : Object { + public abstract string get_active_entry () throws IOError; public abstract void set_active_entry (string entry_name) throws IOError; public signal void entry_selected (string entry_name); diff --git a/lib/main.vala b/lib/main.vala index 1319c534..8c25bf55 100644 --- a/lib/main.vala +++ b/lib/main.vala @@ -41,7 +41,7 @@ public class Indicator.Keyboard.Service : Object { private MenuModel? menu_model; private Menu? sources_menu; - private Greeter greeter; + private Greeter? greeter; private uint lightdm_current; private string? greeter_user; @@ -58,12 +58,11 @@ public class Indicator.Keyboard.Service : Object { } if (is_login_user ()) { - try { - greeter = Bus.get_proxy_sync (BusType.SESSION, "com.canonical.UnityGreeter.List", "/list"); - greeter.entry_selected.connect (handle_entry_selected); - } catch (IOError error) { - warning ("error: %s", error.message); - } + Bus.watch_name (BusType.SESSION, + "com.canonical.UnityGreeter", + BusNameWatcherFlags.NONE, + handle_name_appeared, + handle_name_vanished); } indicator_settings = new Settings ("com.canonical.indicator.keyboard"); @@ -124,6 +123,14 @@ public class Indicator.Keyboard.Service : Object { [DBus (visible = false)] private void update_greeter_user () { + if (greeter_user == null && greeter != null) { + try { + greeter_user = ((!) greeter).get_active_entry (); + } catch (IOError error) { + warning ("error: %s", error.message); + } + } + if (greeter_user != null) { var manager = Act.UserManager.get_default (); @@ -139,21 +146,26 @@ public class Indicator.Keyboard.Service : Object { var sources = ((!) user).input_sources; sources.get ("aa{ss}", out outer); - if (outer.next ("a{ss}", out inner)) { + while (outer.next ("a{ss}", out inner)) { unowned string key; unowned string value; while (inner.next ("{&s&s}", out key, out value)) { if (key == "xkb") { source = value; + break; } } + + if (source != null) { + break; + } } if (source == null) { var layouts = ((!) user).xkeyboard_layouts; - if (layouts.length == 0) { + if (layouts.length <= 0) { var user_list = LightDM.UserList.get_instance (); LightDM.User? light_user = user_list.get_user_by_name ((!) greeter_user); @@ -705,6 +717,21 @@ public class Indicator.Keyboard.Service : Object { } } + [DBus (visible = false)] + private void handle_name_appeared (DBusConnection connection, string name, string name_owner) { + try { + greeter = Bus.get_proxy_sync (BusType.SESSION, "com.canonical.UnityGreeter", "/list"); + ((!) greeter).entry_selected.connect (handle_entry_selected); + } catch (IOError error) { + warning ("error: %s", error.message); + } + } + + [DBus (visible = false)] + private void handle_name_vanished (DBusConnection connection, string name) { + greeter = null; + } + [DBus (visible = false)] private void handle_bus_acquired (DBusConnection connection, string name) { try { -- cgit v1.2.3 From 673d3cc001462e480ce000c713b3994cd8c58354 Mon Sep 17 00:00:00 2001 From: William Hua Date: Tue, 1 Oct 2013 23:03:00 -0400 Subject: ocd --- lib/main.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.vala b/lib/main.vala index 8c25bf55..5357862c 100644 --- a/lib/main.vala +++ b/lib/main.vala @@ -42,8 +42,8 @@ public class Indicator.Keyboard.Service : Object { private Menu? sources_menu; private Greeter? greeter; - private uint lightdm_current; private string? greeter_user; + private uint lightdm_current; [DBus (visible = false)] public Service (ref unowned string[] args) { -- cgit v1.2.3 From d5dab6b801cd8d3ab4519cbf45ae37c27feb3943 Mon Sep 17 00:00:00 2001 From: William Hua Date: Wed, 2 Oct 2013 11:53:34 -0400 Subject: Get greeter unique bus name from environment. --- lib/main.vala | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/main.vala b/lib/main.vala index 5357862c..c40cc112 100644 --- a/lib/main.vala +++ b/lib/main.vala @@ -58,11 +58,15 @@ public class Indicator.Keyboard.Service : Object { } if (is_login_user ()) { - Bus.watch_name (BusType.SESSION, - "com.canonical.UnityGreeter", - BusNameWatcherFlags.NONE, - handle_name_appeared, - handle_name_vanished); + var name = Environment.get_variable ("UNITY_GREETER_DBUS_NAME"); + + if (name != null) { + Bus.watch_name (BusType.SESSION, + (!) name, + BusNameWatcherFlags.NONE, + handle_name_appeared, + handle_name_vanished); + } } indicator_settings = new Settings ("com.canonical.indicator.keyboard"); @@ -720,7 +724,7 @@ public class Indicator.Keyboard.Service : Object { [DBus (visible = false)] private void handle_name_appeared (DBusConnection connection, string name, string name_owner) { try { - greeter = Bus.get_proxy_sync (BusType.SESSION, "com.canonical.UnityGreeter", "/list"); + greeter = Bus.get_proxy_sync (BusType.SESSION, name, "/list"); ((!) greeter).entry_selected.connect (handle_entry_selected); } catch (IOError error) { warning ("error: %s", error.message); -- cgit v1.2.3 From 62e536eb83d30df39da4afe5e17e94a7625762ea Mon Sep 17 00:00:00 2001 From: William Hua Date: Wed, 2 Oct 2013 14:53:12 -0400 Subject: Switch to default layout for non-users in unity-greeter. --- lib/main.vala | 60 ++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/lib/main.vala b/lib/main.vala index c40cc112..190276f8 100644 --- a/lib/main.vala +++ b/lib/main.vala @@ -135,6 +135,8 @@ public class Indicator.Keyboard.Service : Object { } } + string? source = null; + if (greeter_user != null) { var manager = Act.UserManager.get_default (); @@ -142,8 +144,6 @@ public class Indicator.Keyboard.Service : Object { Act.User? user = manager.get_user ((!) greeter_user); if (user != null && ((!) user).is_loaded) { - string? source = null; - VariantIter outer; VariantIter inner; @@ -184,22 +184,35 @@ public class Indicator.Keyboard.Service : Object { source = ((!) source).replace ("\t", "+"); } } + } + } + } - if (source != null) { - var array = source_settings.get_value ("sources"); + if (source == null) { + LightDM.Layout? layout = LightDM.get_layout (); - for (int i = 0; i < array.n_children (); i++) { - unowned string type; - unowned string name; + if (layout != null) { + source = ((!) layout).name; - array.get_child (i, "(&s&s)", out type, out name); + if (source != null) { + source = ((!) source).replace (" ", "+"); + source = ((!) source).replace ("\t", "+"); + } + } + } - if (type == "xkb" && name == (!) source) { - source_settings.set_uint ("current", i); - break; - } - } - } + if (source != null) { + var array = source_settings.get_value ("sources"); + + for (int i = 0; i < array.n_children (); i++) { + unowned string type; + unowned string name; + + array.get_child (i, "(&s&s)", out type, out name); + + if (type == "xkb" && name == (!) source) { + source_settings.set_uint ("current", i); + break; } } } @@ -388,15 +401,20 @@ public class Indicator.Keyboard.Service : Object { } } - var layout = LightDM.get_layout (); + LightDM.Layout? layout = LightDM.get_layout (); + + if (layout != null) { + string? source = ((!) layout).name; - var source = layout.name; - source = source.replace (" ", "+"); - source = source.replace ("\t", "+"); + if (source != null) { + source = ((!) source).replace (" ", "+"); + source = ((!) source).replace ("\t", "+"); - if (!added.contains (source)) { - list.add (source); - added.add (source); + if (!added.contains ((!) source)) { + list.add ((!) source); + added.add ((!) source); + } + } } var builder = new VariantBuilder (new VariantType ("a(ss)")); -- cgit v1.2.3