Destroy existing connection before creating a new connection, and only create the...
authorPeng Huang <shawn.p.huang@gmail.com>
Thu, 21 Oct 2010 08:27:12 +0000 (17:27 +0900)
committerPeng Huang <shawn.p.huang@gmail.com>
Thu, 21 Oct 2010 08:27:12 +0000 (17:27 +0900)
BUG=chromium-os:7998
TEST=manual

Review URL: http://codereview.appspot.com/2640041

client/gtk2/ibusimcontext.c
src/ibusbus.c

index 7eb1b94..3cf7019 100644 (file)
@@ -83,6 +83,7 @@ static guint    _signal_retrieve_surrounding_id = 0;
 
 static const gchar *_no_snooper_apps = NO_SNOOPER_APPS;
 static gboolean _use_key_snooper = ENABLE_SNOOPER;
+static guint    _key_snooper_id = 0;
 
 static GtkIMContext *_focus_im_context = NULL;
 static IBusInputContext *_fake_context = NULL;
@@ -164,7 +165,7 @@ ibus_im_context_register_type (GTypeModule *type_module)
         (GInstanceInitFunc)    ibus_im_context_init,
     };
 
-    if (! _ibus_type_im_context ) {
+    if (!_ibus_type_im_context) {
         if (type_module) {
             _ibus_type_im_context =
                 g_type_module_register_type (type_module,
@@ -354,15 +355,19 @@ ibus_im_context_class_init     (IBusIMContextClass *klass)
     if (_bus == NULL) {
         ibus_set_display (gdk_display_get_name (gdk_display_get_default ()));
         _bus = ibus_bus_new();
-    }
 
-    if (ibus_bus_is_connected (_bus)) {
-        _create_fake_input_context ();
+        /* init the global fake context */
+        if (ibus_bus_is_connected (_bus)) {
+            _create_fake_input_context ();
+        }
+
+        g_signal_connect (_bus, "connected", G_CALLBACK (_bus_connected_cb), NULL);
     }
-    g_signal_connect (_bus, "connected", G_CALLBACK (_bus_connected_cb), NULL);
+
 
     /* always install snooper */
-    gtk_key_snooper_install (_key_snooper_cb, NULL);
+    if (_key_snooper_id == 0)
+        _key_snooper_id = gtk_key_snooper_install (_key_snooper_cb, NULL);
 }
 
 static void
index 60a4a37..ea5e0d6 100644 (file)
@@ -192,22 +192,12 @@ ibus_bus_connect (IBusBus *bus)
     IBusBusPrivate *priv;
     priv = IBUS_BUS_GET_PRIVATE (bus);
 
-#if 0
-    socket_path = ibus_get_socket_path ();
-
-    if (stat (socket_path, &buf) != 0) {
-        g_warning ("Can not get stat from %s!", socket_path);
-        return;
-    }
-    if (buf.st_uid != ibus_get_daemon_uid ()) {
-        g_warning ("The owner of %s is not %s!", socket_path, ibus_get_user_name ());
-        return;
-    }
-
+    /* destry old connection at first */
     if (priv->connection != NULL) {
-        ibus_object_destroy ((IBusObject *) priv->connection);
+        ibus_object_destroy ((IBusObject *)priv->connection);
+        g_assert (priv->connection == NULL);
     }
-#endif
+
     if (ibus_get_address () != NULL) {
         priv->connection = ibus_connection_open (ibus_get_address ());
     }
@@ -286,7 +276,6 @@ ibus_bus_init (IBusBus *bus)
 
     ibus_bus_connect (bus);
 
-
     file = g_file_new_for_path (ibus_get_socket_path ());
     priv->monitor = g_file_monitor_file (file, 0, NULL, NULL);