0318d1
From 5136e4136e38271da195da76e1377308dbc2ed64 Mon Sep 17 00:00:00 2001
63b857
From: fujiwarat <takao.fujiwara1@gmail.com>
0318d1
Date: Fri, 12 Aug 2011 16:42:52 +0900
63b857
Subject: [PATCH] Add a bridge hotkey which use prev-next engines instead
63b857
 of on-off.
63b857
63b857
---
095f9c
 bus/Makefile.am                 |   20 +-
0318d1
 bus/ibusimpl.c                  |  501 ++++++++++++++++++++++++++++++++++-----
0318d1
 bus/inputcontext.c              |   39 +++
095f9c
 bus/inputcontext.h              |   22 ++
0318d1
 bus/registry.c                  |   61 +++++
0318d1
 bus/registry.h                  |   10 +
095f9c
 configure.ac                    |   31 +++
095f9c
 data/Makefile.am                |    6 +-
0318d1
 data/ibus.schemas.in            |  287 ----------------------
0318d1
 data/ibus.schemas.in.in         |  300 +++++++++++++++++++++++
095f9c
 ibus/_config.py.in              |    6 +
0318d1
 ibus/inputcontext.py            |   14 +-
095f9c
 ibus/interface/iinputcontext.py |    4 +-
095f9c
 ibus/xkbxml.py.in               |    4 +
095f9c
 setup/enginecombobox.py         |    3 +
0318d1
 setup/enginetreeview.py         |    8 +-
0318d1
 setup/main.py                   |   24 ++
095f9c
 setup/setup.ui                  |   55 +++++-
095f9c
 src/Makefile.am                 |   18 +-
095f9c
 src/ibushotkey.c                |   11 +
095f9c
 src/ibushotkey.h                |   11 +
095f9c
 src/ibusutil.c                  |   12 +
0318d1
 src/ibusutil.h                  |   14 +
0318d1
 ui/gtk/panel.py                 |  271 ++++++++++++++++++++--
095f9c
 xkb/Makefile.am                 |    2 +
0318d1
 xkb/ibus-engine-xkb-main.c      |   19 ++
095f9c
 xkb/xkbxml.c                    |   10 +-
0318d1
 28 files changed, 1374 insertions(+), 391 deletions(-)
63b857
 delete mode 100644 data/ibus.schemas.in
63b857
 create mode 100644 data/ibus.schemas.in.in
63b857
63b857
diff --git a/bus/Makefile.am b/bus/Makefile.am
095f9c
index 074b456..0efaa1b 100644
63b857
--- a/bus/Makefile.am
63b857
+++ b/bus/Makefile.am
63b857
@@ -29,15 +29,17 @@ INCLUDES =                \
63b857
 	-I$(top_builddir)/src \
63b857
 	$(NULL)
63b857
 
63b857
-AM_CFLAGS =                        \
63b857
-	@GLIB2_CFLAGS@                 \
63b857
-	@GIO2_CFLAGS@                  \
63b857
-	@GTHREAD2_CFLAGS@              \
63b857
-	-DG_LOG_DOMAIN=\"IBUS\"        \
63b857
-	-DPKGDATADIR=\"$(pkgdatadir)\" \
63b857
-	-DLIBEXECDIR=\"$(libexecdir)\" \
63b857
-	-DBINDIR=\"@bindir@\"          \
63b857
-	$(INCLUDES)                    \
63b857
+AM_CFLAGS =                                                            \
63b857
+	@GLIB2_CFLAGS@                                                 \
63b857
+	@GIO2_CFLAGS@                                                  \
63b857
+	@GTHREAD2_CFLAGS@                                              \
63b857
+	-DG_LOG_DOMAIN=\"IBUS\"                                        \
63b857
+	-DPKGDATADIR=\"$(pkgdatadir)\"                                 \
63b857
+	-DLIBEXECDIR=\"$(libexecdir)\"                                 \
63b857
+	-DBINDIR=\"@bindir@\"                                          \
63b857
+	-DUSE_BRIDGE_HOTKEY=$(USE_BRIDGE_HOTKEY)                       \
63b857
+	-DDEFAULT_BRIDGE_ENGINE_NAME=\"$(DEFAULT_BRIDGE_ENGINE_NAME)\" \
63b857
+	$(INCLUDES)                                                    \
63b857
 	$(NULL)
63b857
 AM_LDADD =                  \
63b857
 	@GOBJECT2_LIBS@         \
63b857
diff --git a/bus/ibusimpl.c b/bus/ibusimpl.c
0318d1
index 853465c..00864ac 100644
63b857
--- a/bus/ibusimpl.c
63b857
+++ b/bus/ibusimpl.c
095f9c
@@ -20,12 +20,17 @@
63b857
  * Boston, MA 02111-1307, USA.
63b857
  */
63b857
 
63b857
+#ifdef HAVE_CONFIG_H
63b857
+#include <config.h>
63b857
+#endif
63b857
+
63b857
 #include <unistd.h>
63b857
 #include <sys types.h="">
63b857
 #include <sys wait.h="">
095f9c
 #include <signal.h>
095f9c
 #include <locale.h>
095f9c
 #include <strings.h>
095f9c
+#include <string.h>
095f9c
 #include "types.h"
095f9c
 #include "ibusimpl.h"
095f9c
 #include "dbusimpl.h"
095f9c
@@ -79,6 +84,10 @@ struct _BusIBusImpl {
63b857
     /* engine-specific hotkeys */
63b857
     IBusHotkeyProfile *engines_hotkey_profile;
63b857
     GHashTable      *hotkey_to_engines_map;
63b857
+
47affb
+#if USE_BRIDGE_HOTKEY
63b857
+    IBusEngineDesc *prev_hotkey_engine;
47affb
+#endif
63b857
 };
63b857
 
63b857
 struct _BusIBusImplClass {
095f9c
@@ -99,6 +108,8 @@ enum {
b4e3b4
 static guint            _signals[LAST_SIGNAL] = { 0 };
b4e3b4
 */
b4e3b4
 
b4e3b4
+static gchar           *_bridge_trigger_keys = NULL;
b4e3b4
+
b4e3b4
 /* functions prototype */
b4e3b4
 static void      bus_ibus_impl_destroy           (BusIBusImpl        *ibus);
b4e3b4
 static void      bus_ibus_impl_service_method_call
0318d1
@@ -285,6 +296,112 @@ _panel_destroy_cb (BusPanelProxy *panel,
63b857
     g_object_unref (panel);
63b857
 }
63b857
 
0318d1
+/**
0318d1
+ * _foreach_remove_engine_hotkey:
0318d1
+ *
0318d1
+ * Remove the engine-specific hot key of the engine, and update ibus->engines_hotkey_profile.
0318d1
+ */
0318d1
+gboolean
0318d1
+_foreach_remove_engine_hotkey (gpointer        key,
0318d1
+                               gpointer        value,
0318d1
+                               gpointer        data)
63b857
+{
0318d1
+    GQuark event = GPOINTER_TO_UINT (value);
0318d1
+    struct _impl_and_desc {
0318d1
+        BusIBusImpl    *ibus;
0318d1
+        IBusEngineDesc *desc;
0318d1
+    } *id = (struct _impl_and_desc *) data;
0318d1
+    BusIBusImpl *ibus = id->ibus;
0318d1
+    IBusEngineDesc *desc = id->desc;
0318d1
+    GList *engine_list;
63b857
+
0318d1
+    g_assert (ibus != NULL);
0318d1
+    g_assert (desc != NULL);
0318d1
+
0318d1
+    if (event == 0) {
0318d1
+        return FALSE;
63b857
+    }
63b857
+
0318d1
+    engine_list = g_hash_table_lookup (ibus->hotkey_to_engines_map,
0318d1
+                                       GUINT_TO_POINTER (event));
0318d1
+
0318d1
+    /* As we will rebuild the engines hotkey map whenever an engine was
0318d1
+     * added or removed, we don't need to hold a reference of the engine
0318d1
+     * here. */
0318d1
+    if (engine_list && g_list_find (engine_list, desc) != NULL) {
0318d1
+        engine_list = g_list_remove (engine_list, desc);
63b857
+    }
63b857
+
0318d1
+    /* We need to steal the value before adding it back, otherwise it will
0318d1
+     * be destroyed. */
0318d1
+    g_hash_table_steal (ibus->hotkey_to_engines_map, GUINT_TO_POINTER (event));
0318d1
+
0318d1
+    if (engine_list != NULL) {
0318d1
+        g_hash_table_insert (ibus->hotkey_to_engines_map,
0318d1
+                             GUINT_TO_POINTER (event), engine_list);
0318d1
+    }
0318d1
+
0318d1
+    return FALSE;
0318d1
+}
0318d1
+
0318d1
+/**
0318d1
+ * _add_engine_hotkey_with_hotkeys:
0318d1
+ *
0318d1
+ * Check the engine-specific hot key of the engine, and update ibus->engines_hotkey_profile.
0318d1
+ */
0318d1
+static void
0318d1
+_add_engine_hotkey_with_hotkeys (IBusEngineDesc *engine,
0318d1
+                                 BusIBusImpl    *ibus,
0318d1
+                                 const gchar    *hotkeys)
0318d1
+{
0318d1
+    gchar **hotkey_list;
0318d1
+    gchar **p;
0318d1
+    gchar *hotkey;
0318d1
+    GList *engine_list;
0318d1
+
0318d1
+    GQuark event;
0318d1
+    guint keyval;
0318d1
+    guint modifiers;
0318d1
+
0318d1
+    g_assert (engine != NULL);
0318d1
+    g_assert (hotkeys && *hotkeys);
0318d1
+
0318d1
+    hotkey_list = g_strsplit_set (hotkeys, ";,", 0);
0318d1
+
0318d1
+    for (p = hotkey_list; p && *p; ++p) {
0318d1
+        hotkey = g_strstrip (*p);
0318d1
+        if (!*hotkey || !ibus_key_event_from_string (hotkey, &keyval, &modifiers)) {
0318d1
+            continue;
0318d1
+        }
0318d1
+
0318d1
+        /* If the hotkey already exists, we won't need to add it again. */
0318d1
+        event = ibus_hotkey_profile_lookup_hotkey (ibus->engines_hotkey_profile,
0318d1
+                                                   keyval, modifiers);
0318d1
+        if (event == 0) {
0318d1
+            event = g_quark_from_string (hotkey);
0318d1
+            ibus_hotkey_profile_add_hotkey (ibus->engines_hotkey_profile,
0318d1
+                                            keyval, modifiers, event);
0318d1
+        }
0318d1
+
0318d1
+        engine_list = g_hash_table_lookup (ibus->hotkey_to_engines_map,
0318d1
+                                           GUINT_TO_POINTER (event));
0318d1
+
0318d1
+        /* As we will rebuild the engines hotkey map whenever an engine was
0318d1
+         * added or removed, we don't need to hold a reference of the engine
0318d1
+         * here. */
0318d1
+        engine_list = g_list_append (engine_list, engine);
0318d1
+
0318d1
+        /* We need to steal the value before adding it back, otherwise it will
0318d1
+         * be destroyed. */
0318d1
+        g_hash_table_steal (ibus->hotkey_to_engines_map, GUINT_TO_POINTER (event));
0318d1
+
0318d1
+        g_hash_table_insert (ibus->hotkey_to_engines_map,
0318d1
+                             GUINT_TO_POINTER (event), engine_list);
0318d1
+    }
0318d1
+
0318d1
+    g_strfreev (hotkey_list);
63b857
+}
63b857
+
63b857
 static void
63b857
 _config_set_value_done (GObject      *object,
63b857
                         GAsyncResult *res,
0318d1
@@ -562,6 +679,67 @@ bus_ibus_impl_set_hotkey (BusIBusImpl *i
b4e3b4
 
b4e3b4
 }
b4e3b4
 
b4e3b4
+#if USE_BRIDGE_HOTKEY
095f9c
+static gboolean
095f9c
+use_bridge_hotkey (BusIBusImpl *ibus)
095f9c
+{
095f9c
+    GVariant *variant = NULL;
095f9c
+    gboolean _use_bridge_hotkey = TRUE;
095f9c
+
095f9c
+    g_assert (ibus != NULL);
095f9c
+
095f9c
+    if (!ibus->config) {
095f9c
+        return TRUE;
095f9c
+    }
095f9c
+
095f9c
+    variant = ibus_config_get_value (ibus->config,
095f9c
+                                     "general/hotkey",
095f9c
+                                     "use_bridge_hotkey");
095f9c
+
095f9c
+    if (variant != NULL) {
095f9c
+        g_variant_get (variant, "b", &_use_bridge_hotkey);
095f9c
+        g_variant_unref (variant);
095f9c
+    }
095f9c
+
095f9c
+    return _use_bridge_hotkey;
095f9c
+}
095f9c
+
b4e3b4
+static void
b4e3b4
+bus_ibus_impl_set_bridge_trigger_keys (BusIBusImpl *ibus,
b4e3b4
+                                       GQuark       hotkey,
b4e3b4
+                                       GVariant    *value)
b4e3b4
+{
b4e3b4
+    g_assert (BUS_IS_IBUS_IMPL (ibus));
b4e3b4
+
b4e3b4
+    ibus_hotkey_profile_remove_hotkey_by_event (ibus->hotkey_profile, hotkey);
b4e3b4
+
b4e3b4
+    if (value == NULL) {
b4e3b4
+        return;
b4e3b4
+    }
b4e3b4
+
b4e3b4
+    GVariantIter iter;
b4e3b4
+    g_variant_iter_init (&iter, value);
b4e3b4
+    const gchar *str = NULL;
b4e3b4
+
b4e3b4
+    g_free (_bridge_trigger_keys);
b4e3b4
+    _bridge_trigger_keys = NULL;
b4e3b4
+
b4e3b4
+    while (g_variant_iter_loop (&iter,"&s", &str)) {
b4e3b4
+       if (str != NULL) {
b4e3b4
+           gchar *tmp =NULL;
b4e3b4
+
b4e3b4
+           if (_bridge_trigger_keys) {
b4e3b4
+               tmp = g_strdup_printf ("%s,%s", _bridge_trigger_keys, str);
b4e3b4
+           } else {
b4e3b4
+               tmp = g_strdup (str);
b4e3b4
+           }
b4e3b4
+           g_free (_bridge_trigger_keys);
b4e3b4
+           _bridge_trigger_keys = tmp;
b4e3b4
+       }
b4e3b4
+    }
b4e3b4
+}
b4e3b4
+#endif
b4e3b4
+
b4e3b4
 /**
b4e3b4
  * bus_ibus_impl_set_trigger:
b4e3b4
  *
0318d1
@@ -573,7 +751,15 @@ bus_ibus_impl_set_trigger (BusIBusImpl *
577a98
 {
577a98
     GQuark hotkey = g_quark_from_static_string ("trigger");
577a98
     if (value != NULL) {
b4e3b4
+#if USE_BRIDGE_HOTKEY
095f9c
+        if (use_bridge_hotkey (ibus)) {
095f9c
+            bus_ibus_impl_set_bridge_trigger_keys (ibus, hotkey, value);
095f9c
+        } else {
095f9c
+            bus_ibus_impl_set_hotkey (ibus, hotkey, value);
095f9c
+        }
b4e3b4
+#else
577a98
         bus_ibus_impl_set_hotkey (ibus, hotkey, value);
577a98
+#endif
577a98
     }
577a98
 #ifndef OS_CHROMEOS
577a98
     else {
0318d1
@@ -639,6 +825,72 @@ bus_ibus_impl_set_previous_engine (BusIB
0318d1
     bus_ibus_impl_set_hotkey (ibus, hotkey, value);
63b857
 }
63b857
 
0318d1
+#if USE_BRIDGE_HOTKEY
0318d1
+static gint
0318d1
+_engine_desc_name_cmp (IBusEngineDesc *desc1,
0318d1
+                       IBusEngineDesc *desc2)
63b857
+{
0318d1
+    return g_strcmp0 (ibus_engine_desc_get_name (desc1),
0318d1
+                      ibus_engine_desc_get_name (desc2));
63b857
+}
63b857
+
63b857
+static void
0318d1
+_set_register_engines (BusIBusImpl *ibus,
0318d1
+                       GVariant    *value)
63b857
+{
0318d1
+    GList *engine_list = NULL;
63b857
+
0318d1
+    g_assert (BUS_IS_IBUS_IMPL (ibus));
63b857
+
0318d1
+    engine_list = ibus->register_engine_list;
0318d1
+    if (value != NULL && g_variant_classify (value) == G_VARIANT_CLASS_ARRAY) {
0318d1
+        GVariantIter iter;
0318d1
+        g_variant_iter_init (&iter, value);
0318d1
+        const gchar *engine_name = NULL;
0318d1
+        while (g_variant_iter_loop (&iter, "&s", &engine_name)) {
0318d1
+            IBusEngineDesc *engine = bus_registry_find_engine_by_name (ibus->registry, engine_name);
0318d1
+            if (engine == NULL || g_list_find (engine_list, engine) != NULL)
0318d1
+                continue;
0318d1
+            engine_list = g_list_append (engine_list, g_object_ref (engine));
63b857
+        }
0318d1
+    } else if (value != NULL) {
0318d1
+        g_variant_unref (value);
0318d1
+    }
63b857
+
0318d1
+    ibus->register_engine_list = engine_list;
0318d1
+
0318d1
+    if (engine_list) {
0318d1
+        BusComponent *component = bus_component_from_engine_desc ((IBusEngineDesc *) engine_list->data);
0318d1
+        if (component && !bus_component_is_running (component)) {
0318d1
+            bus_component_start (component, g_verbose);
63b857
+        }
0318d1
+    }
0318d1
+}
63b857
+
0318d1
+static void
0318d1
+_set_default_keyboard_layout_engines (BusIBusImpl *ibus)
0318d1
+{
0318d1
+    GList *engines = NULL;
0318d1
+    GList *list;
0318d1
+    GVariantBuilder builder;
63b857
+
0318d1
+    g_assert (BUS_IS_IBUS_IMPL (ibus));
63b857
+
0318d1
+    engines = bus_registry_get_engines_by_name_prefix (ibus->registry,
0318d1
+                                                       DEFAULT_BRIDGE_ENGINE_NAME);
0318d1
+    /* sort engines by rank */
0318d1
+    engines = g_list_sort (engines, (GCompareFunc) _engine_desc_name_cmp);
63b857
+
0318d1
+    g_variant_builder_init (&builder, G_VARIANT_TYPE ("as"));
0318d1
+    for (list = engines; list != NULL; list = list->next) {
0318d1
+        IBusEngineDesc *desc = (IBusEngineDesc *)list->data;
0318d1
+        g_variant_builder_add (&builder, "s", ibus_engine_desc_get_name (desc));
63b857
+    }
0318d1
+    _set_register_engines (ibus, g_variant_builder_end (&builder));
0318d1
+    g_list_free (engines);
0318d1
+}
0318d1
+#endif
63b857
+
63b857
 /**
0318d1
  * bus_ibus_impl_set_preload_engines:
0318d1
  *
0318d1
@@ -658,6 +910,9 @@ bus_ibus_impl_set_preload_engines (BusIB
0318d1
             _set_preload_engines (ibus, value);
0318d1
         }
0318d1
     }
0318d1
+#if USE_BRIDGE_HOTKEY
0318d1
+    _set_default_keyboard_layout_engines (ibus);
0318d1
+#endif
0318d1
 #else
0318d1
     _set_preload_engines (ibus, value);
0318d1
 #endif
0318d1
@@ -1216,7 +1471,71 @@ _context_request_engine_cb (BusInputCont
63b857
                             const gchar     *engine_name,
63b857
                             BusIBusImpl     *ibus)
63b857
 {
63b857
-    return bus_ibus_impl_get_engine_desc (ibus, engine_name);
63b857
+    IBusEngineDesc *desc = bus_ibus_impl_get_engine_desc (ibus, engine_name);
63b857
+    struct _impl_and_desc {
63b857
+        BusIBusImpl    *ibus;
63b857
+        IBusEngineDesc *desc;
63b857
+    } id = {ibus, desc};
63b857
+
63b857
+#if USE_BRIDGE_HOTKEY
63b857
+    IBusEngineDesc *current_desc = NULL;
b4e3b4
+
095f9c
+    if (!use_bridge_hotkey (ibus)) {
095f9c
+        return desc;
095f9c
+    }
095f9c
+
63b857
+    if (context) {
63b857
+        BusEngineProxy *engine = bus_input_context_get_engine (context);
63b857
+        if (engine != NULL) {
63b857
+            current_desc = bus_engine_proxy_get_desc (engine);
63b857
+        }
63b857
+    }
b4e3b4
+
63b857
+    if (current_desc) {
095f9c
+        if (context) {
095f9c
+            bus_input_context_set_prev_hotkey_engine (context, current_desc);
095f9c
+        } else {
095f9c
+            ibus->prev_hotkey_engine = current_desc;
095f9c
+        }
63b857
+    }
b4e3b4
+
095f9c
+    if (((current_desc == NULL && desc != NULL) ||
095f9c
+         (current_desc != NULL && desc != NULL &&
095f9c
+          g_strcmp0 (ibus_engine_desc_get_name (current_desc),
095f9c
+                     ibus_engine_desc_get_name (desc)) != 0)) &&
095f9c
+        g_ascii_strncasecmp (ibus_engine_desc_get_name (desc),
095f9c
+                             DEFAULT_BRIDGE_ENGINE_NAME,
095f9c
+                             strlen (DEFAULT_BRIDGE_ENGINE_NAME)) == 0) {
b4e3b4
+        const gchar *hotkeys = NULL;
b4e3b4
+
b4e3b4
+        /* If the user customized the trigger key, the trigger key is used for
b4e3b4
+         * any IBus engines. */
b4e3b4
+        if (_bridge_trigger_keys != NULL &&
b4e3b4
+            *_bridge_trigger_keys != '\0' &&
b4e3b4
+            g_strcmp0 (_bridge_trigger_keys, "Control+space") != 0) {
b4e3b4
+
b4e3b4
+            hotkeys = (const gchar *) _bridge_trigger_keys;
095f9c
+        } else if (current_desc) {
b4e3b4
+            hotkeys = ibus_engine_desc_get_hotkeys (current_desc);
b4e3b4
+        }
b4e3b4
+
095f9c
+        /* If engine hotkeys are not defined in the compose xml file,
095f9c
+         * IBus trigger keys are used. */
63b857
+        if (!hotkeys || !*hotkeys) {
b4e3b4
+            hotkeys = (const gchar *) _bridge_trigger_keys;
b4e3b4
+        }
b4e3b4
+
b4e3b4
+        if (!hotkeys || !*hotkeys) {
b4e3b4
+            return desc;
63b857
+        }
b4e3b4
+
63b857
+        ibus_hotkey_profile_foreach_hotkey (ibus->engines_hotkey_profile,
63b857
+                                            _foreach_remove_engine_hotkey,
63b857
+                                            &id);
63b857
+        _add_engine_hotkey_with_hotkeys (desc, ibus, hotkeys);
63b857
+    }
63b857
+#endif
63b857
+    return desc;
63b857
 }
63b857
 
