From 961446aefd28debf647c67aeda152d9b1b65ca92 Mon Sep 17 00:00:00 2001 From: William Hua Date: Tue, 2 Apr 2013 10:14:06 -0400 Subject: Guess correct keyboard layout. --- lib/Makefile.am | 6 ++++-- lib/main.vala | 34 ++++++++++++++++++++++++++++++---- 2 files changed, 34 insertions(+), 6 deletions(-) (limited to 'lib') 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); } -- cgit v1.2.3