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

commit75b3c78e10723e40837ae103642d681286eb1810
parent3ada23d6a8
authorLeon Henrik Plickat <[email protected]>
date2023-11-10 04:53
command/focus-view: add -skip-floating

 doc/riverctl.1.scd                |  4 +++-
 river/command/view_operations.zig | 16 +++++++++++++---
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/doc/riverctl.1.scd b/doc/riverctl.1.scd
index 6a0edd1..cbcac17 100644
--- a/doc/riverctl.1.scd
+++ b/doc/riverctl.1.scd
@@ -50,10 +50,12 @@ necessarily disjunct), an analogy to workspaces.
 	Focus the next or previous output, the closest output in any direction
 	or an output by name.
 
-*focus-view* *next*|*previous*|*up*|*down*|*left*|*right*
+*focus-view* [*-skip-floating*] *next*|*previous*|*up*|*down*|*left*|*right*
 	Focus the next or previous view in the stack or the closest view in
 	any direction.
 
+	- *-skip-floating*: Skip floating views, only focusing tiled ones.
+
 *move* *up*|*down*|*left*|*right* _delta_
 	Move the focused view in the specified direction by _delta_ logical
 	pixels. The view will be set to floating.
diff --git a/river/command/view_operations.zig b/river/command/view_operations.zig
index 0e8b092..285717d 100644
--- a/river/command/view_operations.zig
+++ b/river/command/view_operations.zig
@@ -17,6 +17,7 @@
 const std = @import("std");
 const assert = std.debug.assert;
 const wlr = @import("wlroots");
+const flags = @import("flags");
 
 const server = &@import("../main.zig").server;
 
@@ -34,10 +35,19 @@ pub fn focusView(
     args: []const [:0]const u8,
     _: *?[]const u8,
 ) Error!void {
-    if (args.len < 2) return Error.NotEnoughArguments;
-    if (args.len > 2) return Error.TooManyArguments;
+    const result = flags.parser([:0]const u8, &.{
+        .{ .name = "skip-floating", .kind = .boolean },
+    }).parse(args[1..]) catch {
+        return error.InvalidValue;
+    };
+    if (result.args.len < 1) return Error.NotEnoughArguments;
+    if (result.args.len > 1) return Error.TooManyArguments;
 
-    if (try getTarget(seat, args[1], .all)) |target| {
+    if (try getTarget(
+        seat,
+        result.args[0],
+        if (result.flags.@"skip-floating") .skip_float else .all,
+    )) |target| {
         assert(!target.pending.fullscreen);
         seat.focus(target);
         server.root.applyPending();