Skip to content

X11: restore IME focus after replacing an input context - #4727

Open
shim9610 wants to merge 2 commits into
rust-windowing:masterfrom
shim9610:fix/x11-xic-focus-handoff
Open

shim9610 wants to merge 2 commits into
rust-windowing:masterfrom
shim9610:fix/x11-xic-focus-handoff

Conversation

@shim9610

@shim9610 shim9610 commented Oct 2, 2026

Copy link
Copy Markdown

Enabling IME on an already-focused X11 window replaces its input context without transferring focus to the replacement. Since the window itself remains focused, no new focus event arrives to correct this.

With IBus, this can leave the replacement context unfocused until the first key event and cause the candidate window to appear at an incorrect position, even though the application supplied the correct cursor area.

Return the context replacement result from Ime::set_ime_allowed, then focus the active window's final replacement after draining pending IME requests. This avoids activating intermediate contexts that are immediately replaced by subsequent requests.

Context replacement and IME event ordering are preserved. Unchanged requests do not schedule focus, and a failed final replacement cancels pending focus. Inactive windows are not focused, and the cursor-area equality cache is unchanged.

Validation

Tested against Winit 8b5f46d4 and IBus d464316d, which already includes the X11 candidate-object selection fix, using a private Xvfb/Openbox session.

  • Reproduced the original failure and verified correct candidate placement with a fixed cursor area after the change.
  • Checked late/startup activation, reactivation, inactive windows, multiple windows, and injected context-creation failures.
  • Exercised rapid toggles, including during preedit. For 200 replacements in one batch, GDB recorded 200 context creations/destructions and one XSetICFocus call.
  • Verified rapid native window and logical input-field movement. Native focus transfers remain individually processed.
  • Formatting, X11 build checks, and Clippy passed. X11 tests: 18 passed, 7 ignored.

Cross-platform CI is pending.

Checklist

  • Tested on all platforms changed (X11).
  • Added an entry to the changelog module.
  • Documentation: no public API changes; the behavior fix is described in the changelog.
  • Examples: no example changes required for this bug fix; validated with a local IME reproducer.

@shim9610
shim9610 requested a review from kchibisov as a code owner October 2, 2026 22:24

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant