ibus-m17n/ibus-m17n-xkb-options.patch

387 lines
12 KiB
Diff
Raw Normal View History

2011-07-07 05:37:21 +00:00
Patch to set certain XKB options when an m17n IME is set.
Index: ibus-m17n-1.3.2/configure.ac
===================================================================
--- ibus-m17n-1.3.2.orig/configure.ac
+++ ibus-m17n-1.3.2/configure.ac
@@ -106,6 +106,14 @@ AC_CHECK_FUNCS([ibus_engine_get_surround
CFLAGS="$save_CFLAGS"
LIBS="$save_LIBS"
+# check libxklavier
+have_libxklavier=no
+PKG_CHECK_MODULES([LIBXKLAVIER], [libxklavier gdk-3.0 x11],
+ have_libxklavier=yes)
+if test x$have_libxklavier != xno; then
+ AC_DEFINE([HAVE_LIBXKLAVIER], [1], [Define if libxklavier is found])
+fi
+
# define GETTEXT_* variables
GETTEXT_PACKAGE=ibus-m17n
AC_SUBST(GETTEXT_PACKAGE)
Index: ibus-m17n-1.3.2/src/Makefile.am
===================================================================
--- ibus-m17n-1.3.2.orig/src/Makefile.am
+++ ibus-m17n-1.3.2/src/Makefile.am
@@ -66,10 +66,15 @@ ibus_engine_m17n_SOURCES = \
engine.c \
engine.h \
$(NULL)
+ibus_engine_m17n_CFLAGS = \
+ @LIBXKLAVIER_CFLAGS@ \
+ $(AM_CFLAGS) \
+ $(NULL)
ibus_engine_m17n_LDADD = \
libm17ncommon.a \
@IBUS_LIBS@ \
@M17N_LIBS@ \
+ @LIBXKLAVIER_LIBS@ \
$(NULL)
if HAVE_GTK
Index: ibus-m17n-1.3.2/src/default.xml.in.in
===================================================================
--- ibus-m17n-1.3.2.orig/src/default.xml.in.in
+++ ibus-m17n-1.3.2/src/default.xml.in.in
@@ -12,19 +12,22 @@
<preedit-highlight>FALSE</preedit-highlight>
</engine>
<engine>
- <name>m17n:bn:inscript</name>
+ <name>m17n:bn:inscript*</name>
<rank>2</rank>
<preedit-highlight>FALSE</preedit-highlight>
+ <xkb-options>lv3:ralt_switch</xkb-options>
</engine>
<engine>
- <name>m17n:gu:inscript</name>
+ <name>m17n:gu:inscript*</name>
<rank>2</rank>
<preedit-highlight>FALSE</preedit-highlight>
+ <xkb-options>lv3:ralt_switch</xkb-options>
</engine>
<engine>
- <name>m17n:hi:inscript</name>
+ <name>m17n:hi:inscript*</name>
<rank>2</rank>
<preedit-highlight>FALSE</preedit-highlight>
+ <xkb-options>lv3:ralt_switch</xkb-options>
</engine>
<engine>
<name>m17n:kn:kgp</name>
@@ -37,19 +40,22 @@
<preedit-highlight>FALSE</preedit-highlight>
</engine>
<engine>
- <name>m17n:mai:inscript</name>
+ <name>m17n:mai:inscript*</name>
<rank>2</rank>
<preedit-highlight>FALSE</preedit-highlight>
+ <xkb-options>lv3:ralt_switch</xkb-options>
</engine>
<engine>
- <name>m17n:ml:inscript</name>
+ <name>m17n:ml:inscript*</name>
<rank>2</rank>
<preedit-highlight>FALSE</preedit-highlight>
+ <xkb-options>lv3:ralt_switch</xkb-options>
</engine>
<engine>
- <name>m17n:mr:inscript</name>
+ <name>m17n:mr:inscript*</name>
<rank>2</rank>
<preedit-highlight>FALSE</preedit-highlight>
+ <xkb-options>lv3:ralt_switch</xkb-options>
</engine>
<engine>
<name>m17n:ne:rom</name>
@@ -57,14 +63,16 @@
<preedit-highlight>FALSE</preedit-highlight>
</engine>
<engine>
- <name>m17n:or:inscript</name>
+ <name>m17n:or:inscript*</name>
<rank>2</rank>
<preedit-highlight>FALSE</preedit-highlight>
+ <xkb-options>lv3:ralt_switch</xkb-options>
</engine>
<engine>
- <name>m17n:pa:inscript</name>
+ <name>m17n:pa:inscript*</name>
<rank>2</rank>
<preedit-highlight>FALSE</preedit-highlight>
+ <xkb-options>lv3:ralt_switch</xkb-options>
</engine>
<engine>
<name>m17n:sa:harvard-kyoto</name>
@@ -72,14 +80,16 @@
<preedit-highlight>FALSE</preedit-highlight>
</engine>
<engine>
- <name>m17n:sd:inscript</name>
+ <name>m17n:sd:inscript*</name>
<rank>2</rank>
<preedit-highlight>FALSE</preedit-highlight>
+ <xkb-options>lv3:ralt_switch</xkb-options>
</engine>
<engine>
<name>m17n:si:wijesekera</name>
<rank>2</rank>
<preedit-highlight>FALSE</preedit-highlight>
+ <xkb-options>lv3:ralt_switch</xkb-options>
</engine>
<engine>
<name>m17n:ta:tamil99</name>
@@ -87,9 +97,10 @@
<preedit-highlight>FALSE</preedit-highlight>
</engine>
<engine>
- <name>m17n:te:inscript</name>
+ <name>m17n:te:inscript*</name>
<rank>2</rank>
<preedit-highlight>FALSE</preedit-highlight>
+ <xkb-options>lv3:ralt_switch</xkb-options>
</engine>
<!-- Samanala should have lower rank than other Sinhala
engines since it is the only non-keyboard input method in
@@ -226,6 +237,7 @@
<name>m17n:si:*</name>
<rank>1</rank>
<preedit-highlight>FALSE</preedit-highlight>
+ <xkb-options>lv3:ralt_switch</xkb-options>
</engine>
<engine>
<name>m17n:ta:*</name>
Index: ibus-m17n-1.3.2/src/engine.c
===================================================================
--- ibus-m17n-1.3.2.orig/src/engine.c
+++ ibus-m17n-1.3.2/src/engine.c
@@ -6,6 +6,10 @@
#include <ibus.h>
#include <m17n.h>
#include <string.h>
+#ifdef HAVE_LIBXKLAVIER
+#include <gdk/gdkx.h>
+#include <libxklavier/xklavier.h>
+#endif /* HAVE_LIBXKLAVIER */
#include "m17nutil.h"
#include "engine.h"
@@ -38,6 +42,10 @@ struct _IBusM17NEngineClass {
gboolean use_iok;
MInputMethod *im;
+
+#if HAVE_LIBXKLAVIER
+ XklConfigRec *xkl_config_rec;
+#endif /* HAVE_LIBXKLAVIER */
};
/* functions prototype */
@@ -105,12 +113,90 @@ static IBusEngineClass *parent_class = N
static IBusConfig *config = NULL;
+#if HAVE_LIBXKLAVIER
+static XklEngine *xkl_engine = NULL;
+static XklConfigRec *xkl_system_config_rec = NULL;
+
+static gboolean
+parse_xkb_options (XklConfigRec *config_rec, const gchar *xkb_options)
+{
+ gchar **strv;
+
+ strv = g_strsplit (xkb_options, ",", -1);
+ if (g_strv_length (strv) < 1) {
+ g_strfreev (strv);
+ return FALSE;
+ }
+
+ g_strfreev (config_rec->options);
+ config_rec->options = strv;
+
+ return TRUE;
+}
+
+static GdkFilterReturn
+filter_xkl_event (GdkXEvent *xev,
+ GdkEvent *event,
+ gpointer user_data)
+{
+ XEvent *xevent = (XEvent *)xev;
+
+ xkl_engine_filter_events (xkl_engine, xevent);
+ return GDK_FILTER_CONTINUE;
+}
+
+static void
+on_xkl_config_changed (XklEngine *xklengine,
+ gpointer user_data)
+{
+ IBusM17NEngineClass *klass = user_data;
+ XklConfigRec *config_rec;
+
+ config_rec = xkl_config_rec_new ();
+ if (!xkl_config_rec_get_from_server (config_rec, xkl_engine)) {
+ g_object_unref (config_rec);
+ g_warning ("Can't get default keyboard config from the server");
+ } else if (klass->xkl_config_rec &&
+ !xkl_config_rec_equals (config_rec, klass->xkl_config_rec)) {
+ if (xkl_system_config_rec)
+ g_object_unref (xkl_system_config_rec);
+ xkl_system_config_rec = config_rec;
+ }
+}
+#endif /* HAVE_LIBXKLAVIER */
+
void
ibus_m17n_init (IBusBus *bus)
{
+#if HAVE_LIBXKLAVIER
+ if (gdk_init_check (NULL, NULL)) {
+ GdkDisplay *display = gdk_display_get_default ();
+ g_assert (display);
+
+ xkl_engine = xkl_engine_get_instance (GDK_DISPLAY_XDISPLAY (display));
+ xkl_system_config_rec = xkl_config_rec_new ();
+ if (!xkl_config_rec_get_from_server (xkl_system_config_rec,
+ xkl_engine)) {
+ g_object_unref (xkl_system_config_rec);
+ xkl_system_config_rec = NULL;
+
+ g_warning ("Can't get default keyboard config from the server");
+ } else {
+ gdk_window_add_filter (NULL,
+ (GdkFilterFunc) filter_xkl_event,
+ NULL);
+ gdk_window_add_filter (gdk_get_default_root_window (),
+ (GdkFilterFunc) filter_xkl_event,
+ NULL);
+ xkl_engine_start_listen (xkl_engine, XKLL_TRACK_KEYBOARD_STATE);
+ }
+ }
+#endif /* HAVE_LIBXKLAVIER */
+
config = ibus_bus_get_config (bus);
if (config)
g_object_ref_sink (config);
+
ibus_m17n_init_common ();
}
@@ -299,6 +385,25 @@ ibus_m17n_engine_class_init (IBusM17NEng
G_CALLBACK(ibus_m17n_config_value_changed),
klass);
+#if HAVE_LIBXKLAVIER
+ if (engine_config->xkb_options) {
+ klass->xkl_config_rec = xkl_config_rec_new ();
+ if (!xkl_config_rec_get_from_server (klass->xkl_config_rec,
+ xkl_engine)) {
+ g_object_unref (klass->xkl_config_rec);
+ g_warning ("Can't get default keyboard config from the server");
+ } else if (!parse_xkb_options (klass->xkl_config_rec,
+ engine_config->xkb_options)) {
+ g_object_unref (klass->xkl_config_rec);
+ g_warning ("Can't parse xkb options %s",
+ engine_config->xkb_options);
+ }
+ }
+
+ g_signal_connect (xkl_engine, "X-config-changed",
+ G_CALLBACK(on_xkl_config_changed), klass);
+#endif /* HAVE_LIBXKLAVIER */
+
klass->im = NULL;
}
@@ -412,6 +517,9 @@ ibus_m17n_engine_constructor (GType
IBusM17NEngine *m17n;
GObjectClass *object_class;
IBusM17NEngineClass *klass;
+#if HAVE_LIBXKLAVIER
+ GdkDisplay *display;
+#endif /* HAVE_LIBXKLAVIER */
m17n = (IBusM17NEngine *) G_OBJECT_CLASS (parent_class)->constructor (type,
n_construct_params,
@@ -499,6 +607,11 @@ ibus_m17n_engine_destroy (IBusM17NEngine
m17n->context = NULL;
}
+#if HAVE_LIBXKLAVIER
+ if (xkl_system_config_rec)
+ xkl_config_rec_activate (xkl_system_config_rec, xkl_engine);
+#endif /* HAVE_LIBXKLAVIER */
+
IBUS_OBJECT_CLASS (parent_class)->destroy ((IBusObject *)m17n);
}
@@ -735,6 +848,19 @@ ibus_m17n_engine_enable (IBusEngine *eng
ibus_engine_get_surrounding_text (engine, &text, &cursor_pos);
g_object_unref (text);
#endif /* HAVE_IBUS_ENGINE_GET_SURROUNDING_TEXT */
+
+#if HAVE_LIBXKLAVIER
+ GObjectClass *object_class;
+ IBusM17NEngineClass *klass;
+
+ object_class = G_OBJECT_GET_CLASS (m17n);
+ klass = (IBusM17NEngineClass *) object_class;
+
+ if (klass->xkl_config_rec) {
+ if (!xkl_config_rec_activate (klass->xkl_config_rec, xkl_engine))
+ g_warning ("Can't set the XKB layout");
+ }
+#endif /* HAVE_LIBXKLAVIER */
}
static void
@@ -744,6 +870,17 @@ ibus_m17n_engine_disable (IBusEngine *en
ibus_m17n_engine_focus_out (engine);
parent_class->disable (engine);
+
+#if HAVE_LIBXKLAVIER
+ GObjectClass *object_class;
+ IBusM17NEngineClass *klass;
+
+ object_class = G_OBJECT_GET_CLASS (m17n);
+ klass = (IBusM17NEngineClass *) object_class;
+
+ if (xkl_system_config_rec)
+ xkl_config_rec_activate (xkl_system_config_rec, xkl_engine);
+#endif /* HAVE_LIBXKLAVIER */
}
static void
Index: ibus-m17n-1.3.2/src/m17nutil.c
===================================================================
--- ibus-m17n-1.3.2.orig/src/m17nutil.c
+++ ibus-m17n-1.3.2/src/m17nutil.c
@@ -290,6 +290,11 @@ ibus_m17n_engine_config_parse_xml_node (
sub_node->name, sub_node->text);
continue;
}
+ if (g_strcmp0 (sub_node->name, "xkb-options") == 0) {
+ g_free (cnode->config.xkb_options);
+ cnode->config.xkb_options = g_strdup (sub_node->text);
+ continue;
+ }
g_warning ("<engine> element contains invalid element <%s>",
sub_node->name);
}
Index: ibus-m17n-1.3.2/src/m17nutil.h
===================================================================
--- ibus-m17n-1.3.2.orig/src/m17nutil.h
+++ ibus-m17n-1.3.2/src/m17nutil.h
@@ -16,6 +16,9 @@ struct _IBusM17NEngineConfig {
/* whether to highlight preedit */
gboolean preedit_highlight;
+
+ /* keyboard options to which the engine switches when enabled */
+ char *xkb_options;
};
typedef struct _IBusM17NEngineConfig IBusM17NEngineConfig;