aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIsaac Freund <ifreund@ifreund.xyz>2020-04-15 19:16:55 +0200
committerIsaac Freund <ifreund@ifreund.xyz>2020-04-15 19:16:55 +0200
commit8a326541f6728749dd24b786960dadc2148f0f43 (patch)
treed8b6c16bba96442018730ad8839287f82aa8f9b2 /src
parentf33b1fa3e830b677fa5c2f797513b09775984562 (diff)
downloadriver-8a326541f6728749dd24b786960dadc2148f0f43.tar.gz
river-8a326541f6728749dd24b786960dadc2148f0f43.tar.xz
Add keybinds to cycle between outputs
Diffstat (limited to 'src')
-rw-r--r--src/command.zig31
-rw-r--r--src/config.zig4
2 files changed, 35 insertions, 0 deletions
diff --git a/src/command.zig b/src/command.zig
index 1062d4a..709bf5b 100644
--- a/src/command.zig
+++ b/src/command.zig
@@ -2,6 +2,7 @@ const std = @import("std");
const c = @import("c.zig");
const Log = @import("log.zig").Log;
+const Output = @import("output.zig").Output;
const Seat = @import("seat.zig").Seat;
const View = @import("view.zig").View;
const ViewStack = @import("view_stack.zig").ViewStack;
@@ -63,6 +64,36 @@ pub fn focusPrevView(seat: *Seat, arg: Arg) void {
focusNextPrevView(seat, false);
}
+/// Focus either the next or the previous output, depending on the bool passed.
+fn focusNextPrevOutput(seat: *Seat, next: bool) void {
+ const root = &seat.input_manager.server.root;
+ // If the noop output is focused, there are no other outputs to switch to
+ if (seat.focused_output == &root.noop_output) {
+ std.debug.assert(root.outputs.len == 0);
+ return;
+ }
+
+ const focused_node = @fieldParentPtr(std.TailQueue(Output).Node, "data", seat.focused_output);
+ seat.focused_output = if (if (next) focused_node.next else focused_node.prev) |output_node|
+ // Focus the next/prev output in the list if there is one
+ &output_node.data
+ else if (next) &root.outputs.first.?.data else &root.outputs.last.?.data;
+
+ seat.focus(null);
+}
+
+/// Focus the next output, wrapping if needed. Does nothing if there is
+/// only one output.
+pub fn focusNextOutput(seat: *Seat, arg: Arg) void {
+ focusNextPrevOutput(seat, true);
+}
+
+/// Focus the previous output, wrapping if needed. Does nothing if there is
+/// only one output.
+pub fn focusPrevOutput(seat: *Seat, arg: Arg) void {
+ focusNextPrevOutput(seat, false);
+}
+
/// Modify the number of master views
pub fn modifyMasterCount(seat: *Seat, arg: Arg) void {
const delta = arg.int;
diff --git a/src/config.zig b/src/config.zig
index cbbdcea..b7be734 100644
--- a/src/config.zig
+++ b/src/config.zig
@@ -96,5 +96,9 @@ pub const Config = struct {
// Mod+Shift+0 to tag focused view with all tags
try self.keybinds.append(Keybind{ .keysym = c.XKB_KEY_0, .modifiers = mod | c.WLR_MODIFIER_SHIFT, .command = command.setFocusedViewTags, .arg = .{ .uint = 0xFFFFFFFF } });
+
+ // Mod+Period and Mod+Comma to focus the next/previous output
+ try self.keybinds.append(Keybind{ .keysym = c.XKB_KEY_period, .modifiers = mod, .command = command.focusNextOutput, .arg = .{ .none = {} } });
+ try self.keybinds.append(Keybind{ .keysym = c.XKB_KEY_comma, .modifiers = mod, .command = command.focusPrevOutput, .arg = .{ .none = {} } });
}
};