From 44ec6b2467a452cdef5d779df8a83d5545da7ef5 Mon Sep 17 00:00:00 2001 From: Takuro Ashie Date: Sun, 21 Jun 2026 16:25:48 +0900 Subject: [PATCH] X11: Implement text input focus 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. --- src/x11_window.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/x11_window.c b/src/x11_window.c index d5979829..645637a5 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -1961,8 +1961,11 @@ static void processEvent(XEvent *event) else if (window->cursorMode == GLFW_CURSOR_CAPTURED) captureCursor(window); - if (window->x11.ic) + if (window->x11.ic && + (!window->textInputFocusInitialized || window->textInputFocus)) + { XSetICFocus(window->x11.ic); + } _glfwInputWindowFocus(window, GLFW_TRUE); return; @@ -3431,6 +3434,18 @@ void _glfwSetIMEStatusX11(_GLFWwindow* window, int active) void _glfwSetTextInputFocusX11(_GLFWwindow* window, GLFWbool focused) { + XIC ic = window->x11.ic; + + if (!ic) + return; + + if (focused) + XSetICFocus(ic); + else + { + _glfwResetPreeditTextX11(window); + XUnsetICFocus(ic); + } } int _glfwGetIMEStatusX11(_GLFWwindow* window)