cursor: leave mode if target view is destroyed
This commit is contained in:
parent
db416eb119
commit
7274761069
3 changed files with 29 additions and 13 deletions
|
@ -201,12 +201,7 @@ const Mode = union(enum) {
|
||||||
|
|
||||||
// There is either no surface under the cursor or input is disallowed
|
// There is either no surface under the cursor or input is disallowed
|
||||||
// Reset the cursor image to the default and clear focus.
|
// Reset the cursor image to the default and clear focus.
|
||||||
c.wlr_xcursor_manager_set_cursor_image(
|
self.clearFocus();
|
||||||
self.wlr_xcursor_manager,
|
|
||||||
"left_ptr",
|
|
||||||
self.wlr_cursor,
|
|
||||||
);
|
|
||||||
c.wlr_seat_pointer_clear_focus(self.seat.wlr_seat);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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 {
|
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,
|
// This event is forwarded by the cursor when a pointer emits an axis event,
|
||||||
// for example when you move the scroll wheel.
|
// for example when you move the scroll wheel.
|
||||||
|
|
|
@ -107,13 +107,7 @@ pub fn inputAllowed(self: Self, wlr_surface: *c.wlr_surface) bool {
|
||||||
pub fn isCursorActionTarget(self: Self, view: *View) bool {
|
pub fn isCursorActionTarget(self: Self, view: *View) bool {
|
||||||
var it = self.seats.first;
|
var it = self.seats.first;
|
||||||
return while (it) |node| : (it = node.next) {
|
return while (it) |node| : (it = node.next) {
|
||||||
const seat = &node.data;
|
if (node.data.cursor.isCursorActionTarget(view)) break true;
|
||||||
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,
|
|
||||||
}
|
|
||||||
} else false;
|
} else false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 the unmapped view is focused, choose a new focus
|
||||||
if (self.focused == .view and self.focused.view == view) self.focus(null);
|
if (self.focused == .view and self.focused.view == view) self.focus(null);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue