[gnome-settings-daemon] keyboard: Always try to activate the ibus daemon



commit 613f7965d15c764645085287f1dfe0b1903208b5
Author: Rui Matos <tiagomatos gmail com>
Date:   Tue Mar 19 15:02:21 2013 +0100

    keyboard: Always try to activate the ibus daemon
    
    We set XMODIFIERS= im=ibus globally at session start so that XIM
    clients can immediately benefit from IBus input sources when/if the
    user adds one. Unfortunately, these clients then won't work correctly
    in case we don't actually activate the ibus daemon. E.g. dead keys
    don't work in this case.
    
    Also, previously we'd try to set an "xkb:..." ibus engine according to
    the XKB layout. It happens that this wouldn't work for most layouts
    since there isn't an ibus engine for each layout and it's actually not
    needed since all of those "xkb:..." engines work the same way despite
    having different names.
    
    As such we'll always try to activate the daemon even if none of the
    user's current input sources need it and set one of the trivial "echo"
    engines so that XIM clients work correctly.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=695867

 plugins/keyboard/gsd-keyboard-manager.c     |   85 ++++-----------------------
 plugins/keyboard/test-keyboard-ibus-utils.c |   21 -------
 2 files changed, 12 insertions(+), 94 deletions(-)
---
diff --git a/plugins/keyboard/gsd-keyboard-manager.c b/plugins/keyboard/gsd-keyboard-manager.c
index c5d8666..e4de28a 100644
--- a/plugins/keyboard/gsd-keyboard-manager.c
+++ b/plugins/keyboard/gsd-keyboard-manager.c
@@ -103,7 +103,6 @@ struct GsdKeyboardManagerPrivate
 #ifdef HAVE_IBUS
         IBusBus   *ibus;
         GHashTable *ibus_engines;
-        GHashTable *ibus_xkb_engines;
         GCancellable *ibus_cancellable;
 #endif
         gint       xkb_event_base;
@@ -173,49 +172,9 @@ clear_ibus (GsdKeyboardManager *manager)
         g_cancellable_cancel (priv->ibus_cancellable);
         g_clear_object (&priv->ibus_cancellable);
         g_clear_pointer (&priv->ibus_engines, g_hash_table_destroy);
-        g_clear_pointer (&priv->ibus_xkb_engines, g_hash_table_destroy);
         g_clear_object (&priv->ibus);
 }
 
-static gchar *
-make_xkb_source_id (const gchar *engine_id)
-{
-        gchar *id;
-        gchar *p;
-        gint n_colons = 0;
-
-        /* engine_id is like "xkb:layout:variant:lang" where
-         * 'variant' and 'lang' might be empty */
-
-        engine_id += 4;
-
-        for (p = (gchar *)engine_id; *p; ++p)
-                if (*p == ':')
-                        if (++n_colons == 2)
-                                break;
-        if (!*p)
-                return NULL;
-
-        id = g_strndup (engine_id, p - engine_id + 1);
-
-        id[p - engine_id] = '\0';
-
-        /* id is "layout:variant" where 'variant' might be empty */
-
-        for (p = id; *p; ++p)
-                if (*p == ':') {
-                        if (*(p + 1) == '\0')
-                                *p = '\0';
-                        else
-                                *p = '+';
-                        break;
-                }
-
-        /* id is "layout+variant" or "layout" */
-
-        return id;
-}
-
 static void
 fetch_ibus_engines_result (GObject            *object,
                            GAsyncResult       *result,
@@ -244,22 +203,12 @@ fetch_ibus_engines_result (GObject            *object,
 
         /* Maps IBus engine ids to engine description objects */
         priv->ibus_engines = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref);
-        /* Maps XKB source id strings to engine description objects */
-        priv->ibus_xkb_engines = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
 
         for (l = list; l; l = l->next) {
                 IBusEngineDesc *engine = l->data;
                 const gchar *engine_id = ibus_engine_desc_get_name (engine);
 
                 g_hash_table_replace (priv->ibus_engines, (gpointer)engine_id, engine);
-
-                if (strncmp ("xkb:", engine_id, 4) == 0) {
-                        gchar *xkb_source_id = make_xkb_source_id (engine_id);
-                        if (xkb_source_id)
-                                g_hash_table_replace (priv->ibus_xkb_engines,
-                                                      xkb_source_id,
-                                                      engine);
-                }
         }
         g_list_free (list);
 
@@ -285,23 +234,8 @@ fetch_ibus_engines (GsdKeyboardManager *manager)
 }
 
 static void
