Experimental IBus support for X11 backend built on top of the IME API#10
Experimental IBus support for X11 backend built on top of the IME API#10ashie wants to merge 6 commits into
Conversation
New experimental build switchesI've added two more optional build switches for experiments with applications that already use GLFW with glfw#2130. These options are not intended as an upstream API proposal. They are provided to make it easier to evaluate the IBus backend with existing applications and prebuilt GLFW binaries.
GLFW_IME_MODE_AS_TEXT_INPUT_FOCUS
|
4acec7d to
7d530be
Compare
|
I've also import soft fullscreen patch in im-support-fullscreen branch described in glfw#2130 (comment) to work with Minecraft. Without this patch, Minecraft causes an exception.
When I enable this option, I can't use IM on both X11 and Wayland. On the other hand, when I use this branch without $ cmake -B build \
-D GLFW_EMBED_IBUS_MODULE=ON \
-D BUILD_SHARED_LIBS=ON
$ cmake --build build --target glfwThen install it as described in Mincraft Wiki |
3ad5ce3 to
f266d4a
Compare
|
To prove the text-input-focus concept described in glfw#2130 (comment) and implemented in #11, I've added a mode to implicitly use this feature. It intends to work with Minecraft as a representative application. To work well with it, some required features have also been added in this branch. These features are intentionally excluded from glfw#2130 because each of them is separate issues from the addition of the basic IME API (Please see You can enable it by a build flag e.g. for GNU/Linux) $ cmake -B build \
-D GLFW_EMBED_IBUS_MODULE=ON \
-D GLFW_IME_MODE_AS_TEXT_INPUT_FOCUS=ON \
-D BUILD_SHARED_LIBS=ON
$ cmake --build build --target glfwe.g. for macOS) $ cmake -B build \
-D GLFW_IME_MODE_AS_TEXT_INPUT_FOCUS=ON \
-D BUILD_SHARED_LIBS=ON
$ cmake --build build --target glfwWindows isn't confirmed yet. Then add |
Add a private X11 IME module ABI and an experimental glfw-ibus.so backend for feasibility testing. The module owns D-Bus communication, IBus input contexts and its worker thread, while GLFW drains queued IME events on the main thread without modifying the event loop architecture. The prototype handles ProcessKeyEvent, CommitText, UpdatePreeditText, focus changes, reset, IME status signals and cursor location updates. Key events are passed to IBus with the keysym translated from the X key event so printable shifted keys such as Shift+1 reach IBus as the expected key value. IBus preedit text, caret position and attribute ranges are mapped onto GLFW preedit text, block sizes, focused block and caret index. Candidate window placement uses SetCursorLocation with X11 root-window coordinates, including the startup/focus ordering workaround for the first candidate window. This is a research prototype, not an upstream-ready feature. It keeps GLFW_IME_DEBUG instrumentation and documentation for measuring latency, timeouts and late IBus replies or text signals.
Keep XFilterEvent as the suppressor for the XIM path, but do not call it before the experimental IME module sees KeyPress events. When the module reports a key as handled, return before normal GLFW key and character processing. This gives the IME module path the same kind of duplicate-input suppression that XFilterEvent provides for the XIM path, while keeping the XIM behavior unchanged. This effectively extends the duplicate-input suppression addressed by PR glfw#1972 to the experimental IME module path.
Map glfwSetTextInputFocus to the experimental X11 IME module path. When text input focus is enabled for a focused X11 window, send FocusIn to the module so IBus resumes routing text input. When it is disabled, reset composition and send FocusOut, keeping GLFW window focus separate from the text input focus abstraction. Also gate the module KeyPress path on GLFW's text input focus state so FocusOut actually stops routing input through IBus. Applications that never opt into explicit text input focus keep the legacy behavior. Document the prototype mapping without adding a new module ABI entry.
Document the current state of the experimental X11 IBus module after adding text input focus gating and richer preedit handling. The prototype now maps IBus caret and attribute ranges to GLFW preedit state, gates ProcessKeyEvent on explicit text input focus, and is close to usable for application testing while still remaining experimental.
Add two switches for game/application compatibility testing. GLFW_INFER_TEXT_INPUT_FOCUS infers text input focus from legacy IME and cursor input state, and also acts as the runtime override environment variable. This lets applications that already toggle GLFW_IME or cursor mode use the more portable text-input-focus semantics without code changes. In this mode, cursor mode changes are treated as text input focus hints. GLFW keeps the application-requested text input focus state separate from the effective platform focus, so cursor-disabled gameplay can suppress text input while cursor-normal text entry can re-enable it. This also helps applications that switch between gameplay and text entry with cursor mode only. glfwGetInputMode(GLFW_IME) keeps reporting the native IME status until the inference path initializes text input focus state for the window. After that it returns the application-requested text input focus state, preserving the old query behavior for applications that never use the compatibility mode. GLFW_EMBED_IBUS_MODULE builds the IBus backend into the X11 GLFW library. The embedded backend is used when GLFW_IM_MODULE is not set, while GLFW_IM_MODULE can still override it with an external module.
Add a new window hint: `GLFW_SOFT_FULLSCREEN`. This is especially necessary for the IME(Input Method Editor/Engine) to display properly on the fullscreen window. **Win32** By default, the fullscreen window is a strong exclusive exceeding HWND_TOPMOST and it doen't display OS notifications such as the sound volumn changed. This hint enables to display other views poping up on the fullscreen window. This can also effect transparency to fullscreen. **macOS** By default, the fullscreen window is exclusive. This hint uses macOS's default fullscreen (the behavior of the green button on the window's header). We don't need `monitor` in this mode, so it is not used. Specifying `monitor` in `glfwCreateWindow` makes window fullscreened, but the value is not used inside. The args of `glfwSetWindowMonitor` are not used except for `window` and the function just toggles the fullscreened state. These specifications have been made so that we can use this mode as similar to the normal default mode as possible. **X11** This hint manages XProperty: `NET_WM_BYPASS_COMPOSITOR`. By default, the compositing of the window is disabled to improve rendering performance. However, this can cause problems with other views poping up on the window, such as IME. This hint enables the compositing and the views poping up on the fullscreen to be displayed correctly.
I've renamed it to e.g. for GNU/Linux) $ cmake -B build \
-D GLFW_EMBED_IBUS_MODULE=ON \
-D GLFW_INFER_TEXT_INPUT_FOCUS=ON \
-D BUILD_SHARED_LIBS=ON
$ cmake --build build --target glfwe.g. for macOS) $ cmake -B build \
-D GLFW_INFER_TEXT_INPUT_FOCUS=ON \
-D BUILD_SHARED_LIBS=ON
$ cmake --build build --target glfwWindows isn't confirmed yet. Please add Note that this mode makes GLFW infer the text-input-focus state that should ideally be managed explicitly by the application. Because of that, the inference may fail for some transitions, such as the first time Minecraft enters chat or command input, and the IME may not be enabled for that initial attempt. In my testing, subsequent text input attempts work as expected. |
|
From glfw#2130 (comment)
Thanks, I've also confirmed that it doesn't work on Ubuntu 26.04 (using IBus). My current environment is Ubuntu 24.04, this branch works well on it. I'll investigate the issue later... |
This PR is an experiment built on top of the IME API introduced by PR #2130: Add IME support for each platform.
One motivation for this work is that the traditional X11 XIM protocol is relatively limited compared to modern IME frameworks and can make it difficult to provide functionality comparable to IME implementations available on other platforms.
While XIM remains useful as a baseline solution, as GLFW's IME support evolves, it may be desirable to investigate alternatives that can expose richer IME functionality on X11.
The goal of this experiment is therefore not to propose IBus support for GLFW itself, but to evaluate whether the abstractions introduced by PR glfw#2130 are flexible enough to support an alternative X11 IME backend without modifying the GLFW event loop.
The prototype uses:
and currently supports:
on X11.
This implementation should be viewed as a research prototype rather than an upstream proposal.
See docs/ime-ibus-prototype.md for architecture details, design rationale, limitations and future work.
Additional prerequisites
Build:
Run demo:
$ GLFW_IM_MODULE=$PWD/build/src/glfw-ibus.so ./build/tests/input_text