Add keybinds to cycle between outputs

This commit is contained in:
Isaac Freund
2020-04-15 19:16:55 +02:00
parent f33b1fa3e8
commit 8a326541f6
2 changed files with 35 additions and 0 deletions

View File

@ -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;