aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Makefile.am7
-rw-r--r--lib/greeter.vala25
-rw-r--r--lib/main.vala89
3 files changed, 118 insertions, 3 deletions
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 <http://www.gnu.org/licenses/>.
+ *
+ * Authors: William Hua <william.hua@canonical.com>
+ */
+
+[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);
@@ -112,6 +123,82 @@ public class Indicator.Keyboard.Service : Object {
}
[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 ()) {
lightdm_current = source_settings.get_uint ("current");
@@ -309,6 +396,8 @@ public class Indicator.Keyboard.Service : Object {
}
source_settings.set_value ("sources", builder.end ());
+
+ update_greeter_user ();
}
[DBus (visible = false)]