diff options
author | William Hua <william.hua@canonical.com> | 2013-05-07 16:17:29 -0400 |
---|---|---|
committer | William Hua <william.hua@canonical.com> | 2013-05-07 16:17:29 -0400 |
commit | c121830a02e1367b54c8b71d1341e935e96d03fa (patch) | |
tree | 3d29c8f7fd8309b4d279e224520ef5bbb7bc89c8 /lib | |
parent | aa4b13008af3258f4802f6ee9d874cafc9ba44c7 (diff) | |
download | ayatana-indicator-keyboard-c121830a02e1367b54c8b71d1341e935e96d03fa.tar.gz ayatana-indicator-keyboard-c121830a02e1367b54c8b71d1341e935e96d03fa.tar.bz2 ayatana-indicator-keyboard-c121830a02e1367b54c8b71d1341e935e96d03fa.zip |
Fix keyboard layout display names.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Makefile.am | 36 | ||||
-rw-r--r-- | lib/main.vala | 87 |
2 files changed, 87 insertions, 36 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am index 17e8f2dc..6569c9cb 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1,3 +1,4 @@ +AM_CFLAGS = -DGNOME_DESKTOP_USE_UNSTABLE_API AM_LDFLAGS = -lm AM_VALAFLAGS = --metadatadir $(top_srcdir)/deps \ --vapidir $(top_srcdir)/deps @@ -5,22 +6,25 @@ AM_VALAFLAGS = --metadatadir $(top_srcdir)/deps \ libexec_PROGRAMS = indicator-keyboard-service indicator_keyboard_service_SOURCES = main.vala -indicator_keyboard_service_VALAFLAGS = $(AM_VALAFLAGS) \ - --pkg posix \ - --pkg pangocairo \ - --pkg gtk+-3.0 \ - --pkg Xkl-1.0 \ - --pkg libgnomekbd \ +indicator_keyboard_service_VALAFLAGS = $(AM_VALAFLAGS) \ + --pkg posix \ + --pkg pangocairo \ + --pkg gtk+-3.0 \ + --pkg gnome-desktop-3.0 \ + --pkg Xkl-1.0 \ + --pkg libgnomekbd \ --pkg ibus-1.0 -indicator_keyboard_service_CFLAGS = $(GTK_CFLAGS) \ - $(PANGOCAIRO_CFLAGS) \ - $(LIBXKLAVIER_CFLAGS) \ - $(LIBGNOMEKBD_CFLAGS) \ - $(IBUS_CFLAGS) \ +indicator_keyboard_service_CFLAGS = $(GTK_CFLAGS) \ + $(PANGOCAIRO_CFLAGS) \ + $(GNOME_DESKTOP_CFLAGS) \ + $(LIBXKLAVIER_CFLAGS) \ + $(LIBGNOMEKBD_CFLAGS) \ + $(IBUS_CFLAGS) \ $(AM_CFLAGS) -indicator_keyboard_service_LDFLAGS = $(GTK_LIBS) \ - $(PANGOCAIRO_LIBS) \ - $(LIBXKLAVIER_LIBS) \ - $(LIBGNOMEKBD_LIBS) \ - $(IBUS_LIBS) \ +indicator_keyboard_service_LDFLAGS = $(GTK_LIBS) \ + $(PANGOCAIRO_LIBS) \ + $(GNOME_DESKTOP_LIBS) \ + $(LIBXKLAVIER_LIBS) \ + $(LIBGNOMEKBD_LIBS) \ + $(IBUS_LIBS) \ $(AM_LDFLAGS) diff --git a/lib/main.vala b/lib/main.vala index 77ea4636..759b8cbb 100644 --- a/lib/main.vala +++ b/lib/main.vala @@ -4,6 +4,7 @@ public class Indicator.Keyboard.Service : Object { private MainLoop loop; private Settings indicator_settings; private Settings source_settings; + private Gnome.XkbInfo xkb_info; private IBus.Bus ibus; private SimpleActionGroup action_group; @@ -29,6 +30,8 @@ public class Indicator.Keyboard.Service : Object { this.source_settings.changed["current"].connect (this.handle_changed_current); this.source_settings.changed["sources"].connect (this.handle_changed_sources); + this.xkb_info = new Gnome.XkbInfo (); + this.loop = new MainLoop (); this.loop.run (); } @@ -115,7 +118,22 @@ public class Indicator.Keyboard.Service : Object { string name; array.get_child (index, "(ss)", out type, out name); - this.icons[index] = create_icon (name); + + if (type == "xkb") { + this.icons[index] = create_icon (name); + } else if (type == "ibus") { + var ibus = get_ibus (); + string[] names = { name, null }; + var engines = ibus.get_engines_by_names (names); + var engine = engines[0]; + + try { + this.icons[index] = Icon.new_for_string (engine.get_icon ()); + } catch { + warn_if_reached (); + } + } + icon = this.icons[index]; } } @@ -230,15 +248,24 @@ public class Indicator.Keyboard.Service : Object { 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; + string display_name; + string layout_name; + + this.xkb_info.get_layout_info (name, out display_name, null, out layout_name, null); + + if (display_name == null) { + var language = Xkl.get_language_name (layout_name); + var country = Xkl.get_country_name (layout_name); + + if (language != null && country != null) { + name = @"$language ($country)"; + } else if (language != null) { + name = language; + } else if (country != null) { + name = country; + } + } else { + name = display_name; } } else if (type == "ibus") { @@ -246,16 +273,19 @@ public class Indicator.Keyboard.Service : Object { string[] names = { name, null }; var engines = ibus.get_engines_by_names (names); var engine = engines[0]; - var longname = engine.longname; - var language = Xkl.get_language_name (engine.language); - var country = Xkl.get_country_name (engine.language); + var language = engine.get_language (); + var display_name = engine.get_longname (); if (language != null) { - name = @"$language ($longname)"; - } else if (country != null) { - name = @"$country ($longname)"; - } else { - name = longname; + language = Xkl.get_language_name (language); + } + + if (language != null && display_name != null) { + name = @"$language ($display_name)"; + } else if (language != null) { + name = language; + } else if (display_name != null) { + name = display_name; } } @@ -317,6 +347,7 @@ public class Indicator.Keyboard.Service : Object { [DBus (visible = false)] private void handle_activate_chart (Variant? parameter) { var layout = "us"; + string variant = null; var current = this.source_settings.get_uint ("current"); Variant array; @@ -329,12 +360,28 @@ public class Indicator.Keyboard.Service : Object { array.get_child (current, "(ss)", out type, out name); if (type == "xkb") { - layout = name; + this.xkb_info.get_layout_info (name, null, null, out layout, out variant); + } else if (type == "ibus") { + var ibus = get_ibus (); + string[] names = { name, null }; + var engines = ibus.get_engines_by_names (names); + var engine = engines[0]; + + layout = engine.get_layout (); + variant = engine.get_layout_variant (); } } try { - Process.spawn_command_line_async (@"gkbd-keyboard-display -l $layout"); + string command; + + if (variant != null) { + command = @"gkbd-keyboard-display -l \"$layout\t$variant\""; + } else { + command = @"gkbd-keyboard-display -l $layout"; + } + + Process.spawn_command_line_async (command); } catch { warn_if_reached (); } |