2020-04-07 10:16:38 -07:00
|
|
|
const std = @import("std");
|
|
|
|
const c = @import("c.zig");
|
|
|
|
|
2020-04-08 12:31:07 -07:00
|
|
|
const Log = @import("log.zig").Log;
|
2020-04-07 10:16:38 -07:00
|
|
|
const Server = @import("server.zig").Server;
|
|
|
|
const ViewStack = @import("view_stack.zig").ViewStack;
|
|
|
|
|
2020-04-07 12:48:56 -07:00
|
|
|
pub const Arg = union {
|
|
|
|
int: i32,
|
|
|
|
uint: u32,
|
|
|
|
float: f64,
|
2020-04-08 12:31:07 -07:00
|
|
|
cstr: [*:0]const u8,
|
2020-04-07 12:48:56 -07:00
|
|
|
none: void,
|
|
|
|
};
|
|
|
|
|
|
|
|
pub const Command = fn (server: *Server, arg: Arg) void;
|
|
|
|
|
2020-04-07 10:16:38 -07:00
|
|
|
/// Exit the compositor, terminating the wayland session.
|
2020-04-07 12:48:56 -07:00
|
|
|
pub fn exitCompositor(server: *Server, arg: Arg) void {
|
2020-04-07 10:16:38 -07:00
|
|
|
c.wl_display_terminate(server.wl_display);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Shift focus to the next visible view, wrapping if needed.
|
2020-04-07 12:48:56 -07:00
|
|
|
pub fn focusNextView(server: *Server, arg: Arg) void {
|
2020-04-07 10:16:38 -07:00
|
|
|
server.root.focusNextView();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Shift focus to the previous visible view, wrapping if needed.
|
2020-04-07 12:48:56 -07:00
|
|
|
pub fn focusPrevView(server: *Server, arg: Arg) void {
|
2020-04-07 10:16:38 -07:00
|
|
|
server.root.focusPrevView();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Modify the number of master views
|
2020-04-07 12:48:56 -07:00
|
|
|
pub fn modifyMasterCount(server: *Server, arg: Arg) void {
|
|
|
|
const delta = arg.int;
|
2020-04-07 10:16:38 -07:00
|
|
|
server.root.master_count = @intCast(u32, std.math.max(
|
|
|
|
0,
|
|
|
|
@intCast(i32, server.root.master_count) + delta,
|
|
|
|
));
|
|
|
|
server.root.arrange();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Modify the percent of the width of the screen that the master views occupy.
|
2020-04-07 12:48:56 -07:00
|
|
|
pub fn modifyMasterFactor(server: *Server, arg: Arg) void {
|
|
|
|
const delta = arg.float;
|
2020-04-07 10:16:38 -07:00
|
|
|
const new_master_factor = std.math.min(
|
|
|
|
std.math.max(server.root.master_factor + delta, 0.05),
|
|
|
|
0.95,
|
|
|
|
);
|
|
|
|
if (new_master_factor != server.root.master_factor) {
|
|
|
|
server.root.master_factor = new_master_factor;
|
|
|
|
server.root.arrange();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Bump the focused view to the top of the stack.
|
|
|
|
/// TODO: if the top of the stack is focused, bump the next visible view.
|
2020-04-07 12:48:56 -07:00
|
|
|
pub fn zoom(server: *Server, arg: Arg) void {
|
2020-04-07 10:16:38 -07:00
|
|
|
if (server.root.focused_view) |current_focus| {
|
|
|
|
const node = @fieldParentPtr(ViewStack.Node, "view", current_focus);
|
|
|
|
if (node != server.root.views.first) {
|
|
|
|
server.root.views.remove(node);
|
|
|
|
server.root.views.push(node);
|
|
|
|
server.root.arrange();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Switch focus to the passed tags.
|
2020-04-07 12:48:56 -07:00
|
|
|
pub fn focusTags(server: *Server, arg: Arg) void {
|
|
|
|
const tags = arg.uint;
|
2020-04-07 10:16:38 -07:00
|
|
|
server.root.pending_focused_tags = tags;
|
|
|
|
server.root.arrange();
|
|
|
|
}
|
|
|
|
|
2020-04-07 15:40:41 -07:00
|
|
|
/// Toggle focus of the passsed tags.
|
|
|
|
pub fn toggleTags(server: *Server, arg: Arg) void {
|
|
|
|
const tags = arg.uint;
|
|
|
|
const new_focused_tags = server.root.current_focused_tags ^ tags;
|
|
|
|
if (new_focused_tags != 0) {
|
|
|
|
server.root.pending_focused_tags = new_focused_tags;
|
|
|
|
server.root.arrange();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-07 10:16:38 -07:00
|
|
|
/// Set the tags of the focused view.
|
2020-04-07 12:48:56 -07:00
|
|
|
pub fn setFocusedViewTags(server: *Server, arg: Arg) void {
|
|
|
|
const tags = arg.uint;
|
2020-04-07 10:16:38 -07:00
|
|
|
if (server.root.focused_view) |view| {
|
|
|
|
if (view.current_tags != tags) {
|
|
|
|
view.pending_tags = tags;
|
|
|
|
server.root.arrange();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-08 03:44:41 -07:00
|
|
|
/// Toggle the passed tags of the focused view
|
|
|
|
pub fn toggleFocusedViewTags(server: *Server, arg: Arg) void {
|
|
|
|
const tags = arg.uint;
|
|
|
|
if (server.root.focused_view) |view| {
|
|
|
|
const new_tags = view.current_tags ^ tags;
|
|
|
|
if (new_tags != 0) {
|
|
|
|
view.pending_tags = new_tags;
|
|
|
|
server.root.arrange();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-07 10:16:38 -07:00
|
|
|
/// Spawn a program.
|
|
|
|
/// TODO: make this take a program as a paramter and spawn that
|
2020-04-07 12:48:56 -07:00
|
|
|
pub fn spawn(server: *Server, arg: Arg) void {
|
2020-04-08 12:31:07 -07:00
|
|
|
const cmd = arg.cstr;
|
|
|
|
if (c.fork() == 0) {
|
|
|
|
const terminator: ?*u8 = null;
|
|
|
|
if (c.execl("/bin/sh", "/bin/sh", "-c", cmd, terminator) == -1) {
|
|
|
|
Log.Error.log("Failed to execute command {}", .{cmd});
|
|
|
|
}
|
|
|
|
}
|
2020-04-07 10:16:38 -07:00
|
|
|
}
|
2020-04-08 08:43:00 -07:00
|
|
|
|
|
|
|
/// Close the focused view, if any.
|
|
|
|
pub fn close(server: *Server, arg: Arg) void {
|
|
|
|
if (server.root.focused_view) |view| {
|
|
|
|
view.close();
|
|
|
|
}
|
|
|
|
}
|