Skip to content

Add glfwSetTextInputFocus()#11

Draft
ashie wants to merge 6 commits into
im-supportfrom
im-support-text-input-focus
Draft

Add glfwSetTextInputFocus()#11
ashie wants to merge 6 commits into
im-supportfrom
im-support-text-input-focus

Conversation

@ashie

@ashie ashie commented Jun 29, 2026

Copy link
Copy Markdown
Member

Add glfwSetTextInputFocus() mentioned in glfw#2130 (comment)

This PR is for internal review before merging it to im-support branch (PR #2130).

I've tested it on all platforms and works fine except Win32 with Wine.
Native Win32 is fine with MS-IME.
On Wine, it still shows the candidates windows of IM, but I think it's Wine's issue.
I confirmed this issue with Wine 9.0 & Proton 11.0.

Tested platforms:

  • Windows 11 + MS-IME
  • Wine 9.0
  • macOS 26.4.1
  • X11 + IBus (Ubuntu 24.04)
  • Wayland text-input-v3 (GNOME) + IBus (Ubuntu 24.04)
  • Wayland text-input-v1 (Weston) + Fcitx5

ashie added 6 commits June 21, 2026 17:02
Introduce glfwSetTextInputFocus(window, focused), internal state and a
platform hook for explicit application text input focus.

Track whether the application has explicitly called the API with
textInputFocusExplicit, so existing applications keep legacy platform
behavior until they opt into explicit text input focus.

This follows the text input focus direction from the IME support
discussions in #5 and #7, without changing
platform behavior yet.
Map explicit text input focus to XIM input context focus with XSetICFocus
and XUnsetICFocus.

On focus out, reset preedit through the existing X11 helper before
unsetting IC focus, preserving its conservative behavior.  Native FocusIn
only restores XIC focus when text input focus has not been explicitly
disabled.
When explicit text input focus is inactive, keep GLFW from processing its
own WM_IME_* composition, preedit, candidate and IME status paths while
preserving normal key input.

On Win32, gating GLFW message handling is not enough to prevent native IMM
candidate UI from appearing. Temporarily associate a NULL HIMC with the
window while explicit text input focus is out, then restore the saved HIMC
when focus returns.

Cancel and clear active preedit/candidate state as focus-out cleanup. After
restoring the HIMC, reapply the preedit cursor rectangle so candidate UI
uses the latest location.
When explicit text input focus is inactive, skip interpretKeyEvents and
send plain event characters through GLFW text input instead. This
prevents routing key events through NSTextInput composition while
preserving normal key input.

Applications that never call glfwSetTextInputFocus keep the previous
interpretKeyEvents behavior.

On focus out, discard marked text through the existing NSTextInputContext
reset path. Do not use TIS input source switching for this API.
Map explicit text input focus to text-input-v3 enable/disable and
text-input-v1 activate/deactivate.

When text input focus is inactive, avoid auto-enabling text input on
protocol enter and ignore stale text-input callbacks.  Applications
that never call glfwSetTextInputFocus keep the previous enter-time
activation behavior.

On focus out, reset local preedit state and send the available protocol
reset/disable requests.
Expose glfwSetTextInputFocus in the input_text test so IME and text input
focus behavior can be exercised independently.

The UI starts in compatibility mode, then shows explicit Focus In or
Focus Out after the toggle is used.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant