git.lucas.co / cce-compositor
Wayland compositor (wlroots)
git clone https://git.lucas.co/cce-compositor.git

commit765761b126e2159fa5c235b94c36efd71c6897c8
parent21c46bb499
authorIsaac Freund <[email protected]>
date2023-11-13 22:54
Cursor: clamp cursor movement to resize bounds

Currently resizing a window allows moving the invisible "internal"
cursor infinitely far off screen despite the fact that the window is
bounded by the size constraints of the client and by the output
dimensions. This means that attempting to resize past these bounds in
one dimension will result in the "internal" cursor being far out of
bounds and will require an equal movement in the opposite direction in
order to continue resizing.

Exposing this implementation detail of an invisible "internal" cursor
separate from the rendered cursor is of course bad, so clamp it to the
bounds of the resize.

 river/Cursor.zig | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/river/Cursor.zig b/river/Cursor.zig
index b8fd61d..03868a9 100644
--- a/river/Cursor.zig
+++ b/river/Cursor.zig
@@ -895,11 +895,13 @@ fn processMotion(self: *Self, device: *wlr.InputDevice, time: u32, delta_x: f64,
                 box.width = @max(box.width, constraints.min_width);
                 box.width = @min(box.width, constraints.max_width);
                 box.width = @min(box.width, x2 - border_width);
+                data.x = @floatFromInt(data.initial_width - box.width);
             } else if (data.edges.right) {
                 box.width = data.initial_width + @as(i32, @intFromFloat(data.x));
                 box.width = @max(box.width, constraints.min_width);
                 box.width = @min(box.width, constraints.max_width);
                 box.width = @min(box.width, output_width - border_width - box.x);
+                data.x = @floatFromInt(box.width - data.initial_width);
             }
 
             if (data.edges.top) {
@@ -908,11 +910,13 @@ fn processMotion(self: *Self, device: *wlr.InputDevice, time: u32, delta_x: f64,
                 box.height = @max(box.height, constraints.min_height);
                 box.height = @min(box.height, constraints.max_height);
                 box.height = @min(box.height, y2 - border_width);
+                data.y = @floatFromInt(data.initial_height - box.height);
             } else if (data.edges.bottom) {
                 box.height = data.initial_height + @as(i32, @intFromFloat(data.y));
                 box.height = @max(box.height, constraints.min_height);
                 box.height = @min(box.height, constraints.max_height);
                 box.height = @min(box.height, output_height - border_width - box.y);
+                data.y = @floatFromInt(box.height - data.initial_height);
             }
 
             server.root.applyPending();