63b857
 /**
0318d1
@@ -1255,8 +1574,13 @@ bus_ibus_impl_get_engine_desc (BusIBusIm
0318d1
         if (!desc) {
0318d1
             if (ibus->register_engine_list) {
0318d1
                 desc = (IBusEngineDesc *) ibus->register_engine_list->data;
0318d1
+#if USE_BRIDGE_HOTKEY
0318d1
+                if (engine_name == NULL) {
0318d1
+                    desc = NULL;
0318d1
+                }
0318d1
+#endif
0318d1
             }
0318d1
-            else if (ibus->engine_list) {
0318d1
+            if (!desc && ibus->engine_list) {
0318d1
                 desc = (IBusEngineDesc *) ibus->engine_list->data;
0318d1
             }
0318d1
         }
ed173d
@@ -1407,6 +1731,9 @@ bus_ibus_impl_set_focused_context (BusIBusImpl     *ibus,
ed173d
 
ed173d
     BusEngineProxy *engine = NULL;
ed173d
     gboolean is_enabled = FALSE;
ed173d
+#if USE_BRIDGE_HOTKEY
ed173d
+    IBusEngineDesc *desc = NULL;
ed173d
+#endif
ed173d
 
ed173d
     if (ibus->focused_context) {
ed173d
         if (ibus->use_global_engine) {
ed173d
@@ -1336,6 +1741,9 @@ bus_ibus_impl_set_focused_context (BusIBusImpl     *ibus,
ed173d
             engine = bus_input_context_get_engine (ibus->focused_context);
ed173d
             if (engine) {
ed173d
                 is_enabled = bus_input_context_is_enabled (ibus->focused_context);
ed173d
+#if USE_BRIDGE_HOTKEY
ed173d
+                desc = bus_input_context_get_prev_hotkey_engine (ibus->focused_context);
ed173d
+#endif
ed173d
                 g_object_ref (engine);
ed173d
                 bus_input_context_set_engine (ibus->focused_context, NULL);
ed173d
             }
ed173d
@@ -1360,6 +1768,9 @@ bus_ibus_impl_set_focused_context (BusIBusImpl     *ibus,
ed173d
             if (is_enabled) {
ed173d
                 bus_input_context_enable (context);
ed173d
             }
ed173d
+#if USE_BRIDGE_HOTKEY
ed173d
+            bus_input_context_set_prev_hotkey_engine (ibus->focused_context, desc);
ed173d
+#endif
ed173d
             g_object_unref (engine);
ed173d
         }
ed173d
 
0318d1
@@ -2267,6 +2591,9 @@ bus_ibus_impl_filter_keyboard_shortcuts 
095f9c
 
095f9c
     GQuark event;
095f9c
     GList *engine_list;
095f9c
+#if USE_BRIDGE_HOTKEY
095f9c
+    IBusEngineDesc *prev_hotkey_engine = NULL;
095f9c
+#endif
095f9c
 
095f9c
     if (trigger == 0) {
095f9c
         trigger = g_quark_from_static_string ("trigger");
0318d1
@@ -2331,6 +2658,12 @@ bus_ibus_impl_filter_keyboard_shortcuts 
095f9c
         return FALSE;
095f9c
     }
095f9c
 
095f9c
+#if USE_BRIDGE_HOTKEY
095f9c
+    if (!use_bridge_hotkey (ibus)) {
095f9c
+        return FALSE;
095f9c
+    }
095f9c
+#endif
095f9c
+
095f9c
     /* Then try engines hotkeys. */
