cursor: leave mode if target view is destroyed

This commit is contained in:
Isaac Freund
2020-08-21 16:23:23 +02:00
parent db416eb119
commit 7274761069
3 changed files with 29 additions and 13 deletions

View File

@ -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.