Skip to content

RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process

Fix re-activating the input method after a window switch

vgxldd50e40ebf37
diff --git a/AGENTS.md b/AGENTS.md
index 0e667f7..48e652c 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -260,6 +260,12 @@ panel painting. The key rules:
Reset on focus loss or Ctrl/Alt, no repeat for a consumed key
(`willConsume`/`consumed`), `compose.preload` before a sandbox closes the
filesystem (PDF). `tests/dead_keys.py`.
+* **text-input-v3 (IMEs):** an app-side text-input client must send
+ `disable` + `commit` in its `leave` handler. The `enable` belongs to the
+ surface from `enter`; left enabled, the compositor sees no change when the
+ surface is entered again, no enable event reaches `input/text_input.zig`,
+ and the input method is never activated again — composition silently stops
+ after a window switch. `tests/editor.py`.
## Build and platform
diff --git a/src/editor/ime.zig b/src/editor/ime.zig
index 4146c5e..9e0c5e4 100644
--- a/src/editor/ime.zig
+++ b/src/editor/ime.zig
@@ -44,13 +44,24 @@ pub const Ime = struct {
self.commit.clearRetainingCapacity();
self.preedit.clearRetainingCapacity();
}
- fn event(_: *zwp.TextInputV3, ev: zwp.TextInputV3.Event, self: *Ime) void {
+ fn event(input: *zwp.TextInputV3, ev: zwp.TextInputV3.Event, self: *Ime) void {
switch (ev) {
.enter => {
self.entered = true;
self.revision = std.math.maxInt(usize);
},
.leave => {
+ // enable belongs to the surface from enter: disable it before
+ // dropping that surface, or the compositor still believes the
+ // input is enabled and a later enable/commit after re-entering
+ // changes nothing. No enable event then reaches the relay, so
+ // the input method is never activated again (window switching
+ // silently stops composition).
+ if (self.enabled) {
+ input.disable();
+ input.commit();
+ self.serial +%= 1;
+ }
self.waiting_for_done = false;
self.entered = false;
self.enabled = false;
diff --git a/tests/editor.py b/tests/editor.py
index 717aade..0fccfc5 100644
--- a/tests/editor.py
+++ b/tests/editor.py
@@ -315,6 +315,33 @@ def run():
im_send("commit-only")
key(31, ctrl=True)
wait_for(lambda: second.read_text() == "hcomposedfinalo", "IME replaces preedit")
+
+ # Losing keyboard focus must disable the text input. Left
+ # enabled, the compositor sees no state change when the surface
+ # is entered again and never re-activates the input method:
+ # composition silently stops for every window switch.
+ def ime_events(name):
+ return sum(1 for line in im_log.read_text().splitlines() if line == name or line.startswith(name + " "))
+
+ key(107, ctrl=True) # end of document, before composition
+ before_switch = second.read_text()
+ activations = ime_events("activate")
+ deactivations = ime_events("deactivate")
+ dones = ime_events("im-done")
+ ipc.focus_window(files["id"])
+ wait_for(lambda: ime_events("deactivate") > deactivations, "IME was not deactivated by focus loss")
+ # The deactivation's done must not be mistaken for the state
+ # the re-activated input receives.
+ wait_for(lambda: ime_events("im-done") > dones, "IME deactivation did not complete")
+ dones = ime_events("im-done")
+ ipc.focus_window(editor()["id"])
+ wait_for(lambda: ime_events("activate") > activations, "editor did not re-activate the IME after focus returned")
+ wait_for(lambda: ime_events("im-done") > dones, "IME state did not arrive after focus returned")
+ im_send("commit-only")
+ key(31, ctrl=True)
+ wait_for(lambda: second.read_text() == before_switch + "final", "IME commit after focus returned")
+ print("text-input-v3 re-activates after a window switch", flush=True)
+
im.terminate()
im.wait(timeout=5)
print("text-input-v3 composition", flush=True)