095f9c
     event = ibus_hotkey_profile_filter_key_event (ibus->engines_hotkey_profile,
095f9c
                                                   keyval,
0318d1
@@ -2352,6 +2685,24 @@ bus_ibus_impl_filter_keyboard_shortcuts 
b4e3b4
 
b4e3b4
         g_assert (new_engine_desc);
b4e3b4
 
63b857
+#if USE_BRIDGE_HOTKEY
095f9c
+        if (context) {
095f9c
+            prev_hotkey_engine = bus_input_context_get_prev_hotkey_engine (context);
095f9c
+            if (prev_hotkey_engine == NULL && ibus->prev_hotkey_engine) {
095f9c
+                prev_hotkey_engine = ibus->prev_hotkey_engine;
095f9c
+                bus_input_context_set_prev_hotkey_engine (context,
095f9c
+                                                          prev_hotkey_engine);
095f9c
+            }
095f9c
+        }
095f9c
+
b4e3b4
+        /* If the previous engine is not included in engine_list,
b4e3b4
+         * this enables a new engine instead of toggling the engines
b4e3b4
+         * so should not enable the previous engine. */
095f9c
+        if (prev_hotkey_engine &&
095f9c
+            g_list_find (engine_list, prev_hotkey_engine) != NULL) {
095f9c
+            new_engine_desc = prev_hotkey_engine;
63b857
+        }
63b857
+#else
b4e3b4
         /* Find out what engine we should switch to. If the current engine has
b4e3b4
          * the same hotkey, then we should switch to the next engine with the
b4e3b4
          * same hotkey in the list. Otherwise, we just switch to the first
0318d1
@@ -2363,8 +2714,47 @@ bus_ibus_impl_filter_keyboard_shortcuts 
63b857
                 break;
63b857
             }
63b857
         }
63b857
+#endif
095f9c
+
47affb
+#if USE_BRIDGE_HOTKEY
095f9c
+        if (context == NULL) {
095f9c
+            return FALSE;
095f9c
+        }
0318d1
 
095f9c
+        /* This means RequestEngine signal might be done but SetEngine signal
095f9c
+         * has not been done yet by ibus status icon. */
095f9c
+        if (current_engine_desc == NULL &&
095f9c
+            !bus_input_context_inited_engine (context)) {
095f9c
+            return FALSE;
095f9c
+        }
b4e3b4
+
095f9c
+        if (current_engine_desc != new_engine_desc) {
095f9c
+            if (current_engine_desc) {
095f9c
+                if (context) {
095f9c
+                    bus_input_context_set_prev_hotkey_engine (context,
095f9c
+                                                              current_engine_desc);
095f9c
+                }
095f9c
+            }
0318d1
+
b4e3b4
+            /* If the previous engine is not included in engine_list and
b4e3b4
+             * the current engine is the defualt bridge engine,
b4e3b4
+             * the current engine is also not included in engine_list.
b4e3b4
+             * So the engine is added here. */
6cab06
+            if (current_engine_desc != NULL &&
6cab06
+                g_list_find (engine_list, current_engine_desc) == NULL &&
095f9c
+                g_ascii_strncasecmp (ibus_engine_desc_get_name (current_engine_desc),
095f9c
+                                     DEFAULT_BRIDGE_ENGINE_NAME,
095f9c
+                                     strlen (DEFAULT_BRIDGE_ENGINE_NAME)) == 0) {
b4e3b4
+                engine_list = g_list_append (engine_list, current_engine_desc);
b4e3b4
+
b4e3b4
+                g_hash_table_steal (ibus->hotkey_to_engines_map,
b4e3b4
+                                    GUINT_TO_POINTER (event));
b4e3b4
+                g_hash_table_insert (ibus->hotkey_to_engines_map,
b4e3b4
+                                     GUINT_TO_POINTER (event), engine_list);
b4e3b4
+            }
47affb
+#else
47affb
         if (current_engine_desc != new_engine_desc) {
47affb
+#endif
63b857
             bus_ibus_impl_set_context_engine_from_desc (ibus, context, new_engine_desc);
63b857
         }
63b857
 
0318d1
@@ -2468,59 +2858,54 @@ static void
63b857
 _add_engine_hotkey (IBusEngineDesc *engine, BusIBusImpl *ibus)
63b857
 {
63b857
     const gchar *hotkeys;
63b857
-    gchar **hotkey_list;
63b857
-    gchar **p;
63b857
-    gchar *hotkey;
63b857
-    GList *engine_list;
63b857
-
63b857
-    GQuark event;
63b857
-    guint keyval;
63b857
-    guint modifiers;
63b857
 
63b857
     if (!engine) {
63b857
         return;
63b857
     }
63b857
 
095f9c
-    hotkeys = ibus_engine_desc_get_hotkeys (engine);
095f9c
-
095f9c
-    if (!hotkeys || !*hotkeys) {
b4e3b4
+#if USE_BRIDGE_HOTKEY
095f9c
+    if (!use_bridge_hotkey (ibus)) {
095f9c
         return;
b4e3b4
     }
b4e3b4
 
63b857
-    hotkey_list = g_strsplit_set (hotkeys, ";,", 0);
63b857
-
63b857
-    for (p = hotkey_list; p && *p; ++p) {
63b857
-        hotkey = g_strstrip (*p);
63b857
-        if (!*hotkey || !ibus_key_event_from_string (hotkey, &keyval, &modifiers)) {
63b857
-            continue;
63b857
-        }
63b857
-
63b857
-        /* If the hotkey already exists, we won't need to add it again. */
63b857
-        event = ibus_hotkey_profile_lookup_hotkey (ibus->engines_hotkey_profile,
63b857
-                                                   keyval, modifiers);
63b857
-        if (event == 0) {
63b857
-            event = g_quark_from_string (hotkey);
63b857
-            ibus_hotkey_profile_add_hotkey (ibus->engines_hotkey_profile,
63b857
-                                            keyval, modifiers, event);
63b857
-        }
095f9c
+    /* Do not register hotkeys for the default keymap engines
095f9c
+     * but register hotkeys for only input-method engines
095f9c
+     * in 'RegisterComponent' dbus method.
095f9c
+     * The hotkeys for an activated keymap engine will be registered
095f9c
+     * in 'SetEngine' dbus method. */
095f9c
+    if (g_ascii_strncasecmp (ibus_engine_desc_get_name (engine),
095f9c
+                             DEFAULT_BRIDGE_ENGINE_NAME,
095f9c
+                             strlen (DEFAULT_BRIDGE_ENGINE_NAME)) == 0) {
095f9c
+        return;
095f9c
+    }
095f9c
 
63b857
-        engine_list = g_hash_table_lookup (ibus->hotkey_to_engines_map,
63b857
-                                           GUINT_TO_POINTER (event));
095f9c
+    /* If the user customized the trigger key, the trigger key is used for
095f9c
+     * any IBus engines. */
095f9c
+    if (_bridge_trigger_keys != NULL &&
095f9c
+        *_bridge_trigger_keys != '\0' &&
095f9c
+        g_strcmp0 (_bridge_trigger_keys, "Control+space") != 0) {
095f9c
 
63b857
-        /* As we will rebuild the engines hotkey map whenever an engine was
63b857
-         * added or removed, we don't need to hold a reference of the engine
63b857
-         * here. */
63b857
-        engine_list = g_list_append (engine_list, engine);
095f9c
+        hotkeys = (const gchar *) _bridge_trigger_keys;
095f9c
+    } else {
095f9c
+        hotkeys = ibus_engine_desc_get_hotkeys (engine);
095f9c
+    }
095f9c
+#else
095f9c
+    hotkeys = ibus_engine_desc_get_hotkeys (engine);
095f9c
+#endif
095f9c
 
63b857
-        /* We need to steal the value before adding it back, otherwise it will
63b857
-         * be destroyed. */
63b857
-        g_hash_table_steal (ibus->hotkey_to_engines_map, GUINT_TO_POINTER (event));
095f9c
+#if USE_BRIDGE_HOTKEY
095f9c
+    /* If engine hotkeys are not defined in the compose xml file, IBus trigger
095f9c
+     * keys are used. */
095f9c
+    if (!hotkeys || !*hotkeys) {
095f9c
+        hotkeys = (const gchar *) _bridge_trigger_keys;
095f9c
+    }
095f9c
+#endif
095f9c
 
63b857
-        g_hash_table_insert (ibus->hotkey_to_engines_map,
63b857
-                             GUINT_TO_POINTER (event), engine_list);
b4e3b4
+    if (!hotkeys || !*hotkeys) {
b4e3b4
+        return;
b4e3b4
     }
b4e3b4
 
63b857
-    g_strfreev (hotkey_list);
63b857
+    _add_engine_hotkey_with_hotkeys (engine, ibus, hotkeys);
63b857
 }
63b857
 
63b857
 /**
095f9c
diff --git a/bus/inputcontext.c b/bus/inputcontext.c
095f9c
index 4e8cdc5..43dedc0 100644
095f9c
--- a/bus/inputcontext.c
095f9c
+++ b/bus/inputcontext.c
095f9c
@@ -90,6 +90,12 @@ struct _BusInputContext {
095f9c
 
095f9c
     /* incompleted set engine by desc request */
095f9c
     SetEngineByDescData *data;
095f9c
+
095f9c
+    /* if init engine */
095f9c
+    gboolean inited_engine;
095f9c
+
095f9c
+    /* previous hotkey engine for bridge hotkey mode */
095f9c
+    IBusEngineDesc *prev_hotkey_engine;
095f9c
 };
095f9c
 
095f9c
 struct _BusInputContextClass {
095f9c
@@ -647,6 +653,11 @@ bus_input_context_destroy (BusInputContext *context)
095f9c
         context->client = NULL;
095f9c
     }
095f9c
 
095f9c
+    if (context->prev_hotkey_engine) {
095f9c
+        g_object_unref (context->prev_hotkey_engine);
095f9c
+        context->prev_hotkey_engine = NULL;
095f9c
+    }
095f9c
+
095f9c
     IBUS_OBJECT_CLASS (bus_input_context_parent_class)->destroy (IBUS_OBJECT (context));
095f9c
 }
095f9c
 
095f9c
@@ -2211,6 +2222,7 @@ bus_input_context_set_engine (BusInputContext *context,
095f9c
     }
095f9c
     else {
095f9c
         gint i;
095f9c
+        context->inited_engine = TRUE;
095f9c
         context->engine = engine;
095f9c
         g_object_ref (context->engine);
095f9c
 
095f9c
@@ -2538,3 +2550,30 @@ bus_input_context_get_client (BusInputContext *context)
095f9c
     g_assert (BUS_IS_INPUT_CONTEXT (context));
095f9c
     return context->client;
095f9c
 }
095f9c
+
095f9c
+gboolean
095f9c
+bus_input_context_inited_engine (BusInputContext *context)
095f9c
+{
095f9c
+    g_assert (BUS_IS_INPUT_CONTEXT (context));
095f9c
+    return context->inited_engine;
095f9c
+}
095f9c
+
095f9c
+IBusEngineDesc *
095f9c
+bus_input_context_get_prev_hotkey_engine (BusInputContext *context)
095f9c
+{
095f9c
+    g_assert (BUS_IS_INPUT_CONTEXT (context));
095f9c
+    return context->prev_hotkey_engine;
095f9c
+}
095f9c
+
095f9c
+void
095f9c
+bus_input_context_set_prev_hotkey_engine (BusInputContext *context,
095f9c
+                                          IBusEngineDesc  *desc)
095f9c
+{
095f9c
+    g_assert (BUS_IS_INPUT_CONTEXT (context));
095f9c
+    g_assert (desc == NULL || IBUS_IS_ENGINE_DESC (desc));
095f9c
+
095f9c
+    if (context->prev_hotkey_engine) {
095f9c
+        g_object_unref (context->prev_hotkey_engine);
095f9c
+    }
095f9c
+    context->prev_hotkey_engine = desc ? g_object_ref (desc) : NULL;
095f9c
+}
095f9c
diff --git a/bus/inputcontext.h b/bus/inputcontext.h
095f9c
index bc4e096..c79e033 100644
095f9c
--- a/bus/inputcontext.h
095f9c
+++ b/bus/inputcontext.h
095f9c
@@ -213,5 +213,27 @@ void                 bus_input_context_set_capabilities (BusInputContext    *con
095f9c
  */
095f9c
 const gchar         *bus_input_context_get_client       (BusInputContext    *context);
095f9c
 
095f9c
+/**
095f9c
+ * bus_input_context_inited_engine:
095f9c
+ * @returns: context->inited_engine.
095f9c
+ */
095f9c
+gboolean             bus_input_context_inited_engine
095f9c
+                                                        (BusInputContext *context);
095f9c
+
095f9c
+/**
095f9c
+ * bus_input_context_get_prev_hotkey_engine:
095f9c
+ * @returns: context->prev_hotkey_engine.
095f9c
+ */
095f9c
+IBusEngineDesc      *bus_input_context_get_prev_hotkey_engine
095f9c
+                                                        (BusInputContext *context);
095f9c
+
095f9c
+/**
095f9c
+ * bus_input_context_set_prev_hotkey_engine:
095f9c
+ * @desc: Assign the desc to context->prev_hotkey_engine.
095f9c
+ */
095f9c
+void                 bus_input_context_set_prev_hotkey_engine
095f9c
+                                                        (BusInputContext *context,
095f9c
+                                                         IBusEngineDesc  *desc);
095f9c
+
095f9c
 G_END_DECLS
095f9c
 #endif
63b857
diff --git a/bus/registry.c b/bus/registry.c
0318d1
index 7b74781..28e2abf 100644
63b857
--- a/bus/registry.c
63b857
+++ b/bus/registry.c
63b857
@@ -19,6 +19,11 @@
63b857
  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
63b857
  * Boston, MA 02111-1307, USA.
63b857
  */
63b857
+
63b857
+#ifdef HAVE_CONFIG_H
63b857
+#include <config.h>
63b857
+#endif
63b857
+
63b857
 #include "registry.h"
63b857
 #include <glib gstdio.h="">
63b857
 #include <gio gio.h="">
63b857
@@ -101,6 +106,9 @@ bus_registry_init (BusRegistry *registry)
63b857
     registry->observed_paths = NULL;
63b857
     registry->components = NULL;
63b857
     registry->engine_table = g_hash_table_new (g_str_hash, g_str_equal);
63b857
+#if USE_BRIDGE_HOTKEY
63b857
+    gboolean has_default_engine = FALSE;
63b857
+#endif
63b857
 
63b857
 #ifdef G_THREADS_ENABLED
63b857
     /* If glib supports thread, we'll create a thread to monitor changes in IME
095f9c
@@ -145,12 +153,40 @@ bus_registry_init (BusRegistry *registry)
63b857
         GList *p1;
63b857
         for (p1 = engines; p1 != NULL; p1 = p1->next) {
63b857
             IBusEngineDesc *desc = (IBusEngineDesc *) p1->data;
63b857
+#if USE_BRIDGE_HOTKEY
095f9c
+            if (g_ascii_strncasecmp (ibus_engine_desc_get_name (desc),
095f9c
+                                     DEFAULT_BRIDGE_ENGINE_NAME,
095f9c
+                                     strlen (DEFAULT_BRIDGE_ENGINE_NAME)) == 0) {
63b857
+                has_default_engine = TRUE;
63b857
+            }
63b857
+#endif
63b857
             g_hash_table_insert (registry->engine_table,
63b857
                                  (gpointer) ibus_engine_desc_get_name (desc),
63b857
                                  desc);
63b857
         }
63b857
         g_list_free (engines);
63b857
     }
63b857
+
63b857
+#if USE_BRIDGE_HOTKEY
63b857
+    if (has_default_engine == FALSE) {
63b857
+        bus_registry_remove_all (registry);
63b857
+        bus_registry_load (registry);
63b857
+        bus_registry_save_cache (registry);
63b857
+
63b857
+        for (p = registry->components; p != NULL; p = p->next) {
63b857
+            BusComponent *comp = (BusComponent *) p->data;
63b857
+            GList *engines = bus_component_get_engines (comp);
63b857
+            GList *p1;
63b857
+            for (p1 = engines; p1 != NULL; p1 = p1->next) {
63b857
+                IBusEngineDesc *desc = (IBusEngineDesc *) p1->data;
63b857
+                g_hash_table_insert (registry->engine_table,
63b857
+                                     (gpointer) ibus_engine_desc_get_name (desc),
63b857
+                                     desc);
63b857
+            }
63b857
+            g_list_free (engines);
63b857
+        }
63b857
+    }
63b857
+#endif
63b857
 }
63b857
 
63b857
 static void
0318d1
@@ -516,6 +552,31 @@ bus_registry_get_engines_by_language (BusRegistry *registry,
0318d1
     return engines;
0318d1
 }
0318d1
 
0318d1
+GList *
0318d1
+bus_registry_get_engines_by_name_prefix (BusRegistry *registry,
0318d1
+                                         const gchar *name_prefix)
0318d1
+{
0318d1
+    GList *p1, *p2;
0318d1
+    GList *engines = NULL;
0318d1
+
0318d1
+    g_assert (BUS_IS_REGISTRY (registry));
0318d1
+    g_assert (name_prefix);
0318d1
+
0318d1
+    p1 = bus_registry_get_engines (registry);
0318d1
+
0318d1
+    for (p2 = p1; p2 != NULL; p2 = p2->next) {
0318d1
+        IBusEngineDesc *desc = (IBusEngineDesc *) p2->data;
0318d1
+        if (g_ascii_strncasecmp (ibus_engine_desc_get_name (desc),
0318d1
+                                 name_prefix,
0318d1
+                                 strlen (name_prefix)) == 0) {
0318d1
+            engines = g_list_append (engines, desc);
0318d1
+        }
0318d1
+    }
0318d1
+
0318d1
+    g_list_free (p1);
0318d1
+    return engines;
0318d1
+}
0318d1
+
0318d1
 IBusEngineDesc *
0318d1
 bus_registry_find_engine_by_name (BusRegistry *registry,
0318d1
                                   const gchar *name)
0318d1
diff --git a/bus/registry.h b/bus/registry.h
0318d1
index cdabec0..721187c 100644
0318d1
--- a/bus/registry.h
0318d1
+++ b/bus/registry.h
0318d1
@@ -73,6 +73,16 @@ GList           *bus_registry_get_engines_by_language
0318d1
                                                  const gchar    *language);
0318d1
 
0318d1
 /**
0318d1
+ * bus_registry_get_engines_by_name_prefix:
0318d1
+ * @name_prefix: a prefix in the name of IBusEngineDesc. 
0318d1
+ * @returns: a list of IBusEngineDesc objects which has the name prefix.
0318d1
+ *           The caller has to call g_list_free for the returned list.
0318d1
+ */
0318d1
+GList           *bus_registry_get_engines_by_name_prefix
0318d1
+                                                (BusRegistry    *registry,
0318d1
+                                                 const gchar    *name_prefix);
0318d1
+
0318d1
+/**
0318d1
  * bus_registry_stop_all_components:
0318d1
  *
0318d1
  * Terminate all component processes.
63b857
diff --git a/configure.ac b/configure.ac
095f9c
index 4c20ae7..21d35c3 100644
63b857
--- a/configure.ac
63b857
+++ b/configure.ac
095f9c
@@ -456,6 +456,34 @@ else
63b857
     enable_surrounding_text="no (disabled, use --enable-surrounding-text to enable)"
63b857
 fi
63b857
 
63b857
+# option for bridge hotkey
63b857
+AC_ARG_ENABLE(bridge-hotkey,
63b857
+    AS_HELP_STRING([--enable-bridge-hotkey],
63b857
+        [Enable bridge hotkey instead of ON/OFF hotkey]),
63b857
+    [enable_bridge_hotkey=$enableval],
63b857
+    [enable_bridge_hotkey=no]
63b857
+)
63b857
+
63b857
+if test x"$enable_bridge_hotkey" = x"yes"; then
63b857
+    USE_BRIDGE_HOTKEY=1
b4e3b4
+    TRIGGER_HOTKEYS="Control+space"
63b857
+else
63b857
+    USE_BRIDGE_HOTKEY=0
63b857
+    TRIGGER_HOTKEYS="Control+space,Zenkaku_Hankaku,Alt+Kanji,Alt+grave,Hangul,Alt+Release+Alt_R"
63b857
+    enable_bridge_hotkey="no (disabled, use --enable-bridge-hotkey to enable)"
63b857
+fi
63b857
+AC_SUBST(USE_BRIDGE_HOTKEY)
63b857
+AC_SUBST(TRIGGER_HOTKEYS)
63b857
+
63b857
+# define default bridge engine name
63b857
+AC_ARG_WITH(bridge-engine,
63b857
+    AS_HELP_STRING([--with-bridge-engine[=bridge_engine_name]],
095f9c
+        [Set bridge engine name in IM bridge hotkey. (default: xkb:layout:default:)]),
63b857
+    [DEFAULT_BRIDGE_ENGINE_NAME=$with_bridge_engine],
095f9c
+    [DEFAULT_BRIDGE_ENGINE_NAME="xkb:layout:default:"]
63b857
+)
63b857
+AC_SUBST(DEFAULT_BRIDGE_ENGINE_NAME)
63b857
+
63b857
 # check iso-codes
63b857
 PKG_CHECK_MODULES(ISOCODES, [
63b857
     iso-codes
095f9c
@@ -482,6 +510,7 @@ bus/Makefile
63b857
 util/Makefile
63b857
 util/IMdkit/Makefile
63b857
 data/Makefile
63b857
+data/ibus.schemas.in
63b857
 data/icons/Makefile
63b857
 data/keymaps/Makefile
63b857
 docs/Makefile
095f9c
@@ -534,5 +563,7 @@ Build options:
63b857
   No snooper regexes        "$NO_SNOOPER_APPS"
63b857
   Panel icon                "$IBUS_ICON_KEYBOARD"
63b857
   Enable surrounding-text   $enable_surrounding_text
63b857
+  Enable bridge hotkey      $enable_bridge_hotkey
63b857
+  Default bridge engine     $DEFAULT_BRIDGE_ENGINE_NAME
63b857
 ])
63b857
 
63b857
diff --git a/data/Makefile.am b/data/Makefile.am
095f9c
index 99be41c..824da76 100644
63b857
--- a/data/Makefile.am
63b857
+++ b/data/Makefile.am
0318d1
@@ -26,7 +26,8 @@ SUBDIRS = \
63b857
 	$(NULL)
63b857
 
63b857
 schemasdir = $(GCONF_SCHEMA_FILE_DIR)
63b857
-schemas_in_files = ibus.schemas.in
63b857
+schemas_in_in_files = ibus.schemas.in.in
63b857
+schemas_in_files = $(schemas_in_in_files:.schemas.in.in=.schemas.in)
63b857
 schemas_DATA = $(schemas_in_files:.schemas.in=.schemas)
63b857
 @INTLTOOL_SCHEMAS_RULE@
63b857
 
0318d1
@@ -41,11 +42,12 @@ if GCONF_SCHEMAS_INSTALL
63b857
 endif
63b857
 
63b857
 EXTRA_DIST = \
63b857
-	$(schemas_in_files) \
63b857
+	$(schemas_in_in_files) \
63b857
 	$(NULL)
63b857
 
63b857
 DISTCLEANFILES = \
63b857
 	$(schemas_DATA) \
63b857
+	$(schemas_in_files) \
63b857
 	$(NULL)
63b857
 
63b857
 -include $(top_srcdir)/git.mk
63b857
diff --git a/data/ibus.schemas.in b/data/ibus.schemas.in.in
0318d1
index 8979515..2a2b459
63b857
--- a/data/ibus.schemas.in
63b857
+++ b/data/ibus.schemas.in.in
63b857
@@ -31,7 +31,7 @@
63b857
       <owner>ibus</owner>
63b857
       <type>list</type>
63b857
       <list_type>string</list_type>
63b857
-      <default>[Control+space,Zenkaku_Hankaku,Alt+Kanji,Alt+grave,Hangul,Alt+Release+Alt_R]</default>
63b857
+      <default>[@TRIGGER_HOTKEYS@]</default>
63b857
       <locale name="C">
63b857
         <short>Trigger shortcut keys</short>
63b857
 	    <long>The shortcut keys for turning input method on or off</long>
63b857
diff --git a/ibus/_config.py.in b/ibus/_config.py.in
63b857
index a830136..4c3c980 100644
63b857
--- a/ibus/_config.py.in
63b857
+++ b/ibus/_config.py.in
63b857
@@ -25,6 +25,8 @@ __all__ = (
63b857
     "get_copyright",
63b857
     "get_license",
63b857
     "get_ICON_KEYBOARD",
63b857
+    "use_bridge_hotkey",
63b857
+    "DEFAULT_BRIDGE_ENGINE_NAME",
63b857
     "ISOCODES_PREFIX",
63b857
     "_"
63b857
 )
63b857
@@ -51,4 +53,8 @@ def get_ICON_KEYBOARD():
63b857
         icon = 'ibus-keyboard'
63b857
     return icon
63b857
 
63b857
+def use_bridge_hotkey():
63b857
+    return True if @USE_BRIDGE_HOTKEY@ == 1 else False
63b857
+
63b857
+DEFAULT_BRIDGE_ENGINE_NAME='@DEFAULT_BRIDGE_ENGINE_NAME@'
63b857
 ISOCODES_PREFIX='@ISOCODES_PREFIX@'
63b857
diff --git a/ibus/inputcontext.py b/ibus/inputcontext.py
095f9c
index ceeb56d..b3c2f65 100644
63b857
--- a/ibus/inputcontext.py
63b857
+++ b/ibus/inputcontext.py
63b857
@@ -28,6 +28,7 @@ import sys
63b857
 import gobject
63b857
 import dbus
63b857
 import dbus.lowlevel
63b857
+import _config
63b857
 import object
63b857
 import common
63b857
 import serializable
095f9c
@@ -279,8 +280,19 @@ class InputContext(object.Object):
095f9c
         except:
095f9c
             return None
63b857
 
095f9c
+    def __handle_ic_reply(self):
095f9c
+        pass
095f9c
+
095f9c
+    def __handle_ic_error(self, e):
095f9c
+        print self.__gtype_name__, str(e)
095f9c
+
095f9c
     def set_engine(self, engine):
095f9c
-        return self.__context.SetEngine(engine.name)
095f9c
+        return self.__context.SetEngine(engine.name,
095f9c
+                                        reply_handler=self.__handle_ic_reply,
095f9c
+                                        error_handler=self.__handle_ic_error)
095f9c
+
63b857
+    def set_bridge_engine(self):
63b857
+        return self.__context.SetEngine(_config.DEFAULT_BRIDGE_ENGINE_NAME)
095f9c
 
63b857
     def introspect(self):
63b857
         return self.__context.Introspect()
095f9c
diff --git a/ibus/interface/iinputcontext.py b/ibus/interface/iinputcontext.py
095f9c
index 1d3cd2a..58d75e5 100644
095f9c
--- a/ibus/interface/iinputcontext.py
095f9c
+++ b/ibus/interface/iinputcontext.py
095f9c
@@ -76,8 +76,8 @@ class IInputContext(dbus.service.Object):
095f9c
     @method(out_signature="v")
095f9c
     def GetEngine(self): pass
095f9c
 
095f9c
-    @method(in_signature="s")
095f9c
-    def SetEngine(self, engine_name): pass
095f9c
+    @async_method(in_signature="s")
095f9c
+    def SetEngine(self, engine_name, reply_cb, error_cb): pass
63b857
 
095f9c
     @method()
095f9c
     def Destroy(self): pass
095f9c
diff --git a/ibus/xkbxml.py.in b/ibus/xkbxml.py.in
0318d1
index 9407c13..bf61810 100644
095f9c
--- a/ibus/xkbxml.py.in
095f9c
+++ b/ibus/xkbxml.py.in
095f9c
@@ -33,6 +33,8 @@ import enginedesc
095f9c
 from xml.sax.saxutils import XMLFilterBase, XMLGenerator
095f9c
 from xml.sax._exceptions import SAXParseException
095f9c
 from cStringIO import StringIO
095f9c
+from _config import DEFAULT_BRIDGE_ENGINE_NAME
095f9c
+from _config import get_ICON_KEYBOARD
095f9c
 
095f9c
 try:
095f9c
     from glib import get_user_config_dir
0318d1
@@ -315,6 +317,8 @@ class XKBConfigRegistry():
095f9c
             engine_layout = layout
095f9c
 
095f9c
         icon = 'ibus-engine'
0318d1
+        if name.startswith(DEFAULT_BRIDGE_ENGINE_NAME):
095f9c
+            icon = get_ICON_KEYBOARD()
095f9c
 
095f9c
         engine = enginedesc.EngineDesc(name, longname, desc, lang,
095f9c
                                        'LGPL2.1',
47affb
diff --git a/setup/enginecombobox.py b/setup/enginecombobox.py
095f9c
index 7383177..d35757d 100644
47affb
--- a/setup/enginecombobox.py
47affb
+++ b/setup/enginecombobox.py
47affb
@@ -64,6 +64,9 @@ class EngineComboBox(gtk.ComboBox):
47affb
         self.__model.set(iter1, 0, 0)
47affb
         lang = {}
47affb
         for e in engines:
47affb
+            if ibus.use_bridge_hotkey() and \
095f9c
+               e.name.startswith(ibus.DEFAULT_BRIDGE_ENGINE_NAME):
47affb
+                continue
47affb
             l = ibus.get_language_name(e.language)
47affb
             if l not in lang:
47affb
                 lang[l] = []
577a98
diff --git a/setup/enginetreeview.py b/setup/enginetreeview.py
0318d1
index f620361..664dc99 100644
577a98
--- a/setup/enginetreeview.py
577a98
+++ b/setup/enginetreeview.py
0318d1
@@ -172,8 +172,12 @@ class EngineTreeView(gtk.TreeView):
47affb
         for e in engines:
47affb
             if e in self.__engines:
47affb
                 continue
47affb
-            iter = self.__model.append(None)
47affb
-            self.__model.set(iter, 0, e)
47affb
+            if ibus.use_bridge_hotkey() and \
095f9c
+               e.name.startswith(ibus.DEFAULT_BRIDGE_ENGINE_NAME):
47affb
+                pass
47affb
+            else:
47affb
+                iter = self.__model.append(None)
47affb
+                self.__model.set(iter, 0, e)
47affb
             self.__engines.add(e)
47affb
         self.__emit_changed()
47affb
 
095f9c
diff --git a/setup/main.py b/setup/main.py
095f9c
index 7f4a040..a22ac78 100644
095f9c
--- a/setup/main.py
095f9c
+++ b/setup/main.py
095f9c
@@ -213,6 +213,25 @@ class Setup(object):
095f9c
             self.__config.get_value("general", "use_global_engine", False))
095f9c
         self.__checkbutton_use_global_engine.connect("toggled", self.__checkbutton_use_global_engine_toggled_cb)
095f9c
 
095f9c
+        # hotkey settings
095f9c
+        if ibus.use_bridge_hotkey():
095f9c
+            label = self.__builder.get_object("label_trigger_hotkey")
095f9c
+            label.set_label(_("Toggle:"))
095f9c
+            label.set_tooltip_text(_("The trigger shortcut keys to toggle "
095f9c
+                                     "the previous and next input methods"))
095f9c
+            self.__checkbutton_use_on_off_hotkey = \
095f9c
+                self.__builder.get_object("checkbutton_use_on_off_hotkey")
095f9c
+            self.__checkbutton_use_on_off_hotkey.set_active(
095f9c
+                not self.__config.get_value("general/hotkey",
095f9c
+                                            "use_bridge_hotkey",
095f9c
+                                            True))
095f9c
+            self.__checkbutton_use_on_off_hotkey.connect("toggled",
095f9c
+                self.__checkbutton_use_on_off_hotkey_cb)
095f9c
+        else:
095f9c
+            checkbutton = self.__builder.get_object("checkbutton_use_on_off_hotkey")
095f9c
+            checkbutton.hide()
095f9c
+            checkbutton.set_no_show_all(True)
095f9c
+
095f9c
         # init engine page
095f9c
         preload_engine_mode = self.__config.get_value("general",
095f9c
                                                       "preload_engine_mode",
095f9c
@@ -519,6 +538,11 @@ class Setup(object):
095f9c
         value = self.__checkbutton_use_global_engine.get_active()
095f9c
         self.__config.set_value("general", "use_global_engine", value)
095f9c
 
095f9c
+    def __checkbutton_use_on_off_hotkey_cb(self, button):
095f9c
+        value = self.__checkbutton_use_on_off_hotkey.get_active()
095f9c
+        self.__config.set_value("general/hotkey", "use_bridge_hotkey",
095f9c
+                                not value)
095f9c
+
095f9c
     def __config_value_changed_cb(self, bus, section, name, value):
095f9c
         if section == 'general' and name == 'preload_engines':
095f9c
             engines = self.__get_engine_descs_from_names(value)
095f9c
diff --git a/setup/setup.ui b/setup/setup.ui
095f9c
index f1e6d0b..77714a7 100644
095f9c
--- a/setup/setup.ui
095f9c
+++ b/setup/setup.ui
095f9c
@@ -232,7 +232,7 @@
095f9c
                                   </packing>
095f9c
                                 </child>
095f9c
                                 <child>
095f9c
-                                  <object class="GtkLabel" id="label7">
095f9c
+                                  <object class="GtkLabel" id="label_trigger_hotkey">
095f9c
                                     <property name="visible">True</property>
095f9c
                                     <property name="tooltip_text" translatable="yes">The shortcut keys for turning input method on or off</property>
095f9c
                                     <property name="xalign">0</property>
095f9c
@@ -962,6 +962,59 @@ You may use up/down buttons to change it.</i></small></property>
095f9c
                         <property name="position">1</property>
095f9c
                       </packing>
095f9c
                     </child>
095f9c
+                    <child>
095f9c
+                      <object class="GtkFrame" id="frame6">
095f9c
+                        <property name="visible">True</property>
095f9c
+                        <property name="label_xalign">0</property>
095f9c
+                        <property name="shadow_type">none</property>
095f9c
+                        <child>
095f9c
+                          <object class="GtkAlignment" id="alignment14">
095f9c
+                            <property name="visible">True</property>
095f9c
+                            <property name="left_padding">12</property>
095f9c
+                            <child>
095f9c
+                              <object class="GtkAlignment" id="alignment15">
095f9c
+                                <property name="visible">True</property>
095f9c
+                                <property name="top_padding">6</property>
095f9c
+                                <property name="left_padding">12</property>
095f9c
+                                <child>
095f9c
+                                  <object class="GtkVBox" id="vbox10">
095f9c
+                                    <property name="visible">True</property>
095f9c
+                                    <property name="orientation">vertical</property>
095f9c
+                                    <property name="spacing">6</property>
095f9c
+                                    <child>
095f9c
+                                      <object class="GtkCheckButton" id="checkbutton_use_on_off_hotkey">
095f9c
+                                        <property name="label" translatable="yes">Use trigger keys to enable or disable an input method</property>
095f9c
+                                        <property name="visible">True</property>
095f9c
+                                        <property name="can_focus">True</property>
095f9c
+                                        <property name="receives_default">False</property>
095f9c
+                                        <property name="draw_indicator">True</property>
095f9c
+                                      </object>
095f9c
+                                      <packing>
095f9c
+                                        <property name="expand">False</property>
095f9c
+                                        <property name="fill">False</property>
095f9c
+                                        <property name="position">0</property>
095f9c
+                                      </packing>
095f9c
+                                    </child>
095f9c
+                                  </object>
095f9c
+                                </child>
095f9c
+                              </object>
095f9c
+                            </child>
095f9c
+                          </object>
095f9c
+                        </child>
095f9c
+                        <child type="label">
095f9c
+                          <object class="GtkLabel" id="label50">
095f9c
+                            <property name="visible">True</property>
095f9c
+                            <property name="label" translatable="yes"><b>Hot keys setting</b></property>
095f9c
+                            <property name="use_markup">True</property>
095f9c
+                          </object>
095f9c
+                        </child>
095f9c
+                      </object>
095f9c
+                      <packing>
095f9c
+                        <property name="expand">False</property>
095f9c
+                        <property name="fill">False</property>
095f9c
+                        <property name="position">2</property>
095f9c
+                      </packing>
095f9c
+                    </child>
095f9c
                   </object>
095f9c
                 </child>
095f9c
               </object>
63b857
diff --git a/src/Makefile.am b/src/Makefile.am
47affb
index 6454522..319df3c 100644
63b857
--- a/src/Makefile.am
63b857
+++ b/src/Makefile.am
47affb
@@ -38,14 +38,16 @@ INTROSPECTION_GIRS =
47affb
 CLEANFILES =
47affb
 
47affb
 # C preprocessor flags
47affb
-AM_CPPFLAGS =                                   \
47affb
-    -DG_LOG_DOMAIN=\"IBUS\"                     \
47affb
-    @GLIB2_CFLAGS@                              \
47affb
-    @GOBJECT2_CFLAGS@                           \
47affb
-    @GIO2_CFLAGS@                               \
47affb
-    -DIBUS_DATA_DIR=\"$(pkgdatadir)\"           \
47affb
-    -DIBUS_COMPILATION                          \
47affb
-    -DISOCODES_PREFIX=\"$(ISOCODES_PREFIX)\"    \
47affb
+AM_CPPFLAGS =                                                           \
47affb
+    -DG_LOG_DOMAIN=\"IBUS\"                                             \
47affb
+    @GLIB2_CFLAGS@                                                      \
47affb
+    @GOBJECT2_CFLAGS@                                                   \
47affb
+    @GIO2_CFLAGS@                                                       \
47affb
+    -DIBUS_DATA_DIR=\"$(pkgdatadir)\"                                   \
47affb
+    -DIBUS_COMPILATION                                                  \
47affb
+    -DISOCODES_PREFIX=\"$(ISOCODES_PREFIX)\"                            \
47affb
+    -DUSE_BRIDGE_HOTKEY=$(USE_BRIDGE_HOTKEY)                            \
47affb
+    -DDEFAULT_BRIDGE_ENGINE_NAME=\"$(DEFAULT_BRIDGE_ENGINE_NAME)\"      \
63b857
     $(NULL)
63b857
 
63b857
 # ibus library
63b857
diff --git a/src/ibushotkey.c b/src/ibushotkey.c
63b857
index 32f8338..bef7dfc 100644
63b857
--- a/src/ibushotkey.c
63b857
+++ b/src/ibushotkey.c
63b857
@@ -562,3 +562,14 @@ ibus_hotkey_profile_lookup_hotkey (IBusHotkeyProfile *profile,
63b857
 
63b857
     return (GQuark) GPOINTER_TO_UINT (g_tree_lookup (priv->hotkeys, &hotkey));
63b857
 }
63b857
+
63b857
+void
63b857
+ibus_hotkey_profile_foreach_hotkey (IBusHotkeyProfile *profile,
63b857
+                                    GTraverseFunc      func,
63b857
+                                    gpointer           user_data)
63b857
+{
63b857
+    IBusHotkeyProfilePrivate *priv;
63b857
+    priv = IBUS_HOTKEY_PROFILE_GET_PRIVATE (profile);
63b857
+
63b857
+    g_tree_foreach (priv->hotkeys, func, user_data);
63b857
+}
63b857
diff --git a/src/ibushotkey.h b/src/ibushotkey.h
63b857
index 9a341f6..92ec6af 100644
63b857
--- a/src/ibushotkey.h
63b857
+++ b/src/ibushotkey.h
63b857
@@ -179,5 +179,16 @@ GQuark           ibus_hotkey_profile_lookup_hotkey
63b857
                                                  guint               keyval,
63b857
                                                  guint               modifiers);
63b857
 
63b857
+/**
63b857
+ * ibus_hotkey_profile_foreach_hotkey:
63b857
+ * @profile: An IBusHotkeyProfile.
63b857
+ * @func: (scope call): A GTraverseFunc for g_tree_traverse.
63b857
+ * @user_data: A gpointer for g_tree_traverse.
63b857
+ */
63b857
+void             ibus_hotkey_profile_foreach_hotkey
63b857
+                                                (IBusHotkeyProfile  *profile,
63b857
+                                                 GTraverseFunc       func,
63b857
+                                                 gpointer            user_data);
63b857
+
63b857
 G_END_DECLS
63b857
 #endif
095f9c
diff --git a/src/ibusutil.c b/src/ibusutil.c
095f9c
index ddb6b9e..46dab1a 100644
095f9c
--- a/src/ibusutil.c
095f9c
+++ b/src/ibusutil.c
095f9c
@@ -145,3 +145,15 @@ ibus_get_language_name(const gchar *_locale) {
095f9c
     }
095f9c
     return retval;
095f9c
 }
095f9c
+
095f9c
+gboolean
095f9c
+ibus_use_bridge_hotkey (void)
095f9c
+{
095f9c
+    return (USE_BRIDGE_HOTKEY == 1) ? TRUE : FALSE;
095f9c
+}
095f9c
+
095f9c
+const gchar *
095f9c
+ibus_get_default_bridge_engine_name (void)
095f9c
+{
095f9c
+    return DEFAULT_BRIDGE_ENGINE_NAME;
095f9c
+}
095f9c
diff --git a/src/ibusutil.h b/src/ibusutil.h
095f9c
index 7cf1995..a19d16e 100644
095f9c
--- a/src/ibusutil.h
095f9c
+++ b/src/ibusutil.h
095f9c
@@ -43,4 +43,18 @@
095f9c
  */
095f9c
 const gchar *    ibus_get_language_name         (const gchar    *_locale);
095f9c
 
095f9c
+/**
095f9c
+ * ibus_bus_use_bridge_hotkey:
095f9c
+ * @bus: An #IBusBus.
095f9c
+ * @returns: %TRUE if @bus use bridge hotkey, %FALSE otherwise.
095f9c
+ */
095f9c
+gboolean         ibus_use_bridge_hotkey (void);
095f9c
+
095f9c
+/**
095f9c
+ * ibus_bus_get_default_bridge_engine_name:
095f9c
+ * @bus: An #IBusBus.
095f9c
+ * @returns: A default bridge engine name.
095f9c
+ */
095f9c
+const gchar *    ibus_get_default_bridge_engine_name (void);
095f9c
+
095f9c
 #endif
63b857
diff --git a/ui/gtk/panel.py b/ui/gtk/panel.py
0318d1
index 8804634..f7b3e50 100644
63b857
--- a/ui/gtk/panel.py
63b857
+++ b/ui/gtk/panel.py
0318d1
@@ -67,6 +67,7 @@ class Panel(ibus.PanelBase):
0318d1
         self.__data_dir = path.join(self.__prefix, "share", "ibus")
0318d1
         # self.__icons_dir = path.join(self.__data_dir, "icons")
0318d1
         self.__setup_cmd = path.join(self.__prefix, "bin", "ibus-setup")
0318d1
+        self.__show = 0
0318d1
 
0318d1
         # connect bus signal
0318d1
         self.__config.connect("value-changed", self.__config_value_changed_cb)
0318d1
@@ -133,6 +134,14 @@ class Panel(ibus.PanelBase):
63b857
         # self.__bus.request_name(ibus.panel.IBUS_SERVICE_PANEL, 0)
63b857
 
63b857
         # init xkb
63b857
+        self.__default_layout = 'default'
63b857
+        self.__default_model = 'default'
63b857
+        self.__default_option = 'default'
47affb
+        self.__disabled_engines = None
47affb
+        self.__disabled_engines_id = -1
47affb
+        self.__disabled_engines_prev_id = -1
47affb
+        self.__disabled_engines_swapped = 0
63b857
+
63b857
         self.__xkblayout = ibus.XKBLayout(self.__config)
63b857
         use_xkb = self.__config.get_value("general", "use_system_keyboard_layout", False)
63b857
         if not use_xkb:
b4e3b4
@@ -142,11 +151,18 @@ class Panel(ibus.PanelBase):
63b857
             value = 'default'
63b857
         if value != 'default':
63b857
             self.__xkblayout.set_default_layout(value)
63b857
+            if value.find('(') >= 0:
63b857
+                self.__default_layout = value.split('(')[0]
63b857
+                self.__default_model = value.split('(')[1].split(')')[0]
63b857
+            else:
63b857
+                self.__default_layout = value
63b857
+                self.__default_model = None
63b857
         value = str(self.__config.get_value("general", "system_keyboard_option", ''))
63b857
         if value == '':
63b857
             value = 'default'
63b857
         if value != 'default':
63b857
             self.__xkblayout.set_default_option(value)
63b857
+            self.__default_option = value
63b857
 
63b857
     def set_cursor_location(self, x, y, w, h):
63b857
         self.__candidate_panel.set_cursor_location(x, y, w, h)
0318d1
@@ -233,12 +249,91 @@ class Panel(ibus.PanelBase):
63b857
     def __set_im_name(self, name):
63b857
         self.__language_bar.set_im_name(name)
63b857
 
095f9c
+    def __use_bridge_hotkey(self):
095f9c
+        if not ibus.use_bridge_hotkey():
095f9c
+            return False
095f9c
+        if self.__config == None:
095f9c
+            return True
095f9c
+        return self.__config.get_value("general/hotkey", "use_bridge_hotkey",
095f9c
+                                       True)
095f9c
+
095f9c
+    def __set_default_layout_engine(self, use_bridge_hotkey):
63b857
+        default_layout = self.__default_layout
63b857
+        default_model = self.__default_model
63b857
+        if default_layout == 'default':
63b857
+            default_layout = self.__xkblayout.get_default_layout()[0]
47affb
+            default_model = self.__xkblayout.get_default_layout()[1]
63b857
+        if default_model == 'default':
63b857
+            default_model = self.__xkblayout.get_default_layout()[1]
63b857
+        layouts = default_layout.split(',')
47affb
+        models = None
63b857
+        if default_model != None and default_model != '':
63b857
+            models = default_model.split(',')
47affb
+        if self.__disabled_engines == None or self.__disabled_engines == []:
47affb
+            self.__disabled_engines = []
47affb
+            for i, layout in enumerate(layouts):
47affb
+                registry = ibus.XKBConfigRegistry()
47affb
+                langs = registry.get_layout_lang()[layout]
47affb
+                lang = 'en'
47affb
+                if langs != None:
47affb
+                    lang = str(langs[0])
47affb
+                model = None
47affb
+                if i == 0:
47affb
+                    layout = default_layout
47affb
+                    model = default_model
47affb
+                elif i < len(models):
47affb
+                    model = models[i]
47affb
+                if model == '':
47affb
+                    model = None
47affb
+                model_desc = _("Default Layout")
47affb
+                if model != None:
47affb
+                    model_desc = model_desc + " (" + model + ")"
0318d1
+                name = ibus.DEFAULT_BRIDGE_ENGINE_NAME + "#" + str(i)
47affb
+                engine = registry.engine_desc_new(lang,
47affb
+                                                  layout,
47affb
+                                                  _("Default Layout"),
47affb
+                                                  model,
095f9c
+                                                  model_desc,
0318d1
+                                                  name)
47affb
+                self.__disabled_engines.append(engine)
47affb
+            self.__disabled_engines_id = self.__xkblayout.get_group()
095f9c
+        if not use_bridge_hotkey:
47affb
+            return
095f9c
+        if self.__disabled_engines != None and self.__disabled_engines != []:
095f9c
+            if self.__focus_ic == None:
095f9c
+                return
095f9c
+            engine = self.__focus_ic.get_engine()
095f9c
+            if engine == None:
095f9c
+                if self.__disabled_engines_id < 0:
095f9c
+                    self.__disabled_engines_id = 0
095f9c
+                self.__focus_ic.focus_in()
095f9c
+                self.__focus_ic.set_engine(self.__disabled_engines[self.__disabled_engines_id])
095f9c
+            elif engine != None and \
095f9c
+                 not self.__focus_ic.is_enabled():
095f9c
+                self.__focus_ic.focus_in()
095f9c
+                self.__focus_ic.enable()
63b857
+
63b857
     def focus_in(self, ic):
63b857
         self.reset()
63b857
         self.__focus_ic = ibus.InputContext(self.__bus, ic)
47affb
         enabled = self.__focus_ic.is_enabled()
b4e3b4
-        self.__language_bar.set_enabled(enabled)
63b857
 
095f9c
+        use_bridge_hotkey = self.__use_bridge_hotkey()
095f9c
+        self.__set_default_layout_engine(use_bridge_hotkey)
095f9c
+        if use_bridge_hotkey:
b4e3b4
+            if self.__show != 1:
b4e3b4
+                self.__language_bar.set_enabled(enabled)
b4e3b4
+            elif enabled:
b4e3b4
+                engine = self.__focus_ic.get_engine()
b4e3b4
+                if engine != None and \
095f9c
+                   not engine.name.startswith(ibus.DEFAULT_BRIDGE_ENGINE_NAME):
b4e3b4
+                    self.__language_bar.set_enabled(enabled)
b4e3b4
+                else:
b4e3b4
+                    self.__language_bar.set_enabled(False)
b4e3b4
+            else:
b4e3b4
+                self.__language_bar.set_enabled(False)
b4e3b4
+        else:
b4e3b4
+            self.__language_bar.set_enabled(enabled)
63b857
         if not enabled:
63b857
             self.__set_im_icon(ICON_KEYBOARD)
63b857
             self.__set_im_name(None)
0318d1
@@ -250,7 +345,7 @@ class Panel(ibus.PanelBase):
47affb
                 self.__set_im_icon(engine.icon)
47affb
                 self.__set_im_name(engine.longname)
47affb
                 if self.__bus.get_use_sys_layout():
47affb
-                    self.__xkblayout.set_layout(self.__engine_get_layout_wrapper(engine))
47affb
+                    self.__xkblayout.set_layout(self.__engine_get_layout_wrapper(engine, False))
47affb
             else:
47affb
                 self.__set_im_icon(ICON_KEYBOARD)
47affb
                 self.__set_im_name(None)
ed173d
@@ -273,7 +368,21 @@ class Panel(ibus.PanelBase):
b4e3b4
             return
b4e3b4
 
b4e3b4
         enabled = self.__focus_ic.is_enabled()
b4e3b4
-        self.__language_bar.set_enabled(enabled)
b4e3b4
+
095f9c
+        if self.__use_bridge_hotkey():
b4e3b4
+            if self.__show != 1:
b4e3b4
+                self.__language_bar.set_enabled(enabled)
b4e3b4
+            elif enabled:
b4e3b4
+                engine = self.__focus_ic.get_engine()
b4e3b4
+                if engine != None and \
095f9c
+                   not engine.name.startswith(ibus.DEFAULT_BRIDGE_ENGINE_NAME):
b4e3b4
+                    self.__language_bar.set_enabled(enabled)
b4e3b4
+                else:
b4e3b4
+                    self.__language_bar.set_enabled(False)
b4e3b4
+            else:
b4e3b4
+                self.__language_bar.set_enabled(False)
b4e3b4
+        else:
b4e3b4
+            self.__language_bar.set_enabled(enabled)
b4e3b4
 
b4e3b4
         if enabled == False:
b4e3b4
             self.reset()
ed173d
@@ -287,7 +396,7 @@ class Panel(ibus.PanelBase):
47affb
                 self.__set_im_icon(engine.icon)
47affb
                 self.__set_im_name(engine.longname)
47affb
                 if self.__bus.get_use_sys_layout():
47affb
-                    self.__xkblayout.set_layout(self.__engine_get_layout_wrapper(engine))
47affb
+                    self.__xkblayout.set_layout(self.__engine_get_layout_wrapper(engine, True))
47affb
             else:
47affb
                 self.__set_im_icon(ICON_KEYBOARD)
47affb
                 self.__set_im_name(None)
ed173d
@@ -315,6 +424,7 @@ class Panel(ibus.PanelBase):
b4e3b4
 
b4e3b4
     def __config_load_show(self):
b4e3b4
         show = self.__config.get_value("panel", "show", 0)
b4e3b4
+        self.__show = show
b4e3b4
         self.__language_bar.set_show(show)
b4e3b4
 
b4e3b4
     def __config_load_position(self):
ed173d
@@ -443,6 +553,21 @@ class Panel(ibus.PanelBase):
47affb
     #     menu.set_take_focus(False)
47affb
     #     return menu
47affb
 
47affb
+    def __add_engine_in_menu(self, menu, engine, is_bold, size):
47affb
+        language = engine.language
47affb
+        lang = ibus.get_language_name(language)
47affb
+        item = gtk.ImageMenuItem("%s - %s" % (lang, engine.longname))
47affb
+        if is_bold:
47affb
+            for widget in item.get_children():
47affb
+                if isinstance(widget, gtk.Label):
47affb
+                    widget.set_markup("%s" % widget.get_text())
47affb
+        if engine.icon:
47affb
+            item.set_image(_icon.IconWidget(engine.icon, size[0]))
47affb
+        else:
47affb
+            item.set_image(_icon.IconWidget(ICON_ENGINE, size[0]))
47affb
+        item.connect("activate", self.__im_menu_item_activate_cb, engine)
47affb
+        menu.add(item)
47affb
+
47affb
     def __create_im_menu(self):
47affb
         engines = self.__bus.list_active_engines()
47affb
         current_engine = \
ed173d
@@ -453,25 +578,39 @@ class Panel(ibus.PanelBase):
63b857
         size = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU)
63b857
         menu = gtk.Menu()
63b857
         for i, engine in enumerate(engines):
63b857
-            lang = ibus.get_language_name(engine.language)
47affb
-            item = gtk.ImageMenuItem("%s - %s" % (lang, engine.longname))
47affb
-            if current_engine and current_engine.name == engine.name:
47affb
-                for widget in item.get_children():
47affb
-                    if isinstance(widget, gtk.Label):
47affb
-                        widget.set_markup("%s" % widget.get_text())
47affb
-            if engine.icon:
47affb
-                item.set_image(_icon.IconWidget(engine.icon, size[0]))
47affb
-            else:
47affb
-                item.set_image(_icon.IconWidget(ICON_ENGINE, size[0]))
47affb
-            item.connect("activate", self.__im_menu_item_activate_cb, engine)
47affb
-            menu.add(item)
0318d1
+            if engine.name.startswith(ibus.DEFAULT_BRIDGE_ENGINE_NAME):
0318d1
+                if not self.__use_bridge_hotkey():
0318d1
+                    continue
0318d1
+                if self.__disabled_engines == None:
0318d1
+                    continue
0318d1
+                engine.disabled_engines_id = -1
47affb
+                for j, kb_engine in enumerate(self.__disabled_engines):
095f9c
+                    if engine.name == kb_engine.name:
095f9c
+                        engine.disabled_engines_id = j
095f9c
+                        break
0318d1
+                if engine.disabled_engines_id == -1:
0318d1
+                    continue
0318d1
+                kb_engine = self.__disabled_engines[engine.disabled_engines_id]
0318d1
+                kb_engine.is_bridge = True
0318d1
+                kb_engine.disabled_engines_id = engine.disabled_engines_id
095f9c
+                is_bold = True if (current_engine != None and \
0318d1
+                        current_engine.name == kb_engine.name) else False
0318d1
+                self.__add_engine_in_menu(menu, kb_engine,
095f9c
+                                          is_bold,
095f9c
+                                          size)
47affb
+                continue
47affb
+            engine.is_bridge = False
47affb
+            is_bold = True if (current_engine != None and \
47affb
+                    current_engine.name == engine.name) else False
47affb
+            self.__add_engine_in_menu(menu, engine, is_bold, size)
47affb
 
47affb
         item = gtk.ImageMenuItem(_("Turn off input method"))
47affb
         item.set_image(_icon.IconWidget("gtk-close", size[0]))
63b857
         item.connect("activate", self.__im_menu_item_activate_cb, None)
63b857
         if self.__focus_ic == None or not self.__focus_ic.is_enabled():
63b857
             item.set_sensitive(False)
63b857
-        menu.add(item)
095f9c
+        if not self.__use_bridge_hotkey():
63b857
+            menu.add(item)
63b857
 
63b857
         menu.show_all()
63b857
         menu.set_take_focus(False)
ed173d
@@ -523,8 +662,25 @@ class Panel(ibus.PanelBase):
47affb
         if not self.__focus_ic:
47affb
             return
47affb
         if engine:
47affb
-            self.__focus_ic.set_engine(engine)
095f9c
+            if self.__use_bridge_hotkey() and engine.is_bridge:
47affb
+                engines = self.__bus.list_active_engines()
47affb
+                current_engine = \
47affb
+                    (self.__focus_ic != None and self.__focus_ic.get_engine()) or \
47affb
+                    (engines and engines[0]) or \
47affb
+                    None
47affb
+                if current_engine and \
095f9c
+                   current_engine.name.startswith(ibus.DEFAULT_BRIDGE_ENGINE_NAME):
47affb
+                    self.__disabled_engines_prev_id = self.__disabled_engines_id
47affb
+                    self.__disabled_engines_swapped = 0
47affb
+                else:
47affb
+                    self.__disabled_engines_prev_id = -1
47affb
+                self.__disabled_engines_id = engine.disabled_engines_id
095f9c
+                self.__focus_ic.set_engine(self.__disabled_engines[self.__disabled_engines_id])
47affb
+            else:
47affb
+                self.__disabled_engines_prev_id = -1
47affb
+                self.__focus_ic.set_engine(engine)
47affb
         else:
47affb
+            self.__disabled_engines_prev_id = -1
47affb
             self.__focus_ic.disable()
47affb
 
47affb
     def __sys_menu_item_activate_cb(self, item, command):
ed173d
@@ -573,12 +729,85 @@ class Panel(ibus.PanelBase):
47affb
         self.__setup_pid = pid
47affb
         glib.child_watch_add(self.__setup_pid, self.__child_watch_cb)
47affb
 
47affb
-    def __engine_get_layout_wrapper(self, engine):
095f9c
+    def __get_model_from_layout(self, layout):
095f9c
+        left_bracket = layout.find('(')
095f9c
+        right_bracket = layout.find(')')
095f9c
+        if left_bracket >= 0 and right_bracket > left_bracket:
095f9c
+            return (layout[:left_bracket] + layout[right_bracket + 1:], \
095f9c
+                    layout[left_bracket + 1:right_bracket])
095f9c
+        return (layout, "default")
095f9c
+
095f9c
+    def __get_option_from_layout(self, layout):
095f9c
+        left_bracket = layout.find('[')
095f9c
+        right_bracket = layout.find(']')
095f9c
+        if left_bracket >= 0 and right_bracket > left_bracket:
095f9c
+            return (layout[:left_bracket] + layout[right_bracket + 1:], \
095f9c
+                    layout[left_bracket + 1:right_bracket])
095f9c
+        return (layout, "default")
095f9c
+
095f9c
+    def __merge_models_and_options(self, cur_layout, engine_layout):
095f9c
+        orig_layout = cur_layout
095f9c
+        engine_model = "default"
095f9c
+        engine_option = "default"
095f9c
+        (engine_layout, engine_model) = \
095f9c
+            self.__get_model_from_layout(engine_layout)
095f9c
+        (engine_layout, engine_option) = \
095f9c
+            self.__get_option_from_layout(engine_layout)
095f9c
+        if (engine_model == None or engine_model == "default") and \
095f9c
+           (engine_option == None or engine_option == "default"):
095f9c
+            return cur_layout
095f9c
+        cur_model = "default"
095f9c
+        cur_option = "default"
095f9c
+        (cur_layout, cur_model) = \
095f9c
+            self.__get_model_from_layout(cur_layout)
095f9c
+        (cur_layout, cur_option) = \
095f9c
+            self.__get_option_from_layout(cur_layout)
095f9c
+        # Currently implemented options only.
095f9c
+        # Merging layouts and models are a little complicated.
095f9c
+        # e.g. ja,ru + ja(kana) == ja,ru,ja(,,kana)
095f9c
+        if engine_option != None and engine_option != "default":
095f9c
+            if cur_option == None or cur_option == "default":
095f9c
+                cur_option = engine_option
095f9c
+            elif cur_option != None and cur_option != "default":
095f9c
+                cur_option = "%s,%s" % (cur_option, engine_option)
095f9c
+            if cur_model != None and cur_model != "default":
095f9c
+                cur_layout = "%s(%s)" % (cur_layout, cur_model)
095f9c
+            if cur_option != None and cur_option != "default":
095f9c
+                cur_layout = "%s[%s]" % (cur_layout, cur_option)
095f9c
+            return cur_layout
095f9c
+        return orig_layout
095f9c
+
47affb
+    def __engine_get_layout_wrapper(self, engine, changed_state):
88e8e7
         # This code is for the back compatibility.
88e8e7
         # Should we remove the codes after all IM engines are changed
88e8e7
         # to "default" layout?
88e8e7
-        if engine.name != None and engine.name.startswith("xkb:layout:"):
88e8e7
+        if engine.name != None and engine.name.startswith("xkb:layout:") and \
095f9c
+           not self.__use_bridge_hotkey():
88e8e7
+            return engine.layout
88e8e7
+        elif engine.name != None and \
88e8e7
+             engine.name.startswith("xkb:layout:") and \
095f9c
+             self.__use_bridge_hotkey() and \
095f9c
+             not engine.name.startswith(ibus.DEFAULT_BRIDGE_ENGINE_NAME):
88e8e7
             return engine.layout
095f9c
+        elif self.__use_bridge_hotkey() and \
47affb
+           self.__disabled_engines_id >= 0 and \
47affb
+           self.__disabled_engines != None and \
47affb
+           self.__disabled_engines_id < len(self.__disabled_engines):
47affb
+            if changed_state and self.__disabled_engines_prev_id != -1:
47affb
+                # state_changed is always called twice because we change
47affb
+                # the engine. So the first two calls are ignored here.
47affb
+                if self.__disabled_engines_swapped < 2:
47affb
+                    self.__disabled_engines_swapped = \
47affb
+                            self.__disabled_engines_swapped + 1
47affb
+                else:
47affb
+                    x = self.__disabled_engines_prev_id
47affb
+                    self.__disabled_engines_prev_id = self.__disabled_engines_id
47affb
+                    self.__disabled_engines_id = x
47affb
+                    self.__disabled_engines_swapped = 1
47affb
+            retval = self.__disabled_engines[self.__disabled_engines_id].layout
095f9c
+            if engine.layout != None and engine.layout.startswith("default"):
095f9c
+                return self.__merge_models_and_options(retval, engine.layout)
47affb
+            return retval
095f9c
         elif engine.layout != None and engine.layout.startswith("default"):
095f9c
             return engine.layout
47affb
         else:
63b857
diff --git a/xkb/Makefile.am b/xkb/Makefile.am
63b857
index ad9cdd9..c4d5afb 100644
63b857
--- a/xkb/Makefile.am
63b857
+++ b/xkb/Makefile.am
63b857
@@ -28,6 +28,8 @@ INCLUDES = \
63b857
         -I$(top_srcdir)/src \
63b857
 	-DIBUS_LOCALEDIR=\"$(datadir)/locale\" \
63b857
 	-DLIBEXECDIR=\""$(libexecdir)"\" \
63b857
+	-DUSE_BRIDGE_HOTKEY=$(USE_BRIDGE_HOTKEY) \
63b857
+	-DDEFAULT_BRIDGE_ENGINE_NAME=\"$(DEFAULT_BRIDGE_ENGINE_NAME)\" \
63b857
         $(NULL)
63b857
 
63b857
 noinst_PROGRAMS = $(TESTS)
0318d1
diff --git a/xkb/ibus-engine-xkb-main.c b/xkb/ibus-engine-xkb-main.c
0318d1
index 0fb0f0c..4787bf2 100644
0318d1
--- a/xkb/ibus-engine-xkb-main.c
0318d1
+++ b/xkb/ibus-engine-xkb-main.c
0318d1
@@ -25,6 +25,7 @@
0318d1
 #endif
0318d1
 
0318d1
 #include <ibus.h>
0318d1
+#include <glib gi18n-lib.h="">
0318d1
 #include <stdlib.h>
0318d1
 
0318d1
 #ifdef ENABLE_NLS
0318d1
@@ -290,6 +291,9 @@ print_component ()
0318d1
     const gchar *desc;
0318d1
     gchar *output;
0318d1
     GString *str;
0318d1
+#if USE_BRIDGE_HOTKEY
0318d1
+    int i;
0318d1
+#endif
0318d1
 
0318d1
 #ifdef XKBLAYOUTCONFIG_FILE
0318d1
     layout_config = ibus_xkb_layout_config_new (XKBLAYOUTCONFIG_FILE);
0318d1
@@ -302,6 +306,19 @@ print_component ()
0318d1
     layout_desc = (GHashTable *) ibus_xkb_config_registry_get_layout_desc (config_registry);
0318d1
     variant_desc = (GHashTable *) ibus_xkb_config_registry_get_variant_desc (config_registry);
0318d1
     component = ibus_xkb_component_new ();
0318d1
+#if USE_BRIDGE_HOTKEY
0318d1
+    for (i = 0; i < 4; i++) {
0318d1
+        gchar *name = g_strdup_printf ("%s#%d", DEFAULT_BRIDGE_ENGINE_NAME, i);
0318d1
+        engine = ibus_xkb_engine_desc_new ("eng",
0318d1
+                                           "us",
0318d1
+                                           _("Default Layout"),
0318d1
+                                           NULL,
0318d1
+                                           NULL,
0318d1
+                                           name);
0318d1
+        g_free (name);
0318d1
+        ibus_component_add_engine (component, engine);
0318d1
+    }
0318d1
+#endif
0318d1
     for (keys = g_hash_table_get_keys (layout_list); keys; keys = keys->next) {
0318d1
         if (keys->data == NULL) {
0318d1
             continue;
0318d1
@@ -390,6 +407,8 @@ main (int argc, char **argv)
0318d1
 
0318d1
 #ifdef ENABLE_NLS
0318d1
     setlocale (LC_ALL, "");
0318d1
+    bindtextdomain (GETTEXT_PACKAGE, IBUS_LOCALEDIR);
0318d1
+    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
0318d1
 #endif
0318d1
 
0318d1
     g_type_init ();
63b857
diff --git a/xkb/xkbxml.c b/xkb/xkbxml.c
0318d1
index d59a929..86bcf8f 100644
63b857
--- a/xkb/xkbxml.c
63b857
+++ b/xkb/xkbxml.c
095f9c
@@ -25,6 +25,7 @@
095f9c
 #endif
095f9c
 
095f9c
 #include <glib.h>
095f9c
+#include <string.h>
095f9c
 
095f9c
 #include "xkbxml.h"
095f9c
 #include "ibus.h"
0318d1
@@ -275,6 +276,7 @@ ibus_xkb_engine_desc_new (const gchar *l
63b857
     gchar *desc = NULL;
63b857
     gchar *engine_layout = NULL;
0318d1
     const gchar *name_prefix = "xkb:layout:";
63b857
+    const gchar *icon = "ibus-engine";
63b857
 
63b857
     g_return_val_if_fail (lang != NULL && layout != NULL, NULL);
63b857
 
0318d1
@@ -304,6 +306,12 @@ ibus_xkb_engine_desc_new (const gchar *l
63b857
         desc = g_strdup_printf ("XKB %s keyboard layout", layout);
63b857
         engine_layout = g_strdup (layout);
63b857
     }
63b857
+#if USE_BRIDGE_HOTKEY
095f9c
+    if (g_ascii_strncasecmp (name, DEFAULT_BRIDGE_ENGINE_NAME,
095f9c
+                             strlen (DEFAULT_BRIDGE_ENGINE_NAME)) == 0) {
63b857
+        icon = "input-keyboard-symbolic";
63b857
+    }
63b857
+#endif
63b857
 
63b857
     engine = ibus_engine_desc_new (name,
63b857
                                    longname,
0318d1
@@ -311,7 +319,7 @@ ibus_xkb_engine_desc_new (const gchar *l
63b857
                                    lang,
63b857
                                    "LGPL2.1",
63b857
                                    "Takao Fujiwara <takao.fujiwara1@gmail.com>",
63b857
-                                   "ibus-engine",
63b857
+                                   icon,
63b857
                                    engine_layout);
63b857
 
63b857
     g_free (name);
63b857
-- 
47affb
1.7.5.4
63b857