aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorWilliam Hua <william.hua@canonical.com>2013-04-02 10:14:06 -0400
committerWilliam Hua <william.hua@canonical.com>2013-04-02 10:14:06 -0400
commit961446aefd28debf647c67aeda152d9b1b65ca92 (patch)
treecb019c9725f839e5a6c980f212670e4d2d083bc8 /lib
parent17b5871e6c8d0067543f0eeb82a533e2dab83ff5 (diff)
downloadayatana-indicator-keyboard-961446aefd28debf647c67aeda152d9b1b65ca92.tar.gz
ayatana-indicator-keyboard-961446aefd28debf647c67aeda152d9b1b65ca92.tar.bz2
ayatana-indicator-keyboard-961446aefd28debf647c67aeda152d9b1b65ca92.zip
Guess correct keyboard layout.
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile.am6
-rw-r--r--lib/main.vala34
2 files changed, 34 insertions, 6 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
index cb82ac28..d716aaa2 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -10,10 +10,12 @@ indicator_keyboard_service_VALAFLAGS = $(AM_VALAFLAGS) \
--pkg libgnomekbd \
--pkg Xkl-1.0
indicator_keyboard_service_CFLAGS = $(GTK_CFLAGS) \
- $(IBUS_CFLAGS) \
+ $(LIBXKLAVIER_CFLAGS) \
$(LIBGNOMEKBD_CFLAGS) \
+ $(IBUS_CFLAGS) \
$(AM_CFLAGS)
indicator_keyboard_service_LDFLAGS = $(GTK_LIBS) \
- $(IBUS_LIBS) \
+ $(LIBXKLAVIER_LIBS) \
$(LIBGNOMEKBD_LIBS) \
+ $(IBUS_LIBS) \
$(AM_LDFLAGS)
diff --git a/lib/main.vala b/lib/main.vala
index a0ce4e79..84724b57 100644
--- a/lib/main.vala
+++ b/lib/main.vala
@@ -32,8 +32,23 @@ public class Indicator.Keyboard.Service : Object {
[DBus (visible = false)]
private void handle_activate_chart (Variant? parameter) {
+ var layout = "us";
+
+ if (this.settings != null) {
+ Variant array;
+ string type;
+ string name;
+
+ var current = this.settings.get_uint ("current");
+ this.settings.get ("sources", "@a(ss)", out array);
+ array.get_child (current, "(ss)", out type, out name);
+
+ if (type == "xkb")
+ layout = name;
+ }
+
try {
- Process.spawn_command_line_async ("gkbd-keyboard-display -l fr");
+ Process.spawn_command_line_async (@"gkbd-keyboard-display -l $layout");
} catch {
warn_if_reached ();
}
@@ -102,12 +117,23 @@ public class Indicator.Keyboard.Service : Object {
VariantIter iter;
string type;
string name;
- uint i;
this.settings.get ("sources", "a(ss)", out iter);
- for (i = 0; iter.next ("(ss)", out type, out name); i++) {
- MenuItem menu_item = new MenuItem (name, "indicator.current");
+ for (var i = 0; iter.next ("(ss)", out type, out name); i++) {
+ if (type == "xkb") {
+ var language = Xkl.get_language_name (name);
+ var country = Xkl.get_country_name (name);
+
+ if (language != null && country != null)
+ name = @"$language ($country)";
+ else if (language != null)
+ name = language;
+ else if (country != null)
+ name = country;
+ }
+
+ var menu_item = new MenuItem (name, "indicator.current");
menu_item.set_attribute (Menu.ATTRIBUTE_TARGET, "u", i);
section.append_item (menu_item);
}