RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process
fix(ime): place candidate popups at the cursor rectangle sent after enable
vgxld8affa961b39
diff --git a/src/input/AGENTS.md b/src/input/AGENTS.mdindex a3575bc..3d7417d 100644--- a/src/input/AGENTS.md+++ b/src/input/AGENTS.md@@ -17,7 +17,9 @@the grab already received still reach it, and the IM's virtual keyboardnever counts as a physical modifier source (it only echoes forwardedstate). Lock/auth reject virtual input. IPC `GetTextInput` never returns- text.+ text. Candidate popups follow the client's committed cursor rectangle:+ wlroots' `active_features` only snapshots the enabling commit, so a+ rectangle sent later (Chromium's order) needs `cursor_rectangle_seen`.* **Layouts:** layout-zero fallback is for binding lookup only; text uses theactive XKB state.* **Input sources** (`input_sources.zig`, `input_sources/`): the config'sdiff --git a/src/input/text_input.zig b/src/input/text_input.zigindex c45083f..da825a2 100644--- a/src/input/text_input.zig+++ b/src/input/text_input.zig@@ -168,6 +168,10 @@ const TextInput = struct {relay: *Self,input: *wlr.TextInputV3,link: wl.list.Link = undefined,+ /// A commit used `set_cursor_rectangle`. `active_features` is a snapshot of+ /// the enabling commit, and clients such as Chromium send the rectangle in+ /// a later one.+ cursor_rectangle_seen: bool = false,enable: wl.Listener(void) = .init(enabled),disable: wl.Listener(void) = .init(disabled),commit: wl.Listener(void) = .init(committed),@@ -192,6 +196,7 @@ const TextInput = struct {fn committed(listener: *wl.Listener(void)) void {const self: *TextInput = @fieldParentPtr("commit", listener);+ if (self.input.current.features.cursor_rectangle) self.cursor_rectangle_seen = true;if (self.relay.active == self and self.input.current_enabled) self.relay.sendState();}@@ -383,7 +388,8 @@ pub fn updatePopups(self: *Self) void {if (self.server.locker != null or self.server.polkit_dialog != null or self.server.switcher.active() or self.server.world.overview.active() orshell.open_start_menu != null or shell.open_wifi != null or shell.open_battery != null or shell.open_calendar != null or shell.open_power_menu != null or(if (shell.open_control_center) |cc| cc.hasKeyboardFocus() else false)) break :visible false;- const input = (self.active orelse break :visible false).input;+ const active = self.active orelse break :visible false;+ const input = active.input;const surface = input.focused_surface orelse break :visible false;if (!surface.mapped or !popup.popup.surface.mapped) break :visible false;const node = surfaceNode(&self.server.nodes.tree, surface) orelse break :visible false;@@ -415,7 +421,9 @@ pub fn updatePopups(self: *Self) void {y = layout.y;scale *= self.server.world.camera.zoom();} else if (wlr.LayerSurfaceV1.tryFromWlrSurface(surface.getRootSurface()) == null) break :visible false;- const rect = if (input.active_features.cursor_rectangle) input.current.cursor_rectangle else wlr.Box{ .x = 0, .y = 0, .width = surface.current.width, .height = surface.current.height };+ // `active_features` is a snapshot of the enabling commit's features,+ // so a client may have sent the rectangle afterwards (Chromium does).+ const rect = if (active.cursor_rectangle_seen) input.current.cursor_rectangle else wlr.Box{ .x = 0, .y = 0, .width = surface.current.width, .height = surface.current.height };// Rectangle coordinates are client-controlled signed 32-bit values.// Zoom and adding the scene origin can exceed that range.const rx: i64 = @intFromFloat(@round(x + @as(f64, @floatFromInt(rect.x)) * scale));diff --git a/tests/input_protocol_client.c b/tests/input_protocol_client.cindex 5e0cc1c..aebd7ec 100644--- a/tests/input_protocol_client.c+++ b/tests/input_protocol_client.c@@ -27,6 +27,10 @@ static void enable_input(void) {zwp_text_input_v3_enable(text_input);zwp_text_input_v3_set_surrounding_text(text_input, "hello", 3, 1);zwp_text_input_v3_set_content_type(text_input, 1, 0);+ zwp_text_input_v3_commit(text_input);+ /* Chromium enables with a commit that does not use set_cursor_rectangle and+ sends the caret rectangle in a later commit. The compositor must keep+ using it after that. */zwp_text_input_v3_set_cursor_rectangle(text_input, 40, 30, 2, 20);zwp_text_input_v3_commit(text_input);}@@ -180,6 +184,11 @@ static void command(char *line) {zwp_text_input_v3_set_text_change_cause(text_input,1);zwp_text_input_v3_set_cursor_rectangle(text_input,100,70,3,25);zwp_text_input_v3_commit(text_input);+ } else if(!strncmp(line,"caret ",6)) {+ int x, y;+ if(sscanf(line+6,"%d %d",&x,&y)!=2) abort();+ zwp_text_input_v3_set_cursor_rectangle(text_input,x,y,3,25);+ zwp_text_input_v3_commit(text_input);} else if(!strcmp(line,"extreme-rectangle")) {zwp_text_input_v3_set_cursor_rectangle(text_input,INT32_MAX,INT32_MIN,INT32_MAX,INT32_MAX);zwp_text_input_v3_commit(text_input);diff --git a/tests/input_protocols.py b/tests/input_protocols.pyindex 97efabe..c9c042a 100644--- a/tests/input_protocols.py+++ b/tests/input_protocols.py@@ -204,6 +204,28 @@ def run():action('move_window_to', {"id": w["id"], "x": w["x"] + 40, "y": w["y"] + 30})wait_for(lambda: popup_pixel() == (point[0] + 40, point[1] + 30),"IME popup did not follow its window")++ # Chromium sends set_cursor_rectangle in a commit after the enabling+ # one, so the candidate must follow the caret rather than the+ # surface origin the enabling commit left behind.+ def rectangle():+ lines = [line for line in ime.text().splitlines() if line.startswith("rectangle ")]+ return tuple(map(int, lines[-1].split()[1:]))++ popup = ime_state()["popups"][0]+ start = (popup["x"], popup["y"])+ relative = rectangle()+ app.send("caret 140 110")++ def shift():+ popup = ime_state()["popups"][0]+ return popup["x"] - start[0], popup["y"] - start[1]++ wait_for(lambda: shift() == (40, 40), lambda: f"candidate did not follow the caret: {shift()}")+ # The caret keeps the same place inside the popup, so the IME is+ # not told again: the popup itself has to move.+ assert rectangle() == relative, (relative, rectangle(), ime.text()[-500:])+placed = ime_state()["popups"][0]before_zoom = window("rediwm.protocol-app")action('key_press', {"key": "F9"})