b46cf54
From c6949a852235bedb44126c3c6f36e1fba4b71bce Mon Sep 17 00:00:00 2001
b46cf54
From: fujiwarat <takao.fujiwara1@gmail.com>
b46cf54
Date: Tue, 8 Feb 2011 18:21:50 +0900
b46cf54
Subject: [PATCH] Added the optional sync mode apps in IBusIMContext.
b46cf54
b46cf54
---
b46cf54
 client/gtk2/ibusimcontext.c |   27 +++++++++++++++++++++++++++
b46cf54
 configure.ac                |   11 +++++++++++
b46cf54
 2 files changed, 38 insertions(+), 0 deletions(-)
b46cf54
b46cf54
diff --git a/client/gtk2/ibusimcontext.c b/client/gtk2/ibusimcontext.c
b46cf54
index bb5ae5c..a4e46cb 100644
b46cf54
--- a/client/gtk2/ibusimcontext.c
b46cf54
+++ b/client/gtk2/ibusimcontext.c
b46cf54
@@ -79,6 +79,7 @@ static const gchar *_no_snooper_apps = NO_SNOOPER_APPS;
b46cf54
 static gboolean _use_key_snooper = ENABLE_SNOOPER;
b46cf54
 static guint    _key_snooper_id = 0;
b46cf54
 
b46cf54
+static const gchar *_sync_mode_apps = SYNC_MODE_APPS;
b46cf54
 static gboolean _use_sync_mode = FALSE;
b46cf54
 
b46cf54
 static GtkIMContext *_focus_im_context = NULL;
b46cf54
@@ -477,6 +478,32 @@ ibus_im_context_class_init (IBusIMContextClass *class)
b46cf54
         g_strfreev (apps);
b46cf54
     }
b46cf54
 
b46cf54
+    /* env IBUS_SYNC_MODE_APPS for sync mode apps */
b46cf54
+    /* It seems MetaDisplay does not take the events from gdk_event_put()
b46cf54
+     * in async mode. So if gnome-shell + mutter are used,
b46cf54
+     * the key events are lost in async mode.
b46cf54
+     * gnome-shell search box, actually st_im_text_key_press_event(),
b46cf54
+     * does not call the parent filter_keypress() when the IM client
b46cf54
+     * returns TRUE. The class inherits ClutterActor which is not
b46cf54
+     * GtkWidget so the clutter does not call GTK snoopers.
b46cf54
+     * So ibus_im_context_filter_keypress() needs to return FALSE. */
b46cf54
+    if (!_use_sync_mode) {
b46cf54
+        /* enable sync mode if app is in _sync_mode_apps */
b46cf54
+        const gchar * prgname = g_get_prgname ();
b46cf54
+        if (g_getenv ("IBUS_SYNC_MODE_APPS")) {
b46cf54
+            _sync_mode_apps = g_getenv ("IBUS_SYNC_MODE_APPS");
b46cf54
+        }
b46cf54
+        gchar **p;
b46cf54
+        gchar ** apps = g_strsplit (_sync_mode_apps, ",", 0);
b46cf54
+        for (p = apps; *p != NULL; p++) {
b46cf54
+            if (g_regex_match_simple (*p, prgname, 0, 0)) {
b46cf54
+                _use_sync_mode = TRUE;
b46cf54
+                break;
b46cf54
+            }
b46cf54
+        }
b46cf54
+        g_strfreev (apps);
b46cf54
+    }
b46cf54
+
b46cf54
     /* init bus object */
b46cf54
     if (_bus == NULL) {
b46cf54
         ibus_set_display (gdk_display_get_name (gdk_display_get_default ()));
b46cf54
diff --git a/configure.ac b/configure.ac
b46cf54
index 1a1e663..81efe81 100644
b46cf54
--- a/configure.ac
b46cf54
+++ b/configure.ac
b46cf54
@@ -354,6 +354,16 @@ AC_ARG_WITH(no-snooper-apps,
b46cf54
 AC_DEFINE_UNQUOTED(NO_SNOOPER_APPS, "$NO_SNOOPER_APPS",
b46cf54
     [Does not enbale keyboard snooper in those applications])
b46cf54
 
b46cf54
+# option for sync mode applications.
b46cf54
+AC_ARG_WITH(sync-mode-apps,
b46cf54
+    AS_HELP_STRING([--with-sync-mode-apps[=regex1,regex2]],
b46cf54
+        [Enable sync mode in those applications (like: .*chrome.*,firefox.*)]),
b46cf54
+    [SYNC_MODE_APPS=$with_sync_mode_apps],
b46cf54
+    [SYNC_MODE_APPS=[mutter]]
b46cf54
+)
b46cf54
+AC_DEFINE_UNQUOTED(SYNC_MODE_APPS, "$SYNC_MODE_APPS",
b46cf54
+    [Enbale sync mode in those applications])
b46cf54
+
b46cf54
 # check iso-codes
b46cf54
 PKG_CHECK_MODULES(ISOCODES, [
b46cf54
     iso-codes
b46cf54
@@ -423,6 +433,7 @@ Build options:
b46cf54
   Build vala binding        $enable_vala
b46cf54
   Build document            $enable_gtk_doc
b46cf54
   Enable key snooper        $enable_key_snooper
b46cf54
+  Sync mode regexes         "$SYNC_MODE_APPS"
b46cf54
   No snooper regexes        "$NO_SNOOPER_APPS"
b46cf54
 ])
b46cf54
 
b46cf54
-- 
b46cf54
1.7.3.2
b46cf54