From 39345212e8190aefa55a5266c123b2a7afc5c75f Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Tue, 8 Jan 2019 00:16:52 +0100 Subject: [PATCH] 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. (cherry picked from commit 16d4ce4d0301b7af2a67703e792efdcf27b1d397 with slight changes to use priv->client_window instead of priv->client_widget) --- gtk/gtkimmulticontext.c | 55 +++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/gtk/gtkimmulticontext.c b/gtk/gtkimmulticontext.c index ec67254946..50363559d7 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 @@ -256,10 +254,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 * @@ -267,9 +262,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; @@ -290,23 +282,31 @@ 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_window (GtkIMContext *context, GdkWindow *window) { - GtkIMMulticontext *multicontext = GTK_IM_MULTICONTEXT (context); - GtkIMMulticontextPrivate *priv = multicontext->priv; + GtkIMMulticontext *self = GTK_IM_MULTICONTEXT (context); + GtkIMMulticontextPrivate *priv = self->priv; GtkIMContext *slave; GdkScreen *screen; GtkSettings *settings; - gboolean connected; + + if (priv->client_window != NULL) + { + screen = gdk_window_get_screen (priv->client_window); + settings = gtk_settings_get_for_screen (screen); + + g_signal_handlers_disconnect_by_func (settings, + im_module_setting_changed, + self); + } priv->client_window = window; @@ -315,20 +315,12 @@ gtk_im_multicontext_set_client_window (GtkIMContext *context, screen = gdk_window_get_screen (window); settings = gtk_settings_get_for_screen (screen); - 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_window (slave, window); } @@ -723,9 +715,14 @@ gtk_im_multicontext_append_menuitems (GtkIMMulticontext *context, 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; } /**