[gtk] immulticontext: Don't have a global_context_id



commit 16d4ce4d0301b7af2a67703e792efdcf27b1d397
Author: Benjamin Otte <otte redhat com>
Date:   Tue Jan 8 00:16:52 2019 +0100

    immulticontext: Don't have a global_context_id
    
    Context IDs are dependant on the display - both because displays can use
    different backends, but also because changing the GtkSetting is a
    per-display operation.
    
    So just remove the cache.
    If it turns out we need a per-display cache, we can add one to
    GtkSettings.

 gtk/gtkimmulticontext.c | 54 +++++++++++++++++++++++--------------------------
 1 file changed, 25 insertions(+), 29 deletions(-)
---
diff --git a/gtk/gtkimmulticontext.c b/gtk/gtkimmulticontext.c
index c68ece9e94..aae9b6d0ae 100644
--- a/gtk/gtkimmulticontext.c
+++ b/gtk/gtkimmulticontext.c
@@ -102,8 +102,6 @@ static gboolean gtk_im_multicontext_delete_surrounding_cb   (GtkIMContext      *
 
 static void propagate_purpose (GtkIMMulticontext *context);
 
-static const gchar *global_context_id = NULL;
-
 G_DEFINE_TYPE_WITH_PRIVATE (GtkIMMulticontext, gtk_im_multicontext, GTK_TYPE_IM_CONTEXT)
 
 static void
@@ -250,10 +248,7 @@ get_effective_context_id (GtkIMMulticontext *multicontext)
   if (priv->context_id_aux)
     return priv->context_id_aux;
 
-  if (!global_context_id)
-    global_context_id = _gtk_im_module_get_default_context_id ();
-
-  return global_context_id;
+  return _gtk_im_module_get_default_context_id ();
 }
 
 static GtkIMContext *
@@ -261,9 +256,6 @@ gtk_im_multicontext_get_slave (GtkIMMulticontext *multicontext)
 {
   GtkIMMulticontextPrivate *priv = multicontext->priv;
 
-  if (g_strcmp0 (priv->context_id, get_effective_context_id (multicontext)) != 0)
-    gtk_im_multicontext_set_slave (multicontext, NULL, FALSE);
-
   if (!priv->slave)
     {
       GtkIMContext *slave;
@@ -284,22 +276,29 @@ gtk_im_multicontext_get_slave (GtkIMMulticontext *multicontext)
 }
 
 static void
-im_module_setting_changed (GtkSettings *settings, 
-                           gpointer     data)
+im_module_setting_changed (GtkSettings       *settings, 
+                           GtkIMMulticontext *self)
 {
-  global_context_id = NULL;
+  gtk_im_multicontext_set_slave (self, NULL, FALSE);
 }
 
-
 static void
 gtk_im_multicontext_set_client_widget (GtkIMContext *context,
                                       GtkWidget    *widget)
 {
-  GtkIMMulticontext *multicontext = GTK_IM_MULTICONTEXT (context);
-  GtkIMMulticontextPrivate *priv = multicontext->priv;
+  GtkIMMulticontext *self = GTK_IM_MULTICONTEXT (context);
+  GtkIMMulticontextPrivate *priv = self->priv;
   GtkIMContext *slave;
   GtkSettings *settings;
-  gboolean connected;
+
+  if (priv->client_widget != NULL)
+    {
+      settings = gtk_widget_get_settings (priv->client_widget);
+
+      g_signal_handlers_disconnect_by_func (settings,
+                                            im_module_setting_changed,
+                                            self);
+    }
 
   priv->client_widget = widget;
 
@@ -307,20 +306,12 @@ gtk_im_multicontext_set_client_widget (GtkIMContext *context,
     {
       settings = gtk_widget_get_settings (widget);
 
-      connected = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (settings),
-                                                      "gtk-im-module-connected"));
-      if (!connected)
-        {
-          g_signal_connect (settings, "notify::gtk-im-module",
-                            G_CALLBACK (im_module_setting_changed), NULL);
-          g_object_set_data (G_OBJECT (settings), "gtk-im-module-connected",
-                             GINT_TO_POINTER (TRUE));
-
-          global_context_id = NULL;
-        }
+      g_signal_connect (settings, "notify::gtk-im-module",
+                        G_CALLBACK (im_module_setting_changed),
+                        self);
     }
 
-  slave = gtk_im_multicontext_get_slave (multicontext);
+  slave = gtk_im_multicontext_get_slave (self);
   if (slave)
     gtk_im_context_set_client_widget (slave, widget);
 }
@@ -559,9 +550,14 @@ gtk_im_multicontext_delete_surrounding_cb (GtkIMContext      *slave,
 const char *
 gtk_im_multicontext_get_context_id (GtkIMMulticontext *context)
 {
+  GtkIMMulticontextPrivate *priv = context->priv;
+
   g_return_val_if_fail (GTK_IS_IM_MULTICONTEXT (context), NULL);
 
-  return context->priv->context_id;
+  if (priv->context_id == NULL)
+    gtk_im_multicontext_get_slave (context);
+
+  return priv->context_id;
 }
 
 /**


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