From 5bf7d22972d50e3ab2b63da82ca7c2161139a0e3 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Wed, 20 Oct 2021 13:22:24 +0200 Subject: [PATCH] Cursor: only trigger focus-follow-cursor on motion This greatly improves the UX of this feature, as views moving under a stationary cursor (as happens during the zoom command for example) will no longer trigger focus change. --- river/Cursor.zig | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/river/Cursor.zig b/river/Cursor.zig index 2692fd8..af36711 100644 --- a/river/Cursor.zig +++ b/river/Cursor.zig @@ -738,6 +738,24 @@ fn processMotion(self: *Self, device: *wlr.InputDevice, time: u32, delta_x: f64, switch (self.mode) { .passthrough => { self.wlr_cursor.move(device, dx, dy); + + if (self.surfaceAt()) |result| { + const focus_change = self.seat.wlr_seat.pointer_state.focused_surface != result.surface; + if (server.config.focus_follows_cursor == .normal and focus_change) { + switch (result.parent) { + .view => |view| { + if (self.seat.focused != .view or self.seat.focused.view != view) { + self.seat.focusOutput(view.output); + self.seat.focus(view); + server.root.startTransaction(); + } + }, + .layer_surface => {}, + .xwayland_unmanaged => assert(build_options.xwayland), + } + } + } + self.passthrough(time); }, .down => |view| { @@ -830,25 +848,8 @@ fn passthrough(self: *Self, time: u32) void { // events. Note that wlroots won't actually send an enter event if // the surface has already been entered. if (server.input_manager.inputAllowed(result.surface)) { - // The focus change must be checked before sending enter events - const focus_change = self.seat.wlr_seat.pointer_state.focused_surface != result.surface; - self.seat.wlr_seat.pointerNotifyEnter(result.surface, result.sx, result.sy); self.seat.wlr_seat.pointerNotifyMotion(time, result.sx, result.sy); - - if (server.config.focus_follows_cursor == .normal and focus_change) { - switch (result.parent) { - .view => |view| { - if (self.seat.focused != .view or self.seat.focused.view != view) { - self.seat.focusOutput(view.output); - self.seat.focus(view); - server.root.startTransaction(); - } - }, - .layer_surface => {}, - .xwayland_unmanaged => assert(build_options.xwayland), - } - } } } else { // There is either no surface under the cursor or input is disallowed