Commit fbdac0e6 authored by Rui Matos's avatar Rui Matos

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.
parent d1301233
......@@ -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}
......
......@@ -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
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment