RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process
Files: disable text input when the window loses focus
vgxl023a1831e72b
diff --git a/src/files/AGENTS.md b/src/files/AGENTS.mdindex f0cd9cb..f00a239 100644--- a/src/files/AGENTS.md+++ b/src/files/AGENTS.md@@ -61,7 +61,11 @@ selection and the caret rectangle, applies delete + commit to the active`renderEditor` to draw. Re-enable and drop preedit when the target fieldchanges; a `done` applies only when its serial and the advertised field(cursor, anchor, text revision) still match. Terminal commits go to the PTY-through `ft_key`, never through paste.+through `ft_key`, never through paste. The `enable` belongs to the surface+from `enter`: `leave` sends `disable` + `commit` before clearing the local+state, or the compositor keeps the input enabled, sees no change when the+surface is entered again, and the input method is never re-activated — IME+composition silently stops after a window switch.## File types and associationsdiff --git a/src/files/ime.zig b/src/files/ime.zigindex ef75642..74ae029 100644--- a/src/files/ime.zig+++ b/src/files/ime.zig@@ -87,10 +87,21 @@ pub const Ime = struct {if (app.focus == .terminal) return if (app.terminal.visible and app.terminal.session != null) .terminal else .none;return if (app.activeEditor() != null) .editor else .none;}- 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,.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.entered = false;self.enabled = false;self.clear();diff --git a/tests/files_ime.py b/tests/files_ime.pyindex 6ba81f8..8441c32 100644--- a/tests/files_ime.py+++ b/tests/files_ime.py@@ -24,6 +24,7 @@ def run():docs = home / "Documents" / "文档"docs.mkdir(parents=True)(docs / "中文.txt").write_text("中文内容")+ (home / "另一个").mkdir()(home / "alpha.txt").write_text("alpha")from input_protocols import compile_client@@ -136,6 +137,44 @@ def run():assert not (docs / "中文.txt").exists()print("PASS: text-input-v3 composition in the location bar, search box and rename dialog")+ # 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 ime_text().splitlines() if line == name or line.startswith(name + " "))++ advertised = ime_text().count("surround " + str(docs))+ key(38, ctrl=True) # Ctrl+L: the location bar takes composition again+ wait_for(lambda: ime_text().count("surround " + str(docs)) > advertised,+ "location bar was not advertised to the IME again")+ activations = ime_events("activate")+ deactivations = ime_events("deactivate")+ dones = ime_events("im-done")+ calculator_log = (tmp / "rediwm-calculator.log").open("w")+ calculator = subprocess.Popen([str(ROOT / "zig-out/bin/rediwm-calculator")], env=env,+ stdout=calculator_log, stderr=calculator_log)+ calculator_log.close()+ clients.append(calculator)+ calculator_window = wait_for(+ lambda: next((w for w in ipc.get_windows() if w["app_id"] == "rediwm-calculator"), None),+ "calculator did not map")+ ipc.focus_window(calculator_window["id"])+ wait_for(lambda: ime_events("deactivate") > deactivations,+ "IME was not deactivated when Files lost focus")+ # 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(win["id"])+ wait_for(lambda: ime_events("activate") > activations,+ "Files 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")+ ime_send("commit-text " + str(home / "另一个"))+ key(28)+ title("另一个")+ print("PASS: the input method is re-activated after focus returns")+# The terminal drawer keeps its own composition path: the# commit is typed into the PTY, not pasted or shell syntax.before = ime_surrounds()