From c073a062b6ad0dfccdd83282fd7ac5e0f8870a19 Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Thu, 25 Apr 2019 12:13:21 +0800 Subject: [PATCH] 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. --- modules/input/gtkimcontextime.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/modules/input/gtkimcontextime.c b/modules/input/gtkimcontextime.c index 2b165e9fcd..5bc31c42db 100644 --- a/modules/input/gtkimcontextime.c +++ b/modules/input/gtkimcontextime.c @@ -845,6 +845,7 @@ gtk_im_context_ime_set_cursor_location (GtkIMContext *context, COMPOSITIONFORM cf; HWND hwnd; HIMC himc; + guint scale; g_return_if_fail (GTK_IS_IM_CONTEXT_IME (context)); @@ -860,10 +861,11 @@ gtk_im_context_ime_set_cursor_location (GtkIMContext *context, if (!himc) return; + scale = gdk_window_get_scale_factor (context_ime->client_window); get_window_position (context_ime->client_window, &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); @@ -1050,6 +1052,7 @@ gtk_im_context_ime_message_filter (GdkXEvent *xevent, { gint wx = 0, wy = 0; CANDIDATEFORM cf; + guint scale = gdk_window_get_scale_factor (context_ime->client_window); get_window_position (context_ime->client_window, &wx, &wy); /* FIXME! */ @@ -1062,17 +1065,17 @@ gtk_im_context_ime_message_filter (GdkXEvent *xevent, gdk_win32_window_get_impl_hwnd (gdk_window_get_toplevel (context_ime->client_window)); GetWindowRect (hwnd_top, &rc); - pt.x = wx; - pt.y = wy; + pt.x = wx * scale; + pt.y = wy * scale; ClientToScreen (hwnd_top, &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))