Skip to content

Fix/win32 ime setcontext lparam#4485

Open
Touma-Kazusa2 wants to merge 2 commits intorust-windowing:masterfrom
Touma-Kazusa2:fix/win32-ime-setcontext-lparam
Open

Fix/win32 ime setcontext lparam#4485
Touma-Kazusa2 wants to merge 2 commits intorust-windowing:masterfrom
Touma-Kazusa2:fix/win32-ime-setcontext-lparam

Conversation

@Touma-Kazusa2
Copy link

@Touma-Kazusa2 Touma-Kazusa2 commented Feb 13, 2026

• ## Summary

Fix Win32 IME UI flag masking in the WM_IME_SETCONTEXT path.

Problem

For WM_IME_SETCONTEXT, IME UI visibility flags (including ISC_SHOWUICOMPOSITIONWINDOW) are carried in lParam.

The current code masks ISC_SHOWUICOMPOSITIONWINDOW on wParam, so the intended flag is not actually cleared.

Reproduction / Observed behavior (Windows + Microsoft Pinyin)

  • On first IME input after app launch, an extra composition/preedit UI may appear.
  • After window focus is lost and regained, the first IME input can reproduce the same issue.
  • Once the current composition is committed (Enter/candidate selection) or fully canceled (delete all preedit text), the
    extra UI disappears.
  • Subsequent IME input in the same focus cycle is typically normal.

Behavioral linkage (cause -> effect)

  1. WM_IME_SETCONTEXT is the context-(re)activation point (startup first input / first input after refocus).
  2. In this message, IME UI visibility control is carried by lParam (ISC_* flags).
  3. winit intends to suppress the default IMM composition UI in this path before forwarding to DefWindowProcW.
  4. Previously, the mask was applied to wParam, so the intended suppression did not actually affect the UI-flag carrier
    (lParam).
  5. This can surface as an extra IME composition/preedit box when context is activated.
  6. Commit/cancel ends the current composition session (e.g. WM_IME_ENDCOMPOSITION), so that extra box disappears with
    the ended session.
  7. In the same focus cycle, WM_IME_SETCONTEXT is usually not re-entered, so the faulty path is not retriggered until the
    next context reactivation.

Change

Mask ISC_SHOWUICOMPOSITIONWINDOW on lParam (not wParam) before forwarding to DefWindowProcW.

Why changing lParam here is expected

This does not mutate the OS message source. Windows still provides the original wParam/lParam for WM_IME_SETCONTEXT.

Per Microsoft docs, apps that handle composition display should clear ISC_SHOWUICOMPOSITIONWINDOW in lParam before
calling DefWindowProc.

  • Existing code already intends to hide IME-drawn composition UI in WM_IME_SETCONTEXT.
  • The issue is operand mismatch: ISC_SHOWUICOMPOSITIONWINDOW is a lParam flag, but the mask was applied to wParam.
  • This PR keeps the same intent and fixes only the target operand (wParam -> lParam) before forwarding to DefWindowProcW.
  • So this is a correctness bugfix, not a behavior-policy change.

References

Scope

Windows backend only (winit-win32).

Validation

  • cargo test -p winit-win32
  • Downstream manual verification (Windows):
    • Reproduced with bevy 0.18 example: examples/input/text_input.rs (Microsoft Pinyin).
    • Before patch: behavior matched the reproduction notes above.
    • After patch: the above behavior is no longer reproduced.

Related

Checklist

  • Tested on all platforms changed (Windows)
  • Added an entry to changelog for this user-visible change
  • Updated documentation (N/A: no API/documentation surface change)
  • Added/updated example (N/A: bugfix in existing Win32 path)

@madsmtm madsmtm added B - bug Dang, that shouldn't have happened DS - win32 Affects the Win32/Windows backend labels Feb 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

B - bug Dang, that shouldn't have happened DS - win32 Affects the Win32/Windows backend

Development

Successfully merging this pull request may close these issues.

2 participants