lifecycle: detach IME from the game window via ImmAssociateContextEx for CJK Windows #521

Open
aowu wants to merge 0 commits from aowu/Darner:pr/ime-cjk-detach into Main
First-time contributor

Problem

When DARNER_IME_ENGLISH=1 is enabled, english_input() currently searches GetKeyboardLayoutList for the en-US keyboard layout (0x0409_0409) and calls ActivateKeyboardLayout.

On CJK Windows installations (e.g. zh-CN with Microsoft Pinyin or Sogou IME, ja-JP, ko-KR), many users do not have a separate en-US keyboard layout installed—they toggle English/CJK mode inside the IME itself. As a result, 0x0409_0409 is not found, english_input() leaves the IME attached, and pressing Shift + WASD still pops up the IME candidate window and eats gameplay input.

Fix

Call imm32.dll::ImmAssociateContextEx(hwnd, NULL, 0) on window creation and WM_SETFOCUS when DARNER_IME_ENGLISH is enabled, while keeping the existing en-US layout activation fallback.

  • Only detaches the IME context from the game's own HWND; other Windows applications are unaffected.
  • Works in both windowed and fullscreen modes across Microsoft Pinyin, Sogou, and other CJK IMEs without requiring an extra Windows keyboard layout.

Verification

  • cargo test -p darner-hle --lib lifecycle passes (22/22).
  • Verified in-game on Chinese Windows 11 (Microsoft Pinyin & Sogou IME): Shift + WASD no longer triggers IME composition or candidate boxes, while IME remains normal in other apps.
### Problem When `DARNER_IME_ENGLISH=1` is enabled, `english_input()` currently searches `GetKeyboardLayoutList` for the `en-US` keyboard layout (`0x0409_0409`) and calls `ActivateKeyboardLayout`. On CJK Windows installations (e.g. zh-CN with Microsoft Pinyin or Sogou IME, ja-JP, ko-KR), many users do not have a separate `en-US` keyboard layout installed—they toggle English/CJK mode inside the IME itself. As a result, `0x0409_0409` is not found, `english_input()` leaves the IME attached, and pressing `Shift` + `WASD` still pops up the IME candidate window and eats gameplay input. ### Fix Call `imm32.dll::ImmAssociateContextEx(hwnd, NULL, 0)` on window creation and `WM_SETFOCUS` when `DARNER_IME_ENGLISH` is enabled, while keeping the existing `en-US` layout activation fallback. - Only detaches the IME context from the game's own `HWND`; other Windows applications are unaffected. - Works in both windowed and fullscreen modes across Microsoft Pinyin, Sogou, and other CJK IMEs without requiring an extra Windows keyboard layout. ### Verification - `cargo test -p darner-hle --lib lifecycle` passes (22/22). - Verified in-game on Chinese Windows 11 (Microsoft Pinyin & Sogou IME): `Shift` + `WASD` no longer triggers IME composition or candidate boxes, while IME remains normal in other apps.
Owner

Test needed — commit 7d11aa28; what to check: the change described above

Evidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture.

Reply testing to take this run; it's free again after 24 h with no results.

**Test needed** — commit `7d11aa28`; what to check: the change described above Evidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture. Reply `testing` to take this run; it's free again after 24 h with no results.
This branch is already included in the target branch. There is nothing to merge.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'pr/ime-cjk-detach:aowu-pr/ime-cjk-detach'
git switch 'aowu-pr/ime-cjk-detach'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'Main'
git merge --no-ff 'aowu-pr/ime-cjk-detach'
git switch 'aowu-pr/ime-cjk-detach'
git rebase 'Main'
git switch 'Main'
git merge --ff-only 'aowu-pr/ime-cjk-detach'
git switch 'aowu-pr/ime-cjk-detach'
git rebase 'Main'
git switch 'Main'
git merge --no-ff 'aowu-pr/ime-cjk-detach'
git switch 'Main'
git merge --squash 'aowu-pr/ime-cjk-detach'
git switch 'Main'
git merge --ff-only 'aowu-pr/ime-cjk-detach'
git switch 'Main'
git merge 'aowu-pr/ime-cjk-detach'
git push origin 'Main'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
TrustNo1/Darner!521
No description provided.