[gnome-settings-daemon/wip/input-sources: 5/6] keyboard: Add the IBus engine setting code



commit fbdac0e6dc39b32fc386f391f227e31a05a39670
Author: Rui Matos <tiagomatos gmail com>
Date:   Tue Apr 17 15:39:00 2012 +0200

    keyboard: Add the IBus engine setting code
    
    We simply connect to IBus and tell it to switch engine when our
    current input source setting is changed and an IBus engine is
    specified there. The responsibility to make sure that this engine
    actually exists on the IBus side is left to whoever writes the
    setting.
    
    At the same time, if an IBus engine is specified, we flip the setting
    that backs the Gtk/IMModule XSETTING so that GTK+ applications get
    notified to load the IBus input method when needed and go back to the
    simple input method when IBus isn't required.

 configure.ac                            |   28 +++++++++++++++-
 plugins/keyboard/Makefile.am            |    2 +
 plugins/keyboard/gsd-keyboard-manager.c |   56 +++++++++++++++++++++++++++++++
 3 files changed, 85 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index f05cb88..0647bdf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -184,6 +184,32 @@ AC_ARG_WITH(xkb-config-root,
         [XKBCONFIGROOT=${datadir}/X11/xkb])
 AC_SUBST([XKBCONFIGROOT])
 
+IBUS_CFLAGS=
+IBUS_LIBS=
+AC_ARG_ENABLE(ibus,
+        AS_HELP_STRING([--enable-ibus],
+                       [Enable IBus support (auto)]),
+        enable_ibus=$enableval,
+        enable_ibus=auto)
+
+if test "x$enable_ibus" = "xno" ; then
+        have_ibus=no
+else
+        have_ibus=no
+        PKG_CHECK_MODULES(IBUS, ibus-1.0, have_ibus=yes, have_ibus=no)
+
+        if test "x$enable_ibus" = "xyes" -a "x$have_ibus" = "xno" ; then
+                AC_MSG_ERROR(IBus support explicity enabled but not available)
+        fi
+
+        if test "x$have_ibus" = "xyes" ; then
+                AC_DEFINE(HAVE_IBUS, 1, [Defined if IBus support is enabled])
+        fi
+fi
+AM_CONDITIONAL(HAVE_IBUS, test "x$have_ibus" = "xyes")
+AC_SUBST(IBUS_CFLAGS)
+AC_SUBST(IBUS_LIBS)
+
 dnl ---------------------------------------------------------------------------
 dnl - Housekeeping plugin stuff
 dnl ---------------------------------------------------------------------------
@@ -515,7 +541,7 @@ echo "
 
         Session tracking:         ${SESSION_TRACKING}
         LCMS DICT support:        ${have_new_lcms}
-
+        IBus support:             ${have_ibus}
         Libnotify support:        ${have_libnotify}
         PackageKit support:       ${have_packagekit}
         Smartcard support:        ${have_smartcard_support}
diff --git a/plugins/keyboard/Makefile.am b/plugins/keyboard/Makefile.am
index d1192f3..2b90548 100644
--- a/plugins/keyboard/Makefile.am
+++ b/plugins/keyboard/Makefile.am
@@ -37,6 +37,7 @@ libkeyboard_la_CFLAGS = \
 	$(PLUGIN_CFLAGS)		\
 	$(SETTINGS_PLUGIN_CFLAGS)	\
 	$(KEYBOARD_CFLAGS)		\
+	$(IBUS_CFLAGS)			\
 	$(AM_CFLAGS)
 
 libkeyboard_la_LDFLAGS = 	\
@@ -48,6 +49,7 @@ libkeyboard_la_LIBADD  =				\
 	$(SETTINGS_PLUGIN_LIBS)				\
 	$(XF86MISC_LIBS)				\
 	$(KEYBOARD_LIBS)				\
+	$(IBUS_LIBS)					\
 	$(NULL)
 
 noinst_PROGRAMS = test-keyboard
