gtkimcontextime.c: Fix preedit window placement on HiDPI
authorChun-wei Fan <fanchunwei@src.gnome.org>
Sat, 19 Feb 2022 17:31:28 +0000 (18:31 +0100)
committerLuca Bacci <luca.bacci982@gmail.com>
Sat, 19 Feb 2022 17:31:28 +0000 (18:31 +0100)
We must also take the scaling factor into account for placing the IME
preedit window that is often used for Chinese and Japanese input on
Windows.

gtk/gtkimcontextime.c

index 5c9282b59d58f91e2c0f4e26bc355b244d6ad3d6..ad8045fb7bd0da18d3e85e050b45ed02a9f7804e 100644 (file)
@@ -771,6 +771,7 @@ gtk_im_context_ime_set_cursor_location (GtkIMContext *context,
   COMPOSITIONFORM cf;
   HWND hwnd;
   HIMC himc;
+  int scale;
 
   g_return_if_fail (GTK_IS_IM_CONTEXT_IME (context));
 
@@ -786,10 +787,11 @@ gtk_im_context_ime_set_cursor_location (GtkIMContext *context,
   if (!himc)
     return;
 
+  scale = gdk_surface_get_scale_factor (context_ime->client_surface);
   get_window_position (context_ime->client_surface, &wx, &wy);
   cf.dwStyle = CFS_POINT;
-  cf.ptCurrentPos.x = wx + context_ime->cursor_location.x;
-  cf.ptCurrentPos.y = wy + context_ime->cursor_location.y;
+  cf.ptCurrentPos.x = (wx + context_ime->cursor_location.x) * scale;
+  cf.ptCurrentPos.y = (wy + context_ime->cursor_location.y) * scale;
   ImmSetCompositionWindow (himc, &cf);
 
   ImmReleaseContext (hwnd, himc);
@@ -975,6 +977,7 @@ gtk_im_context_ime_message_filter (GdkWin32Display *display,
       {
         int wx = 0, wy = 0;
         CANDIDATEFORM cf;
+        int scale = gdk_surface_get_scale_factor (context_ime->client_surface);
 
         get_window_position (context_ime->client_surface, &wx, &wy);
         /* FIXME! */
@@ -986,17 +989,17 @@ gtk_im_context_ime_message_filter (GdkWin32Display *display,
           impl_hwnd =
             gdk_win32_surface_get_impl_hwnd (context_ime->client_surface);
           GetWindowRect (impl_hwnd, &rc);
-          pt.x = wx;
-          pt.y = wy;
+          pt.x = wx * scale;
+          pt.y = wy * scale;
           ClientToScreen (impl_hwnd, &pt);
-          wx = pt.x - rc.left;
-          wy = pt.y - rc.top;
+          wx = (pt.x - rc.left) / scale;
+          wy = (pt.y - rc.top) / scale;
         }
         cf.dwIndex = 0;
         cf.dwStyle = CFS_CANDIDATEPOS;
-        cf.ptCurrentPos.x = wx + context_ime->cursor_location.x;
-        cf.ptCurrentPos.y = wy + context_ime->cursor_location.y
-          + context_ime->cursor_location.height;
+        cf.ptCurrentPos.x = (wx + context_ime->cursor_location.x) * scale;
+        cf.ptCurrentPos.y = (wy + context_ime->cursor_location.y
+          + context_ime->cursor_location.height) * scale;
         ImmSetCandidateWindow (himc, &cf);
 
         if ((msg->lParam & GCS_COMPSTR))