From 8031d6831d622d6420fb2e1c4e65926f7ba46231 Mon Sep 17 00:00:00 2001 From: William Hua Date: Fri, 20 Sep 2013 20:56:11 -0400 Subject: Infer variable type. --- lib/main.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/main.vala') diff --git a/lib/main.vala b/lib/main.vala index 7aac365c..e0557e34 100644 --- a/lib/main.vala +++ b/lib/main.vala @@ -112,7 +112,7 @@ public class Indicator.Keyboard.Service : Object { [DBus (visible = false)] private void migrate_keyboard_layouts () { if (is_login_user ()) { - Act.UserManager manager = Act.UserManager.get_default (); + var manager = Act.UserManager.get_default (); if (manager.is_loaded) { users = manager.list_users (); -- cgit v1.2.3 From 474217efa011b2f360edad72c1a8872dbe7d257e Mon Sep 17 00:00:00 2001 From: William Hua Date: Fri, 20 Sep 2013 21:06:51 -0400 Subject: Only use XKeyboardLayouts if InputSources is empty. --- lib/main.vala | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'lib/main.vala') diff --git a/lib/main.vala b/lib/main.vala index e0557e34..485f37a4 100644 --- a/lib/main.vala +++ b/lib/main.vala @@ -209,12 +209,12 @@ public class Indicator.Keyboard.Service : Object { foreach (var user in users) { if (user.is_loaded) { - var sources = user.input_sources; - var layouts = user.xkeyboard_layouts; + var done = false; VariantIter outer; VariantIter inner; + var sources = user.input_sources; sources.get ("aa{ss}", out outer); while (outer.next ("a{ss}", out inner)) { @@ -223,6 +223,8 @@ public class Indicator.Keyboard.Service : Object { while (inner.next ("{&s&s}", out key, out source)) { if (key == "xkb") { + done = true; + if (!added.contains (source)) { list.add (source); added.add (source); @@ -231,14 +233,19 @@ public class Indicator.Keyboard.Service : Object { } } - foreach (var layout in layouts) { - var source = layout; - source = source.replace (" ", "+"); - source = source.replace ("\t", "+"); + if (!done) { + var layouts = user.xkeyboard_layouts; + foreach (var layout in layouts) { + done = true; - if (!added.contains (source)) { - list.add (source); - added.add (source); + var source = layout; + source = source.replace (" ", "+"); + source = source.replace ("\t", "+"); + + if (!added.contains (source)) { + list.add (source); + added.add (source); + } } } } -- cgit v1.2.3 From f485f87438c2c80bf378b42d997e9adde4d99cae Mon Sep 17 00:00:00 2001 From: William Hua Date: Fri, 20 Sep 2013 21:22:57 -0400 Subject: Fallback to LightDM default. --- lib/main.vala | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/main.vala') diff --git a/lib/main.vala b/lib/main.vala index 485f37a4..7daba518 100644 --- a/lib/main.vala +++ b/lib/main.vala @@ -251,6 +251,16 @@ public class Indicator.Keyboard.Service : Object { } } + if (list.size == 0) { + var layout = LightDM.get_layout (); + + var source = layout.name; + source = source.replace (" ", "+"); + source = source.replace ("\t", "+"); + + list.add (source); + } + var builder = new VariantBuilder (new VariantType ("a(ss)")); foreach (var layout in list) { -- cgit v1.2.3 From b4546f5c93ecfd844621942388f526c82a8c10bd Mon Sep 17 00:00:00 2001 From: William Hua Date: Fri, 20 Sep 2013 23:23:17 -0400 Subject: Use old user layouts if they haven't migrated yet. --- lib/main.vala | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'lib/main.vala') diff --git a/lib/main.vala b/lib/main.vala index 7daba518..df962c98 100644 --- a/lib/main.vala +++ b/lib/main.vala @@ -147,6 +147,13 @@ public class Indicator.Keyboard.Service : Object { } }); } + + var user_list = LightDM.UserList.get_instance (); + + user_list.user_added.connect ((user) => { migrate_input_sources (); }); + user_list.user_changed.connect ((user) => { migrate_input_sources (); }); + user_list.user_removed.connect ((user) => { migrate_input_sources (); }); + user_list.get_user_by_name ("this line force loads the users"); } else { if (!indicator_settings.get_boolean ("migrated")) { var builder = new VariantBuilder (new VariantType ("a(ss)")); @@ -248,6 +255,27 @@ public class Indicator.Keyboard.Service : Object { } } } + + if (!done) { + var user_list = LightDM.UserList.get_instance (); + LightDM.User? light_user = user_list.get_user_by_name (user.user_name); + + if (light_user != null) { + var layouts = ((!) light_user).get_layouts (); + foreach (var layout in layouts) { + done = true; + + var source = layout; + source = source.replace (" ", "+"); + source = source.replace ("\t", "+"); + + if (!added.contains (source)) { + list.add (source); + added.add (source); + } + } + } + } } } -- cgit v1.2.3 From 04f6c6c8a443bd58d95be15b6860f3b0e98e18a7 Mon Sep 17 00:00:00 2001 From: William Hua Date: Sat, 21 Sep 2013 00:21:06 -0400 Subject: Don't waste space. --- lib/main.vala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/main.vala') diff --git a/lib/main.vala b/lib/main.vala index df962c98..026be597 100644 --- a/lib/main.vala +++ b/lib/main.vala @@ -153,7 +153,9 @@ public class Indicator.Keyboard.Service : Object { user_list.user_added.connect ((user) => { migrate_input_sources (); }); user_list.user_changed.connect ((user) => { migrate_input_sources (); }); user_list.user_removed.connect ((user) => { migrate_input_sources (); }); - user_list.get_user_by_name ("this line force loads the users"); + + /* Force the loading of the user list. */ + user_list.get_user_by_name (""); } else { if (!indicator_settings.get_boolean ("migrated")) { var builder = new VariantBuilder (new VariantType ("a(ss)")); -- cgit v1.2.3 From caa8187d0c9dd3e891b9a0ba4967fdeb901f76e9 Mon Sep 17 00:00:00 2001 From: William Hua Date: Sat, 21 Sep 2013 11:01:35 -0400 Subject: Always add the default layout. --- lib/main.vala | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'lib/main.vala') diff --git a/lib/main.vala b/lib/main.vala index 026be597..11802d8a 100644 --- a/lib/main.vala +++ b/lib/main.vala @@ -281,20 +281,21 @@ public class Indicator.Keyboard.Service : Object { } } - if (list.size == 0) { - var layout = LightDM.get_layout (); + var layout = LightDM.get_layout (); - var source = layout.name; - source = source.replace (" ", "+"); - source = source.replace ("\t", "+"); + var source = layout.name; + source = source.replace (" ", "+"); + source = source.replace ("\t", "+"); + if (!added.contains (source)) { list.add (source); + added.add (source); } var builder = new VariantBuilder (new VariantType ("a(ss)")); - foreach (var layout in list) { - builder.add ("(ss)", "xkb", layout); + foreach (var name in list) { + builder.add ("(ss)", "xkb", name); } source_settings.set_value ("sources", builder.end ()); -- cgit v1.2.3 From 4c4d3fe6179b3457c63d619ee3012cfba0d4a50d Mon Sep 17 00:00:00 2001 From: William Hua Date: Sat, 21 Sep 2013 11:55:33 -0400 Subject: Prevent index out of bounds. --- lib/main.vala | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/main.vala') diff --git a/lib/main.vala b/lib/main.vala index 11802d8a..a0315590 100644 --- a/lib/main.vala +++ b/lib/main.vala @@ -41,6 +41,8 @@ public class Indicator.Keyboard.Service : Object { private MenuModel? menu_model; private Menu? sources_menu; + private uint lightdm_current; + [DBus (visible = false)] public Service (ref unowned string[] args) { force = "--force" in args; @@ -112,6 +114,8 @@ public class Indicator.Keyboard.Service : Object { [DBus (visible = false)] private void migrate_keyboard_layouts () { if (is_login_user ()) { + lightdm_current = source_settings.get_uint ("current"); + var manager = Act.UserManager.get_default (); if (manager.is_loaded) { @@ -298,6 +302,12 @@ public class Indicator.Keyboard.Service : Object { builder.add ("(ss)", "xkb", name); } + if (lightdm_current < list.size) { + source_settings.set_uint ("current", lightdm_current); + } else { + source_settings.set_uint ("current", list.size - 1); + } + source_settings.set_value ("sources", builder.end ()); } -- cgit v1.2.3