diff --git a/plugins/keyboard/gsd-keyboard-manager.c b/plugins/keyboard/gsd-keyboard-manager.c
index 4b41426..5609520 100644
--- a/plugins/keyboard/gsd-keyboard-manager.c
+++ b/plugins/keyboard/gsd-keyboard-manager.c
@@ -42,6 +42,10 @@
 #include <X11/keysym.h>
 #include <X11/extensions/XKBrules.h>
 
+#ifdef HAVE_IBUS
+#include <ibus.h>
+#endif
+
 #include "gnome-settings-profile.h"
 #include "gsd-keyboard-manager.h"
 #include "gsd-input-helper.h"
@@ -81,11 +85,22 @@
 #define DFLT_XKB_MODEL "pc105"
 #endif
 
+#ifdef HAVE_IBUS
+#define GNOME_DESKTOP_INTERFACE_DIR "org.gnome.desktop.interface"
+
+#define KEY_GTK_IM_MODULE "gtk-im-module"
+#define GTK_IM_MODULE_SIMPLE "gtk-im-context-simple"
+#define GTK_IM_MODULE_IBUS   "ibus"
+#endif
+
 struct GsdKeyboardManagerPrivate
 {
 	guint      start_idle_id;
         GSettings *settings;
         GSettings *is_settings;
+#ifdef HAVE_IBUS
+        GSettings *interface_settings;
+#endif
         gulong     ignore_serial;
         gint       xkb_event_base;
         GsdNumLockState old_state;
@@ -330,6 +345,28 @@ apply_xkb_layout (GsdKeyboardManager *manager,
         g_free (rules_path);
 }
 
+#ifdef HAVE_IBUS
+static void
+apply_ibus_engine (GsdKeyboardManager *manager,
+                   const gchar        *engine)
+{
+        IBusEngineDesc *desc = NULL;
+        IBusBus *ibus = ibus_bus_new ();
+
+        if (!ibus_bus_set_global_engine (ibus, engine) ||
+            !(desc = ibus_bus_get_global_engine (ibus)))
+                g_warning ("Couldn't set IBus engine");
+        else
+                g_settings_set_string (manager->priv->interface_settings,
+                                       KEY_GTK_IM_MODULE,
+                                       GTK_IM_MODULE_IBUS);
+
+        g_object_unref (ibus);
+        if (desc)
+                g_object_unref (desc);
+}
+#endif
+
 static void
 apply_input_sources_settings (GSettings          *settings,
                               gchar              *key,
@@ -343,6 +380,14 @@ apply_input_sources_settings (GSettings          *settings,
                         "(&s&s&s&s&s)", NULL, NULL, &layout, &variant, &engine);
 
         apply_xkb_layout (manager, layout, variant);
+#ifdef HAVE_IBUS
+        if (engine && engine[0] != '\0')
+                apply_ibus_engine (manager, engine);
+        else
+                g_settings_set_string (manager->priv->interface_settings,
+                                       KEY_GTK_IM_MODULE,
+                                       GTK_IM_MODULE_SIMPLE);
+#endif
 }
 
 static void
@@ -472,6 +517,11 @@ start_keyboard_idle_cb (GsdKeyboardManager *manager)
         manager->priv->is_settings = g_settings_new (GNOME_DESKTOP_INPUT_SOURCES_DIR);
         manager->priv->ignore_serial = XLastKnownRequestProcessed (display) - 1;
 
+#ifdef HAVE_IBUS
+        ibus_init ();
+        manager->priv->interface_settings = g_settings_new (GNOME_DESKTOP_INTERFACE_DIR);
+#endif
+
         /* apply current settings before we install the callback */
         apply_settings (manager->priv->settings, NULL, manager);
         apply_input_sources_settings (manager->priv->is_settings, NULL, manager);
@@ -524,6 +574,12 @@ gsd_keyboard_manager_stop (GsdKeyboardManager *manager)
                 g_object_unref (p->is_settings);
                 p->is_settings = NULL;
         }
+#ifdef HAVE_IBUS
+        if (p->interface_settings != NULL) {
+                g_object_unref (p->interface_settings);
+                p->interface_settings = NULL;
+        }
+#endif
 
         if (p->device_manager != NULL) {
                 g_signal_handler_disconnect (p->device_manager, p->device_added_id);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]