aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorWilliam Hua <william.hua@canonical.com>2013-08-07 16:20:23 -0400
committerWilliam Hua <william.hua@canonical.com>2013-08-07 16:20:23 -0400
commit4451d840969698c2d2106c013a95a3c6eb4baf70 (patch)
tree876280e17772db786478cebd765e1b4d10d4d473 /lib
parent0e3bb46532e1858f2cfee808bd66efa225cb2d94 (diff)
downloadayatana-indicator-keyboard-4451d840969698c2d2106c013a95a3c6eb4baf70.tar.gz
ayatana-indicator-keyboard-4451d840969698c2d2106c013a95a3c6eb4baf70.tar.bz2
ayatana-indicator-keyboard-4451d840969698c2d2106c013a95a3c6eb4baf70.zip
Work under lightdm/unity-greeter.
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile.am58
-rw-r--r--lib/main.vala203
2 files changed, 195 insertions, 66 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
index cdf41ba2..0e6c70d1 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -9,32 +9,38 @@ AM_VALAFLAGS = --enable-experimental-non-null \
indicator_keyboard_service_SOURCES = main.vala \
source.vala \
common.vala
-indicator_keyboard_service_VALAFLAGS = $(AM_VALAFLAGS) \
- --pkg gee-1.0 \
- --pkg posix \
- --pkg pangocairo \
- --pkg gtk+-3.0 \
- --pkg GDesktopEnums-3.0 \
- --pkg gnome-desktop-3.0 \
- --pkg Xkl-1.0 \
- --pkg Gkbd-3.0 \
- --pkg ibus-1.0 \
+indicator_keyboard_service_VALAFLAGS = $(AM_VALAFLAGS) \
+ --pkg gee-1.0 \
+ --pkg posix \
+ --pkg pangocairo \
+ --pkg gtk+-3.0 \
+ --pkg GDesktopEnums-3.0 \
+ --pkg gnome-desktop-3.0 \
+ --pkg Xkl-1.0 \
+ --pkg Gkbd-3.0 \
+ --pkg ibus-1.0 \
+ --pkg accountsservice \
+ --pkg liblightdm-gobject-1 \
--pkg libbamf3
-indicator_keyboard_service_CFLAGS = $(AM_CFLAGS) \
- $(GEE_CFLAGS) \
- $(PANGOCAIRO_CFLAGS) \
- $(GTK_CFLAGS) \
- $(GNOME_DESKTOP_CFLAGS) \
- $(LIBXKLAVIER_CFLAGS) \
- $(LIBGNOMEKBD_CFLAGS) \
- $(IBUS_CFLAGS) \
+indicator_keyboard_service_CFLAGS = $(AM_CFLAGS) \
+ $(GEE_CFLAGS) \
+ $(PANGOCAIRO_CFLAGS) \
+ $(GTK_CFLAGS) \
+ $(GNOME_DESKTOP_CFLAGS) \
+ $(LIBXKLAVIER_CFLAGS) \
+ $(LIBGNOMEKBD_CFLAGS) \
+ $(IBUS_CFLAGS) \
+ $(ACCOUNTSSERVICE_CFLAGS) \
+ $(LIGHTDM_CFLAGS) \
$(BAMF_CFLAGS)
-indicator_keyboard_service_LDFLAGS = $(AM_LDFLAGS) \
- $(GEE_LIBS) \
- $(PANGOCAIRO_LIBS) \
- $(GTK_LIBS) \
- $(GNOME_DESKTOP_LIBS) \
- $(LIBXKLAVIER_LIBS) \
- $(LIBGNOMEKBD_LIBS) \
- $(IBUS_LIBS) \
+indicator_keyboard_service_LDFLAGS = $(AM_LDFLAGS) \
+ $(GEE_LIBS) \
+ $(PANGOCAIRO_LIBS) \
+ $(GTK_LIBS) \
+ $(GNOME_DESKTOP_LIBS) \
+ $(LIBXKLAVIER_LIBS) \
+ $(LIBGNOMEKBD_LIBS) \
+ $(IBUS_LIBS) \
+ $(ACCOUNTSSERVICE_LIBS) \
+ $(LIGHTDM_LIBS) \
$(BAMF_LIBS)
diff --git a/lib/main.vala b/lib/main.vala
index 91466f8c..ef94b2f2 100644
--- a/lib/main.vala
+++ b/lib/main.vala
@@ -29,6 +29,7 @@ public class Indicator.Keyboard.Service : Object {
private Settings indicator_settings;
private Settings source_settings;
private Settings per_window_settings;
+ private SList<Act.User> users;
private Bamf.Matcher? matcher;
private Gee.HashMap<string, uint>? window_sources;
@@ -67,6 +68,11 @@ public class Indicator.Keyboard.Service : Object {
}
[DBus (visible = false)]
+ private static bool is_login_user () {
+ return Environment.get_user_name () == "lightdm";
+ }
+
+ [DBus (visible = false)]
private static IBus.Bus get_ibus () {
if (ibus == null) {
IBus.init ();
@@ -91,64 +97,177 @@ public class Indicator.Keyboard.Service : Object {
[DBus (visible = false)]
private void migrate_keyboard_layouts () {
- if (!indicator_settings.get_boolean ("migrated")) {
- var builder = new VariantBuilder (new VariantType ("a(ss)"));
- var length = 0;
+ if (is_login_user ()) {
+ Act.UserManager manager = Act.UserManager.get_default ();
+
+ if (manager.is_loaded) {
+ users = manager.list_users ();
+
+ foreach (var user in users) {
+ if (user.is_loaded) {
+ migrate_input_sources ();
+ } else {
+ user.notify["is-loaded"].connect ((pspec) => {
+ if (user.is_loaded) {
+ migrate_input_sources ();
+ }
+ });
+ }
+ }
+ } else {
+ manager.notify["is-loaded"].connect ((pspec) => {
+ if (manager.is_loaded) {
+ users = manager.list_users ();
+
+ foreach (var user in users) {
+ if (user.is_loaded) {
+ migrate_input_sources ();
+ } else {
+ user.notify["is-loaded"].connect ((pspec) => {
+ if (user.is_loaded) {
+ migrate_input_sources ();
+ }
+ });
+ }
+ }
+ }
+ });
+ }
+ } else {
+ if (!indicator_settings.get_boolean ("migrated")) {
+ var builder = new VariantBuilder (new VariantType ("a(ss)"));
+ var length = 0;
+
+ var layout_settings = new Settings ("org.gnome.libgnomekbd.keyboard");
+ var layouts = layout_settings.get_strv ("layouts");
+
+ foreach (var layout in layouts) {
+ var source = layout;
+ source = source.replace (" ", "+");
+ source = source.replace ("\t", "+");
- var layout_settings = new Settings ("org.gnome.libgnomekbd.keyboard");
- var layouts = layout_settings.get_strv ("layouts");
+ builder.add ("(ss)", "xkb", source);
+ length++;
+ }
- foreach (var layout in layouts) {
- var source = layout;
+ var engines = get_ibus ().list_active_engines ();
- source = source.replace (" ", "+");
- source = source.replace ("\t", "+");
+ foreach (var engine in engines) {
+ if (length == 0 || engine.name.has_prefix ("xkb")) {
+ var source = "us";
+ string? layout = engine.get_layout ();
+ string? variant = engine.get_layout_variant ();
- builder.add ("(ss)", "xkb", source);
- length++;
- }
+ if (layout != null && ((!) layout).length == 0) {
+ layout = null;
+ }
- var engines = get_ibus ().list_active_engines ();
+ if (variant != null && ((!) variant).length == 0) {
+ variant = null;
+ }
- foreach (var engine in engines) {
- if (length == 0 || engine.name.has_prefix ("xkb")) {
- var source = "us";
- string? layout = engine.get_layout ();
- string? variant = engine.get_layout_variant ();
+ if (layout != null && variant != null) {
+ source = @"$((!) layout)+$((!) variant)";
+ } else if (layout != null) {
+ source = (!) layout;
+ }
- if (layout != null && ((!) layout).length == 0) {
- layout = null;
+ builder.add ("(ss)", "xkb", source);
+ length++;
}
- if (variant != null && ((!) variant).length == 0) {
- variant = null;
+ if (!engine.name.has_prefix ("xkb")) {
+ builder.add ("(ss)", "ibus", engine.name);
+ length++;
}
+ }
- if (layout != null && variant != null) {
- source = @"$((!) layout)+$((!) variant)";
- } else if (layout != null) {
- source = (!) layout;
- }
+ source_settings.set_value ("sources", builder.end ());
+ indicator_settings.set_boolean ("migrated", true);
+ }
+ }
+ }
- builder.add ("(ss)", "xkb", source);
- length++;
+ [DBus (visible = false)]
+ private void migrate_input_sources () {
+ var list = new Gee.LinkedList<string> ();
+ var added = new Gee.HashSet<string> ();
+
+ foreach (var user in users) {
+ if (user.is_loaded) {
+ var sources = user.input_sources;
+ var layouts = user.xkeyboard_layouts;
+
+ VariantIter outer;
+ VariantIter inner;
+
+ sources.get ("aa{ss}", out outer);
+
+ while (outer.next ("a{ss}", out inner)) {
+ unowned string key;
+ unowned string source;
+
+ while (inner.next ("{&s&s}", out key, out source)) {
+ if (key == "xkb") {
+ if (!added.contains (source)) {
+ list.add (source);
+ added.add (source);
+ }
+ }
+ }
}
- if (!engine.name.has_prefix ("xkb")) {
- builder.add ("(ss)", "ibus", engine.name);
- length++;
+ foreach (var layout in layouts) {
+ var source = layout;
+ source = source.replace (" ", "+");
+ source = source.replace ("\t", "+");
+
+ if (!added.contains (source)) {
+ list.add (source);
+ added.add (source);
+ }
}
}
+ }
- source_settings.set_value ("sources", builder.end ());
+ var builder = new VariantBuilder (new VariantType ("a(ss)"));
- indicator_settings.set_boolean ("migrated", true);
+ foreach (var layout in list) {
+ builder.add ("(ss)", "xkb", layout);
+ }
+
+ source_settings.set_value ("sources", builder.end ());
+ }
+
+ [DBus (visible = false)]
+ private void update_login_layout () {
+ unowned List<LightDM.Layout> layouts = LightDM.get_layouts ();
+ var current = source_settings.get_uint ("current");
+
+ if (current < get_sources ().length) {
+ var source = get_sources ()[current];
+ string? name = null;
+
+ if (source.layout != null && source.variant != null) {
+ name = @"$((!) source.layout)\t$((!) source.variant)";
+ } else if (source.layout != null) {
+ name = source.layout;
+ }
+
+ if (name != null) {
+ foreach (var layout in layouts) {
+ if (layout.name == (!) name) {
+ LightDM.set_layout (layout);
+ break;
+ }
+ }
+ }
}
}
[DBus (visible = false)]
private void update_window_sources () {
- if (use_bamf) {
+ if (use_bamf && !is_login_user ()) {
var group_per_window = per_window_settings.get_boolean ("group-per-window");
if (group_per_window != (window_sources != null)) {
@@ -318,11 +437,13 @@ public class Indicator.Keyboard.Service : Object {
submenu.append_section (null, section_menu);
- var section = new Menu ();
- section.append (_ ("Character Map"), "indicator.map");
- section.append (_ ("Keyboard Layout Chart"), "indicator.chart");
- section.append (_ ("Text Entry Settings..."), "indicator.settings");
- submenu.append_section (null, section);
+ if (!is_login_user ()) {
+ var section = new Menu ();
+ section.append (_ ("Character Map"), "indicator.map");
+ section.append (_ ("Keyboard Layout Chart"), "indicator.chart");
+ section.append (_ ("Text Entry Settings..."), "indicator.settings");
+ submenu.append_section (null, section);
+ }
var indicator = new MenuItem.submenu ("x", submenu);
indicator.set_attribute ("x-canonical-type", "s", "com.canonical.indicator.root");
@@ -349,6 +470,7 @@ public class Indicator.Keyboard.Service : Object {
[DBus (visible = false)]
private void handle_changed_current (string key) {
update_indicator_action ();
+ update_login_layout ();
}
[DBus (visible = false)]
@@ -357,6 +479,7 @@ public class Indicator.Keyboard.Service : Object {
update_sources_menu ();
update_indicator_action ();
+ update_login_layout ();
}
[DBus (visible = false)]