From 8702a09333934ca8e52e9e1c0119889c8ef14799 Mon Sep 17 00:00:00 2001 From: wjian23 Date: Fri, 22 Dec 2023 03:44:30 +0800 Subject: [PATCH] On Windows, fix IME area not working --- CHANGELOG.md | 1 + src/platform_impl/windows/ime.rs | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e728d1de..3e11a4f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ Unreleased` header. - On Web, remove queuing fullscreen request in absence of transient activation. - On Web, fix setting cursor icon overriding cursor visibility. - On Wayland, fix resize being sent on focus change. +- On Windows, fix `set_ime_cursor_area`. # 0.29.4 diff --git a/src/platform_impl/windows/ime.rs b/src/platform_impl/windows/ime.rs index 09db3ce4..fc480469 100644 --- a/src/platform_impl/windows/ime.rs +++ b/src/platform_impl/windows/ime.rs @@ -10,9 +10,9 @@ use windows_sys::Win32::{ UI::{ Input::Ime::{ ImmAssociateContextEx, ImmGetCompositionStringW, ImmGetContext, ImmReleaseContext, - ImmSetCandidateWindow, ATTR_TARGET_CONVERTED, ATTR_TARGET_NOTCONVERTED, CANDIDATEFORM, - CFS_EXCLUDE, GCS_COMPATTR, GCS_COMPSTR, GCS_CURSORPOS, GCS_RESULTSTR, IACE_CHILDREN, - IACE_DEFAULT, + ImmSetCandidateWindow, ImmSetCompositionWindow, ATTR_TARGET_CONVERTED, + ATTR_TARGET_NOTCONVERTED, CANDIDATEFORM, CFS_EXCLUDE, CFS_POINT, COMPOSITIONFORM, + GCS_COMPATTR, GCS_COMPSTR, GCS_CURSORPOS, GCS_RESULTSTR, IACE_CHILDREN, IACE_DEFAULT, }, WindowsAndMessaging::{GetSystemMetrics, SM_IMMENABLED}, }, @@ -124,7 +124,7 @@ impl ImeContext { left: x, top: y, right: x + width, - bottom: y - height, + bottom: y + height, }; let candidate_form = CANDIDATEFORM { dwIndex: 0, @@ -132,8 +132,16 @@ impl ImeContext { ptCurrentPos: POINT { x, y }, rcArea: rc_area, }; + let composition_form = COMPOSITIONFORM { + dwStyle: CFS_POINT, + ptCurrentPos: POINT { x, y: y + height }, + rcArea: rc_area, + }; - unsafe { ImmSetCandidateWindow(self.himc, &candidate_form) }; + unsafe { + ImmSetCompositionWindow(self.himc, &composition_form); + ImmSetCandidateWindow(self.himc, &candidate_form); + } } pub unsafe fn set_ime_allowed(hwnd: HWND, allowed: bool) {