Win32 IME: Keep track of the client widget
authorLuca Bacci <luca.bacci982@gmail.com>
Mon, 21 Feb 2022 11:39:52 +0000 (12:39 +0100)
committerLuca Bacci <luca.bacci982@gmail.com>
Mon, 21 Feb 2022 14:53:13 +0000 (15:53 +0100)
gtk/gtkimcontextime.c
gtk/gtkimcontextime.h

index 6a423fca9dd44937f4f11fd8f547fb68a02c1441..1fe4745fe5b5cefcc5c60c4b36e748135ae37583 100644 (file)
@@ -156,6 +156,7 @@ gtk_im_context_ime_class_init (GtkIMContextIMEClass *class)
 static void
 gtk_im_context_ime_init (GtkIMContextIME *context_ime)
 {
+  context_ime->client_widget          = NULL;
   context_ime->client_surface         = NULL;
   context_ime->use_preedit            = TRUE;
   context_ime->preediting             = FALSE;
@@ -272,6 +273,7 @@ gtk_im_context_ime_set_client_widget (GtkIMContext *context,
       gtk_im_context_ime_focus_out (context);
     }
 
+  context_ime->client_widget = widget;
   context_ime->client_surface = client_surface;
 }
 
@@ -825,7 +827,6 @@ static void
 gtk_im_context_ime_set_preedit_font (GtkIMContext *context)
 {
   GtkIMContextIME *context_ime;
-  GtkWidget *widget = NULL;
   HWND hwnd;
   HIMC himc;
   HKL ime = GetKeyboardLayout (0);
@@ -839,11 +840,8 @@ gtk_im_context_ime_set_preedit_font (GtkIMContext *context)
   g_return_if_fail (GTK_IS_IM_CONTEXT_IME (context));
 
   context_ime = GTK_IM_CONTEXT_IME (context);
-  if (!context_ime->client_surface)
-    return;
 
-  widget = GTK_WIDGET (gtk_native_get_for_surface (context_ime->client_surface));
-  if (!widget)
+  if (!(context_ime->client_widget && context_ime->client_surface))
     return;
 
   hwnd = gdk_win32_surface_get_impl_hwnd (context_ime->client_surface);
@@ -852,7 +850,7 @@ gtk_im_context_ime_set_preedit_font (GtkIMContext *context)
     return;
 
   /* set font */
-  pango_context = gtk_widget_get_pango_context (widget);
+  pango_context = gtk_widget_get_pango_context (context_ime->client_widget);
   if (!pango_context)
     goto ERROR_OUT;
 
@@ -887,7 +885,7 @@ gtk_im_context_ime_set_preedit_font (GtkIMContext *context)
       lang = ""; break;
     }
 
-  font_desc = gtk_css_style_get_pango_font (gtk_style_context_lookup_style (gtk_widget_get_style_context (widget)));
+  font_desc = gtk_css_style_get_pango_font (gtk_style_context_lookup_style (gtk_widget_get_style_context (context_ime->client_widget)));
 
   if (lang[0])
     {
index 8621bc6dfe4c32185a9f71ee497d9a455418e2bc..27e09f2426dc6a8d78ac9b88952e159fb71fb6f2 100644 (file)
@@ -36,6 +36,7 @@ struct _GtkIMContextIME
 {
   GtkIMContext object;
 
+  GtkWidget *client_widget;
   GdkSurface *client_surface;
   guint use_preedit : 1;
   guint preediting : 1;