aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIsaac Freund <ifreund@ifreund.xyz>2020-08-21 16:23:23 +0200
committerIsaac Freund <ifreund@ifreund.xyz>2020-08-21 16:31:39 +0200
commit72747610695feef8867a8aac48935274072bd14b (patch)
tree25dbb9943d8aa62d2cefd3a26abe98ca829b1235
parentdb416eb11960bebd1d0802c1ee291ce0bb450ba8 (diff)
downloadriver-72747610695feef8867a8aac48935274072bd14b.tar.gz
river-72747610695feef8867a8aac48935274072bd14b.tar.xz
cursor: leave mode if target view is destroyed
-rw-r--r--river/Cursor.zig32
-rw-r--r--river/InputManager.zig8
-rw-r--r--river/Seat.zig2
3 files changed, 29 insertions, 13 deletions
diff --git a/river/Cursor.zig b/river/Cursor.zig
index abca096..4e24b7e 100644
--- a/river/Cursor.zig
+++ b/river/Cursor.zig
@@ -201,12 +201,7 @@ const Mode = union(enum) {
// There is either no surface under the cursor or input is disallowed
// Reset the cursor image to the default and clear focus.
- c.wlr_xcursor_manager_set_cursor_image(
- self.wlr_xcursor_manager,
- "left_ptr",
- self.wlr_cursor,
- );
- c.wlr_seat_pointer_clear_focus(self.seat.wlr_seat);
+ self.clearFocus();
}
};
@@ -321,6 +316,31 @@ pub fn setTheme(self: *Self, theme: ?[*:0]const u8, _size: ?u32) !void {
}
}
+pub fn isCursorActionTarget(self: Self, view: *const View) bool {
+ return switch (self.mode) {
+ .passthrough => false,
+ .down => |target_view| target_view == view,
+ .move => |target_view| target_view == view,
+ .resize => |data| data.view == view,
+ };
+}
+
+pub fn handleViewUnmap(self: *Self, view: *View) void {
+ if (self.isCursorActionTarget(view)) {
+ self.mode = .passthrough;
+ self.clearFocus();
+ }
+}
+
+fn clearFocus(self: Self) void {
+ c.wlr_xcursor_manager_set_cursor_image(
+ self.wlr_xcursor_manager,
+ "left_ptr",
+ self.wlr_cursor,
+ );
+ c.wlr_seat_pointer_clear_focus(self.seat.wlr_seat);
+}
+
fn handleAxis(listener: ?*c.wl_listener, data: ?*c_void) callconv(.C) void {
// This event is forwarded by the cursor when a pointer emits an axis event,
// for example when you move the scroll wheel.
diff --git a/river/InputManager.zig b/river/InputManager.zig
index feb1ef2..a4e39ed 100644
--- a/river/InputManager.zig
+++ b/river/InputManager.zig
@@ -107,13 +107,7 @@ pub fn inputAllowed(self: Self, wlr_surface: *c.wlr_surface) bool {
pub fn isCursorActionTarget(self: Self, view: *View) bool {
var it = self.seats.first;
return while (it) |node| : (it = node.next) {
- const seat = &node.data;
- switch (seat.cursor.mode) {
- .passthrough => {},
- .down => |target_view| if (target_view == view) break true,
- .move => |target_view| if (target_view == view) break true,
- .resize => |data| if (data.view == view) break true,
- }
+ if (node.data.cursor.isCursorActionTarget(view)) break true;
} else false;
}
diff --git a/river/Seat.zig b/river/Seat.zig
index a1825ed..8f03550 100644
--- a/river/Seat.zig
+++ b/river/Seat.zig
@@ -261,6 +261,8 @@ pub fn handleViewUnmap(self: *Self, view: *View) void {
}
}
+ self.cursor.handleViewUnmap(view);
+
// If the unmapped view is focused, choose a new focus
if (self.focused == .view and self.focused.view == view) self.focus(null);
}