[gtk: 1/2] gtkimcontextime.c: Fix preedit window placement on HiDPI




commit c6ce05b78275498e4acf733549d8cf8d583c7a1a
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Sat Feb 19 18:31:28 2022 +0100

    gtkimcontextime.c: Fix preedit window placement on HiDPI
    
    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 | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)
---
diff --git a/gtk/gtkimcontextime.c b/gtk/gtkimcontextime.c
index 5c9282b59d..ad8045fb7b 100644
--- a/gtk/gtkimcontextime.c
+++ b/gtk/gtkimcontextime.c
@@ -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))


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