-maybe_start_ibus (GsdKeyboardManager *manager,
-                  GVariant           *sources)
+maybe_start_ibus (GsdKeyboardManager *manager)
 {
-        gboolean need_ibus = FALSE;
-        GVariantIter iter;
-        const gchar *type;
-
-        g_variant_iter_init (&iter, sources);
-        while (g_variant_iter_next (&iter, "(&s&s)", &type, NULL))
-                if (g_str_equal (type, INPUT_SOURCE_TYPE_IBUS)) {
-                        need_ibus = TRUE;
-                        break;
-                }
-
-        if (!need_ibus)
-                return;
-
         if (!manager->priv->ibus) {
                 ibus_init ();
                 manager->priv->ibus = ibus_bus_new_async ();
@@ -364,16 +298,21 @@ set_ibus_engine (GsdKeyboardManager *manager,
 }
 
 static void
-set_ibus_xkb_engine (GsdKeyboardManager *manager,
-                     const gchar        *xkb_id)
+set_ibus_xkb_engine (GsdKeyboardManager *manager)
 {
         IBusEngineDesc *engine;
         GsdKeyboardManagerPrivate *priv = manager->priv;
 
-        if (!priv->ibus_xkb_engines)
+        if (!priv->ibus_engines)
                 return;
 
-        engine = g_hash_table_lookup (priv->ibus_xkb_engines, xkb_id);
+        /* All the "xkb:..." IBus engines simply "echo" back symbols,
+           despite their naming implying differently, so we always set
+           one in order for XIM applications to work given that we set
+           XMODIFIERS= im=ibus in the first place so that they can
+           work without restarting when/if the user adds an IBus
+           input source. */
+        engine = g_hash_table_lookup (priv->ibus_engines, "xkb:us::eng");
         if (!engine)
                 return;
 
@@ -1011,7 +950,7 @@ apply_input_sources_settings (GSettings          *settings,
         }
 
 #ifdef HAVE_IBUS
-        maybe_start_ibus (manager, sources);
+        maybe_start_ibus (manager);
 #endif
 
         g_variant_get_child (sources, current, "(&s&s)", &type, &id);
@@ -1029,7 +968,7 @@ apply_input_sources_settings (GSettings          *settings,
                 }
                 set_gtk_im_module (manager, GTK_IM_MODULE_SIMPLE);
 #ifdef HAVE_IBUS
-                set_ibus_xkb_engine (manager, id);
+                set_ibus_xkb_engine (manager);
 #endif
         } else if (g_str_equal (type, INPUT_SOURCE_TYPE_IBUS)) {
 #ifdef HAVE_IBUS
diff --git a/plugins/keyboard/test-keyboard-ibus-utils.c b/plugins/keyboard/test-keyboard-ibus-utils.c
index 0bfc2e5..6af034a 100644
--- a/plugins/keyboard/test-keyboard-ibus-utils.c
+++ b/plugins/keyboard/test-keyboard-ibus-utils.c
@@ -1,26 +1,6 @@
 #include "gsd-keyboard-manager.c"
 
 static void
-test_make_xkb_source_id (void)
-{
-        gint i;
-        const gchar *test_strings[][2] = {
-                /* input                output */
-                { "xkb:aa:bb:cc",       "aa+bb" },
-                { "xkb:aa:bb:",         "aa+bb" },
-                { "xkb:aa::cc",         "aa" },
-                { "xkb:aa::",           "aa" },
-                { "xkb::bb:cc",         "+bb" },
-                { "xkb::bb:",           "+bb" },
-                { "xkb:::cc",           "" },
-                { "xkb:::",             "" },
-        };
-
-        for (i = 0; i < G_N_ELEMENTS (test_strings); ++i)
-                g_assert_cmpstr (make_xkb_source_id (test_strings[i][0]), ==, test_strings[i][1]);
-}
-
-static void
 test_layout_from_ibus_layout (void)
 {
         gint i;
@@ -107,7 +87,6 @@ test_options_from_ibus_layout (void)
 int
 main (void)
 {
-        test_make_xkb_source_id ();
         test_layout_from_ibus_layout ();
         test_variant_from_ibus_layout ();
         test_options_from_ibus_layout ();


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