Cocoa: Bypass text input system when unfocused

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.

This builds on the Cocoa input method work from clear-code/glfw#7.
This commit is contained in:
Takuro Ashie 2026-06-21 16:29:59 +09:00
parent a8819c7924
commit 148ff80572
2 changed files with 11 additions and 2 deletions

View file

@ -89,6 +89,7 @@ video tutorials.
- GeO4d
- Marcus Geelnard
- Gegy
- ghostflyby
- ghuser404
- Charles Giessen
- Ryan C. Gordon

View file

@ -573,7 +573,14 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
if (![self hasMarkedText])
_glfwInputKey(window, key, [event keyCode], GLFW_PRESS, mods);
[self interpretKeyEvents:@[event]];
if (!window->textInputFocusInitialized || window->textInputFocus)
[self interpretKeyEvents:@[event]];
else
{
NSString* characters = [event characters];
if (characters)
[self insertText:characters replacementRange:[self selectedRange]];
}
}
- (void)flagsChanged:(NSEvent *)event
@ -2039,7 +2046,8 @@ void _glfwResetPreeditTextCocoa(_GLFWwindow* window)
void _glfwSetTextInputFocusCocoa(_GLFWwindow* window, GLFWbool focused)
{
// TODO: Add a safe NSTextInputContext mapping without changing TIS behavior.
if (!focused)
_glfwResetPreeditTextCocoa(window);
}
void _glfwSetIMEStatusCocoa(_GLFWwindow* window, int active)