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/greeter.vala | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 lib/greeter.vala (limited to 'lib/greeter.vala') 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); +} -- 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(-) (limited to 'lib/greeter.vala') 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