aboutsummaryrefslogtreecommitdiff
path: root/lib/main.vala
diff options
context:
space:
mode:
authorWilliam Hua <william.hua@canonical.com>2013-09-30 09:45:06 -0400
committerWilliam Hua <william.hua@canonical.com>2013-09-30 09:45:06 -0400
commit292ca060720c47dabfe938ea64abcf0ea243887b (patch)
tree3c7ae7c97be5fd14b14b0380d7e142364e6efe68 /lib/main.vala
parente081bed515c52f2a5f975e870c509087aea4b2a3 (diff)
downloadayatana-indicator-keyboard-292ca060720c47dabfe938ea64abcf0ea243887b.tar.gz
ayatana-indicator-keyboard-292ca060720c47dabfe938ea64abcf0ea243887b.tar.bz2
ayatana-indicator-keyboard-292ca060720c47dabfe938ea64abcf0ea243887b.zip
Set initial layout whenever user is switched in unity-greeter.
Diffstat (limited to 'lib/main.vala')
-rw-r--r--lib/main.vala89
1 files changed, 89 insertions, 0 deletions
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)]