aboutsummaryrefslogtreecommitdiff
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
parent17b5871e6c8d0067543f0eeb82a533e2dab83ff5 (diff)
downloadayatana-indicator-keyboard-961446aefd28debf647c67aeda152d9b1b65ca92.tar.gz
ayatana-indicator-keyboard-961446aefd28debf647c67aeda152d9b1b65ca92.tar.bz2
ayatana-indicator-keyboard-961446aefd28debf647c67aeda152d9b1b65ca92.zip
Guess correct keyboard layout.
-rw-r--r--configure.ac10
-rw-r--r--deps/Xkl-1.0.metadata18
-rw-r--r--deps/libxklavier.vapi36
-rw-r--r--lib/Makefile.am6
-rw-r--r--lib/main.vala34
5 files changed, 77 insertions, 27 deletions
diff --git a/configure.ac b/configure.ac
index 380ff654..a5f077d0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -28,14 +28,18 @@ PKG_CHECK_MODULES([GTK], [gtk+-3.0])
AC_SUBST([GTK_CFLAGS])
AC_SUBST([GTK_LIBS])
-PKG_CHECK_MODULES([IBUS], [ibus-1.0])
-AC_SUBST([IBUS_CFLAGS])
-AC_SUBST([IBUS_LIBS])
+PKG_CHECK_MODULES([LIBXKLAVIER], [libxklavier])
+AC_SUBST([LIBXKLAVIER_CFLAGS])
+AC_SUBST([LIBXKLAVIER_LIBS])
PKG_CHECK_MODULES([LIBGNOMEKBD], [libgnomekbdui])
AC_SUBST([LIBGNOMEKBD_CFLAGS])
AC_SUBST([LIBGNOMEKBD_LIBS])
+PKG_CHECK_MODULES([IBUS], [ibus-1.0])
+AC_SUBST([IBUS_CFLAGS])
+AC_SUBST([IBUS_LIBS])
+
AC_CONFIG_FILES([Makefile
data/Makefile
data/indicator-keyboard.service
diff --git a/deps/Xkl-1.0.metadata b/deps/Xkl-1.0.metadata
index 3f8f4706..62226dbc 100644
--- a/deps/Xkl-1.0.metadata
+++ b/deps/Xkl-1.0.metadata
@@ -1 +1,19 @@
+ConfigItem cheader_filename="libxklavier/xklavier.h"
+ConfigRec cheader_filename="libxklavier/xklavier.h"
+ConfigRegistry cheader_filename="libxklavier/xklavier.h"
+Engine cheader_filename="libxklavier/xklavier.h"
+State cheader_filename="libxklavier/xklavier.h"
+EngineFeatures cheader_filename="libxklavier/xklavier.h"
+EngineListenModes cheader_filename="libxklavier/xklavier.h"
+EngineStateChange cheader_filename="libxklavier/xklavier.h"
+ConfigItemProcessFunc cheader_filename="libxklavier/xklavier.h"
+TwoConfigItemsProcessFunc cheader_filename="libxklavier/xklavier.h"
+MAX_CI_DESC_LENGTH cheader_filename="libxklavier/xklavier.h"
+MAX_CI_NAME_LENGTH cheader_filename="libxklavier/xklavier.h"
+MAX_CI_SHORT_DESC_LENGTH cheader_filename="libxklavier/xklavier.h"
+get_country_name cheader_filename="libxklavier/xklavier.h"
+get_language_name cheader_filename="libxklavier/xklavier.h"
+get_last_error cheader_filename="libxklavier/xklavier.h"
+restore_names_prop cheader_filename="libxklavier/xklavier.h"
+set_debug_level cheader_filename="libxklavier/xklavier.h"
Engine.filter_events.evt type="X.Event"
diff --git a/deps/libxklavier.vapi b/deps/libxklavier.vapi
index 8e248f23..a2b7738c 100644
--- a/deps/libxklavier.vapi
+++ b/deps/libxklavier.vapi
@@ -2,7 +2,7 @@
[CCode (cprefix = "Xkl", gir_namespace = "Xkl", gir_version = "1.0", lower_case_cprefix = "xkl_")]
namespace Xkl {
- [CCode (cheader_filename = "Xkl-1.0.h", type_id = "xkl_config_item_get_type ()")]
+ [CCode (cheader_filename = "libxklavier/xklavier.h", type_id = "xkl_config_item_get_type ()")]
public class ConfigItem : GLib.Object {
[CCode (array_length = false, array_null_terminated = true)]
public weak char[] description;
@@ -16,7 +16,7 @@ namespace Xkl {
public void set_name (string? name);
public void set_short_description (string? short_description);
}
- [CCode (cheader_filename = "Xkl-1.0.h", type_id = "xkl_config_rec_get_type ()")]
+ [CCode (cheader_filename = "libxklavier/xklavier.h", type_id = "xkl_config_rec_get_type ()")]
public class ConfigRec : GLib.Object {
[CCode (array_length = false, array_null_terminated = true)]
public weak string[] layouts;
@@ -39,7 +39,7 @@ namespace Xkl {
public void set_variants ([CCode (array_length = false, array_null_terminated = true)] string[] new_variants);
public static bool write_to_file (Xkl.Engine engine, string file_name, Xkl.ConfigRec data, bool binary);
}
- [CCode (cheader_filename = "Xkl-1.0.h", type_id = "xkl_config_registry_get_type ()")]
+ [CCode (cheader_filename = "libxklavier/xklavier.h", type_id = "xkl_config_registry_get_type ()")]
public class ConfigRegistry : GLib.Object {
[CCode (has_construct_function = false)]
protected ConfigRegistry ();
@@ -63,7 +63,7 @@ namespace Xkl {
[NoAccessorMethod]
public Xkl.Engine engine { owned get; construct; }
}
- [CCode (cheader_filename = "Xkl-1.0.h", type_id = "xkl_engine_get_type ()")]
+ [CCode (cheader_filename = "libxklavier/xklavier.h", type_id = "xkl_engine_get_type ()")]
public class Engine : GLib.Object {
[CCode (has_construct_function = false)]
protected Engine ();
@@ -129,13 +129,13 @@ namespace Xkl {
public signal void X_new_device ();
public signal int new_toplevel_window (long object, long p0);
}
- [CCode (cheader_filename = "Xkl-1.0.h", copy_function = "g_boxed_copy", free_function = "g_boxed_free", type_id = "xkl_state_get_type ()")]
+ [CCode (cheader_filename = "libxklavier/xklavier.h", copy_function = "g_boxed_copy", free_function = "g_boxed_free", type_id = "xkl_state_get_type ()")]
[Compact]
public class State {
public int32 group;
public uint32 indicators;
}
- [CCode (cheader_filename = "Xkl-1.0.h", cprefix = "XKLF_", has_type_id = false)]
+ [CCode (cheader_filename = "libxklavier/xklavier.h", cprefix = "XKLF_", has_type_id = false)]
[Flags]
public enum EngineFeatures {
CAN_TOGGLE_INDICATORS,
@@ -145,37 +145,37 @@ namespace Xkl {
REQUIRES_MANUAL_LAYOUT_MANAGEMENT,
DEVICE_DISCOVERY
}
- [CCode (cheader_filename = "Xkl-1.0.h", cprefix = "XKLL_", has_type_id = false)]
+ [CCode (cheader_filename = "libxklavier/xklavier.h", cprefix = "XKLL_", has_type_id = false)]
public enum EngineListenModes {
MANAGE_WINDOW_STATES,
TRACK_KEYBOARD_STATE,
MANAGE_LAYOUTS
}
- [CCode (cheader_filename = "Xkl-1.0.h", cprefix = "", has_type_id = false)]
+ [CCode (cheader_filename = "libxklavier/xklavier.h", cprefix = "", has_type_id = false)]
public enum EngineStateChange {
[CCode (cname = "GROUP_CHANGED")]
ROUP_CHANGED,
[CCode (cname = "INDICATORS_CHANGED")]
NDICATORS_CHANGED
}
- [CCode (cheader_filename = "Xkl-1.0.h", has_target = false)]
+ [CCode (cheader_filename = "libxklavier/xklavier.h", has_target = false)]
public delegate void ConfigItemProcessFunc (Xkl.ConfigRegistry config, Xkl.ConfigItem item, void* data);
- [CCode (cheader_filename = "Xkl-1.0.h", has_target = false)]
+ [CCode (cheader_filename = "libxklavier/xklavier.h", has_target = false)]
public delegate void TwoConfigItemsProcessFunc (Xkl.ConfigRegistry config, Xkl.ConfigItem item, Xkl.ConfigItem subitem, void* data);
- [CCode (cheader_filename = "Xkl-1.0.h", cname = "XKL_MAX_CI_DESC_LENGTH")]
+ [CCode (cheader_filename = "libxklavier/xklavier.h", cname = "XKL_MAX_CI_DESC_LENGTH")]
public const int MAX_CI_DESC_LENGTH;
- [CCode (cheader_filename = "Xkl-1.0.h", cname = "XKL_MAX_CI_NAME_LENGTH")]
+ [CCode (cheader_filename = "libxklavier/xklavier.h", cname = "XKL_MAX_CI_NAME_LENGTH")]
public const int MAX_CI_NAME_LENGTH;
- [CCode (cheader_filename = "Xkl-1.0.h", cname = "XKL_MAX_CI_SHORT_DESC_LENGTH")]
+ [CCode (cheader_filename = "libxklavier/xklavier.h", cname = "XKL_MAX_CI_SHORT_DESC_LENGTH")]
public const int MAX_CI_SHORT_DESC_LENGTH;
- [CCode (cheader_filename = "Xkl-1.0.h")]
+ [CCode (cheader_filename = "libxklavier/xklavier.h")]
public static unowned string get_country_name (string code);
- [CCode (cheader_filename = "Xkl-1.0.h")]
+ [CCode (cheader_filename = "libxklavier/xklavier.h")]
public static unowned string get_language_name (string code);
- [CCode (cheader_filename = "Xkl-1.0.h")]
+ [CCode (cheader_filename = "libxklavier/xklavier.h")]
public static unowned string get_last_error ();
- [CCode (cheader_filename = "Xkl-1.0.h")]
+ [CCode (cheader_filename = "libxklavier/xklavier.h")]
public static bool restore_names_prop (Xkl.Engine engine);
- [CCode (cheader_filename = "Xkl-1.0.h")]
+ [CCode (cheader_filename = "libxklavier/xklavier.h")]
public static void set_debug_level (int level);
}
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);
}