git.lucas.co / cce-compositor
Wayland compositor (wlroots)
git clone https://git.lucas.co/cce-compositor.git

commit9af651daa5cfad1c436d929d49a0912f021df327
parentb6346a7f58
authorIsaac Freund <[email protected]>
date2022-06-03 11:09
Cursor: revive 'always' focus-follows-cursor mode

This was removed a while back because it was buggy and I didn't know
of anyone using it. Since refactoring it is now trivial to implement
and I know of at least one person using it, so I don't mind reviving it.

 completions/bash/riverctl      | 2 +-
 completions/fish/riverctl.fish | 2 +-
 completions/zsh/_riverctl      | 2 +-
 doc/riverctl.1.scd             | 6 ++++--
 river/Config.zig               | 2 ++
 river/Cursor.zig               | 4 +++-
 6 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/completions/bash/riverctl b/completions/bash/riverctl
index 881946f..14a5bfb 100644
--- a/completions/bash/riverctl
+++ b/completions/bash/riverctl
@@ -59,7 +59,7 @@ function __riverctl_completion ()
 			"map") OPTS="-release -repeat -layout" ;;
 			"unmap") OPTS="-release" ;;
 			"attach-mode") OPTS="top bottom" ;;
-			"focus-follows-cursor") OPTS="disabled normal" ;;
+			"focus-follows-cursor") OPTS="disabled normal always" ;;
 			"set-cursor-warp") OPTS="disabled on-output-change" ;;
 			"hide-cursor") OPTS="timeout when-typing" ;;
 			*) return ;;
diff --git a/completions/fish/riverctl.fish b/completions/fish/riverctl.fish
index 7a09063..443e986 100644
--- a/completions/fish/riverctl.fish
+++ b/completions/fish/riverctl.fish
@@ -73,7 +73,7 @@ complete -c riverctl -x -n '__fish_seen_subcommand_from swap'                 -a
 complete -c riverctl -x -n '__fish_seen_subcommand_from map'                  -a '-release -repeat -layout'
 complete -c riverctl -x -n '__fish_seen_subcommand_from unmap'                -a '-release'
 complete -c riverctl -x -n '__fish_seen_subcommand_from attach-mode'          -a 'top bottom'
-complete -c riverctl -x -n '__fish_seen_subcommand_from focus-follows-cursor' -a 'disabled normal'
+complete -c riverctl -x -n '__fish_seen_subcommand_from focus-follows-cursor' -a 'disabled normal always'
 complete -c riverctl -x -n '__fish_seen_subcommand_from set-cursor-warp'      -a 'disabled on-output-change'
 
 # Subcommands for 'input'
diff --git a/completions/zsh/_riverctl b/completions/zsh/_riverctl
index 8fec8fe..ed2662d 100644
--- a/completions/zsh/_riverctl
+++ b/completions/zsh/_riverctl
@@ -172,7 +172,7 @@ _riverctl()
                 map) _alternative 'arguments:optional:(-release -repeat -layout)' ;;
                 unmap) _alternative 'arguments:optional:(-release)' ;;
                 attach-mode) _alternative 'arguments:args:(top bottom)' ;;
-                focus-follows-cursor) _alternative 'arguments:args:(disabled normal)' ;;
+                focus-follows-cursor) _alternative 'arguments:args:(disabled normal always)' ;;
                 set-cursor-warp) _alternative 'arguments:args:(disabled on-output-change)' ;;
                 hide-cursor) _riverctl_hide_cursor ;;
                 *) return 0 ;;
diff --git a/doc/riverctl.1.scd b/doc/riverctl.1.scd
index 42e1500..0de4045 100644
--- a/doc/riverctl.1.scd
+++ b/doc/riverctl.1.scd
@@ -282,14 +282,16 @@ A complete list may be found in _/usr/include/linux/input-event-codes.h_
 *border-width* _pixels_
 	Set the border width to _pixels_.
 
-*focus-follows-cursor* *disabled*|*normal*
-	There are two available modes:
+*focus-follows-cursor* *disabled*|*normal*|*always*
+	There are three available modes:
 
 	- _disabled_: Moving the cursor does not affect focus. This is
 	  the default.
 	- _normal_: Moving the cursor over a view will focus that view.
 	  Moving the cursor within a view will not re-focus that view if
 	  focus has moved elsewhere.
+	- _always_: Moving the cursor will always focus whatever view is
+	  under the cursor.
 
 	If the view to be focused is on an output that does not have focus,
 	focus is switched to that output.
diff --git a/river/Config.zig b/river/Config.zig
index 9d0fa4c..7916621 100644
--- a/river/Config.zig
+++ b/river/Config.zig
@@ -29,6 +29,8 @@ pub const FocusFollowsCursorMode = enum {
     disabled,
     /// Only change focus on entering a surface
     normal,
+    /// Change focus on any cursor movement
+    always,
 };
 
 pub const WarpCursorMode = enum {
diff --git a/river/Cursor.zig b/river/Cursor.zig
index d02a2bd..0b90054 100644
--- a/river/Cursor.zig
+++ b/river/Cursor.zig
@@ -902,7 +902,9 @@ pub fn checkFocusFollowsCursor(self: *Self) void {
     if (self.seat.pointer_drag) return;
     if (server.config.focus_follows_cursor == .disabled) return;
     if (self.surfaceAt()) |result| {
-        if (self.seat.wlr_seat.pointer_state.focused_surface != result.surface) {
+        if (server.config.focus_follows_cursor == .always or
+            self.seat.wlr_seat.pointer_state.focused_surface != result.surface)
+        {
             switch (result.parent) {
                 .view => |view| {
                     if (self.seat.focused != .view or self.seat.focused.view != view) {