[gtk] immodule: Pass a GdkDisplay for default context ID



commit ca76675a6948ea113e15d7b455f2de2cd69ab26b
Author: Benjamin Otte <otte redhat com>
Date:   Tue Jan 8 00:22:14 2019 +0100

    immodule: Pass a GdkDisplay for default context ID
    
    After all, the context depends on the display - we want to use the
    wayland context for Wayland,  xim for X11 and so on.

 gtk/gtkimmodule.c        | 22 +++++++++++-----------
 gtk/gtkimmoduleprivate.h |  2 +-
 gtk/gtkimmulticontext.c  |  8 +++++++-
 3 files changed, 19 insertions(+), 13 deletions(-)
---
diff --git a/gtk/gtkimmodule.c b/gtk/gtkimmodule.c
index 92920d4637..5ebc55d4df 100644
--- a/gtk/gtkimmodule.c
+++ b/gtk/gtkimmodule.c
@@ -115,13 +115,12 @@ is_platform (const char *context_id)
 }
 
 static gboolean
-match_backend (const char *context_id)
+match_backend (GdkDisplay *display,
+               const char *context_id)
 {
 #ifdef GDK_WINDOWING_WAYLAND
   if (g_strcmp0 (context_id, "wayland") == 0)
     {
-      GdkDisplay *display = gdk_display_get_default ();
-
       return GDK_IS_WAYLAND_DISPLAY (display) &&
              gdk_wayland_display_query_registry (display,
                                                  "zwp_text_input_manager_v3");
@@ -130,22 +129,22 @@ match_backend (const char *context_id)
 
 #ifdef GDK_WINDOWING_BROADWAY
   if (g_strcmp0 (context_id, "broadway") == 0)
-    return GDK_IS_BROADWAY_DISPLAY (gdk_display_get_default ());
+    return GDK_IS_BROADWAY_DISPLAY (display);
 #endif
 
 #ifdef GDK_WINDOWING_X11
   if (g_strcmp0 (context_id, "xim") == 0)
-    return GDK_IS_X11_DISPLAY (gdk_display_get_default ());
+    return GDK_IS_X11_DISPLAY (display);
 #endif
 
 #ifdef GDK_WINDOWING_WIN32
   if (g_strcmp0 (context_id, "ime") == 0)
-    return GDK_IS_WIN32_DISPLAY (gdk_display_get_default ());
+    return GDK_IS_WIN32_DISPLAY (display);
 #endif
 
 #ifdef GDK_WINDOWING_QUARTZ
   if (g_strcmp0 (context_id, "quartz") == 0)
-    return GDK_IS_QUARTZ_DISPLAY (gdk_display_get_default ());
+    return GDK_IS_QUARTZ_DISPLAY (display);
 #endif
 
   return TRUE;
@@ -178,14 +177,15 @@ lookup_immodule (gchar **immodules_list)
 
 /**
  * _gtk_im_module_get_default_context_id:
- * 
+ * @display: The display to look up the module for
+ *
  * Return the context_id of the best IM context type 
  * for the given window.
  * 
  * Returns: the context ID (will never be %NULL)
  */
 const gchar *
-_gtk_im_module_get_default_context_id (void)
+_gtk_im_module_get_default_context_id (GdkDisplay *display)
 {
   const gchar *context_id = NULL;
   const gchar *envvar;
@@ -205,7 +205,7 @@ _gtk_im_module_get_default_context_id (void)
     }
 
   /* Check if the certain immodule is set in XSETTINGS. */
-  settings = gtk_settings_get_default ();
+  settings = gtk_settings_get_for_display (display);
   g_object_get (G_OBJECT (settings), "gtk-im-module", &tmp, NULL);
   if (tmp)
     {
@@ -231,7 +231,7 @@ _gtk_im_module_get_default_context_id (void)
       const char *context_id;
 
       context_id = g_io_extension_get_name (ext);
-      if (match_backend (context_id))
+      if (match_backend (display, context_id))
         return context_id;
 
       // FIXME: locale matching
diff --git a/gtk/gtkimmoduleprivate.h b/gtk/gtkimmoduleprivate.h
index ed469891d0..032a4782db 100644
--- a/gtk/gtkimmoduleprivate.h
+++ b/gtk/gtkimmoduleprivate.h
@@ -26,7 +26,7 @@ G_BEGIN_DECLS
 
 void           gtk_im_module_ensure_extension_point  (void);
 GtkIMContext * _gtk_im_module_create                 (const char *context_id);
-const gchar  * _gtk_im_module_get_default_context_id (void);
+const gchar  * _gtk_im_module_get_default_context_id (GdkDisplay *display);
 
 G_END_DECLS
 
diff --git a/gtk/gtkimmulticontext.c b/gtk/gtkimmulticontext.c
index aae9b6d0ae..e075adfbc3 100644
--- a/gtk/gtkimmulticontext.c
+++ b/gtk/gtkimmulticontext.c
@@ -244,11 +244,17 @@ static const gchar *
 get_effective_context_id (GtkIMMulticontext *multicontext)
 {
   GtkIMMulticontextPrivate *priv = multicontext->priv;
+  GdkDisplay *display;
 
   if (priv->context_id_aux)
     return priv->context_id_aux;
 
-  return _gtk_im_module_get_default_context_id ();
+  if (priv->client_widget)
+    display = gtk_widget_get_display (priv->client_widget);
+  else
+    display = gdk_display_get_default ();
+
+  return _gtk_im_module_get_default_context_id (display);
 }
 
 static GtkIMContext *


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