gtkimmulticontext: Handle switches between displays
authorCarlos Garnacho <carlosg@gnome.org>
Thu, 31 Mar 2022 14:29:34 +0000 (16:29 +0200)
committerCarlos Garnacho <carlosg@gnome.org>
Thu, 31 Mar 2022 14:35:29 +0000 (16:35 +0200)
Currently the GtkIMMultiContext may stick to a delegate GtkIMContext
that no longer applies after the multicontext is dissociated from
any widget.

Handle set_client_widget() so that it can handle changes between
widgets from 2 different display, but also so the delegate is made
NULL whenever the context has a NULL widget.

Doing so, any new client widget results in a new delegate IM context
lookup from the right GdkDisplay and GtkSettings, which avoids any
mix up.

Fixes: https://gitlab.gnome.org/GNOME/gtk/-/issues/4805
gtk/gtkimmulticontext.c

index 47347d299b810b5c4be2ec95fdf11e6320124e65..0a5ef9a5a6ac2505980ff519fa974f4b9cf833c4 100644 (file)
@@ -314,6 +314,11 @@ gtk_im_multicontext_set_client_widget (GtkIMContext *context,
   GtkIMContext *delegate;
   GtkSettings *settings;
 
+  if (priv->client_widget == widget)
+    return;
+
+  gtk_im_multicontext_set_delegate (self, NULL, TRUE);
+
   if (priv->client_widget != NULL)
     {
       settings = gtk_widget_get_settings (priv->client_widget);
@@ -332,11 +337,11 @@ gtk_im_multicontext_set_client_widget (GtkIMContext *context,
       g_signal_connect (settings, "notify::gtk-im-module",
                         G_CALLBACK (im_module_setting_changed),
                         self);
-    }
 
-  delegate = gtk_im_multicontext_get_delegate (self);
-  if (delegate)
-    gtk_im_context_set_client_widget (delegate, widget);
+      delegate = gtk_im_multicontext_get_delegate (self);
+      if (delegate)
+        gtk_im_context_set_client_widget (delegate, widget);
+    }
 }
 
 static void