aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIsaac Freund <mail@isaacfreund.com>2023-11-06 13:10:59 +0100
committerIsaac Freund <mail@isaacfreund.com>2023-11-06 13:14:16 +0100
commit18a440b6063db07604fa8626fda893cc77d841dc (patch)
tree8754b5f848626ef78b54c462b67c3bdaa5d39559
parent642f9b7ae0b5fd55d7b677640f9df1e1f6bc4a42 (diff)
downloadriver-18a440b6063db07604fa8626fda893cc77d841dc.tar.gz
river-18a440b6063db07604fa8626fda893cc77d841dc.tar.xz
pointer-constraints: fix assertion failure
It is possible for the assertion in PointerConstraint.confine() to fail if a view with an active pointer constraint is, for example, resized using a keybinding such that the pointer is outside the constraint region. Handle this edge case by deactivating the constraint. The other option would be to warp the pointer to the nearest point still inside the constraint region. Deactivating the constraint is far simpler however and I don't expect this to be a UX pain point.
-rw-r--r--river/PointerConstraint.zig14
1 files changed, 12 insertions, 2 deletions
diff --git a/river/PointerConstraint.zig b/river/PointerConstraint.zig
index 5da1dc3..e833ee8 100644
--- a/river/PointerConstraint.zig
+++ b/river/PointerConstraint.zig
@@ -119,13 +119,23 @@ pub fn updateState(constraint: *PointerConstraint) void {
return;
}
- const warp_lx = @as(f64, @floatFromInt(lx)) + constraint.state.active.sx;
- const warp_ly = @as(f64, @floatFromInt(ly)) + constraint.state.active.sy;
+ const sx = constraint.state.active.sx;
+ const sy = constraint.state.active.sy;
+ const warp_lx = @as(f64, @floatFromInt(lx)) + sx;
+ const warp_ly = @as(f64, @floatFromInt(ly)) + sy;
if (!seat.cursor.wlr_cursor.warp(null, warp_lx, warp_ly)) {
log.info("deactivating pointer constraint, could not warp cursor", .{});
constraint.deactivate();
return;
}
+
+ // It is possible for the cursor to end up outside of the constraint region despite the warp
+ // if, for example, the a keybinding is used to resize the view.
+ if (!constraint.wlr_constraint.region.containsPoint(@intFromFloat(sx), @intFromFloat(sy), null)) {
+ log.info("deactivating pointer constraint, cursor outside region despite warp", .{});
+ constraint.deactivate();
+ return;
+ }
}
pub fn confine(constraint: *PointerConstraint, dx: *f64, dy: *f64) void {