aboutsummaryrefslogtreecommitdiff
path: root/src/command
diff options
context:
space:
mode:
Diffstat (limited to 'src/command')
-rw-r--r--src/command/close.zig11
-rw-r--r--src/command/exit.zig12
-rw-r--r--src/command/focus.zig19
-rw-r--r--src/command/focus_all_tags.zig11
-rw-r--r--src/command/focus_output.zig15
-rw-r--r--src/command/focus_tag.zig17
-rw-r--r--src/command/layout.zig17
-rw-r--r--src/command/mod_master_count.zig14
-rw-r--r--src/command/mod_master_factor.zig14
-rw-r--r--src/command/mode.zig17
-rw-r--r--src/command/send_to_output.zig17
-rw-r--r--src/command/spawn.zig34
-rw-r--r--src/command/tag_view.zig17
-rw-r--r--src/command/tag_view_all_tags.zig11
-rw-r--r--src/command/toggle_float.zig12
-rw-r--r--src/command/toggle_tag_focus.zig17
-rw-r--r--src/command/toggle_view_tag.zig17
-rw-r--r--src/command/zoom.zig13
18 files changed, 223 insertions, 62 deletions
diff --git a/src/command/close.zig b/src/command/close.zig
index c5be01c..04b2dcd 100644
--- a/src/command/close.zig
+++ b/src/command/close.zig
@@ -15,13 +15,20 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
+const std = @import("std");
+
const c = @import("../c.zig");
-const Arg = @import("../Command.zig").Arg;
+const Error = @import("../command.zig").Error;
const Seat = @import("../Seat.zig");
/// Close the focused view, if any.
-pub fn close(seat: *Seat, arg: Arg) void {
+pub fn close(
+ allocator: *std.mem.Allocator,
+ seat: *Seat,
+ args: []const []const u8,
+ failure_message: *[]const u8,
+) Error!void {
if (seat.focused_view) |view| {
// Note: we don't call arrange() here as it will be called
// automatically when the view is unmapped.
diff --git a/src/command/exit.zig b/src/command/exit.zig
index 799b12c..a21e4f3 100644
--- a/src/command/exit.zig
+++ b/src/command/exit.zig
@@ -15,12 +15,20 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
+const std = @import("std");
+
const c = @import("../c.zig");
-const Arg = @import("../Command.zig").Arg;
+const Error = @import("../command.zig").Error;
const Seat = @import("../Seat.zig");
/// Exit the compositor, terminating the wayland session.
-pub fn exit(seat: *Seat, arg: Arg) void {
+pub fn exit(
+ allocator: *std.mem.Allocator,
+ seat: *Seat,
+ args: []const []const u8,
+ failure_message: *[]const u8,
+) Error!void {
+ if (args.len > 1) return Error.TooManyArguments;
c.wl_display_terminate(seat.input_manager.server.wl_display);
}
diff --git a/src/command/focus.zig b/src/command/focus.zig
index 930a36c..0e2c9e0 100644
--- a/src/command/focus.zig
+++ b/src/command/focus.zig
@@ -15,18 +15,30 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
+const std = @import("std");
+
const c = @import("../c.zig");
-const Arg = @import("../Command.zig").Arg;
+const Error = @import("../command.zig").Error;
+const Direction = @import("../command.zig").Direction;
const Seat = @import("../Seat.zig");
const View = @import("../View.zig");
const ViewStack = @import("../view_stack.zig").ViewStack;
/// Focus either the next or the previous visible view, depending on the enum
/// passed. Does nothing if there are 1 or 0 views in the stack.
-pub fn focus(seat: *Seat, arg: Arg) void {
- const direction = arg.direction;
+pub fn focus(
+ allocator: *std.mem.Allocator,
+ seat: *Seat,
+ args: []const []const u8,
+ failure_message: *[]const u8,
+) Error!void {
+ if (args.len < 2) return Error.NotEnoughArguments;
+ if (args.len > 2) return Error.TooManyArguments;
+
+ const direction = try Direction.parse(args[1]);
const output = seat.focused_output;
+
if (seat.focused_view) |current_focus| {
// If there is a currently focused view, focus the next visible view in the stack.
const focused_node = @fieldParentPtr(ViewStack(View).Node, "view", current_focus);
@@ -50,5 +62,6 @@ pub fn focus(seat: *Seat, arg: Arg) void {
.Next => ViewStack(View).iterator(output.views.first, output.current_focused_tags),
.Prev => ViewStack(View).reverseIterator(output.views.last, output.current_focused_tags),
};
+
seat.focus(if (it.next()) |node| &node.view else null);
}
diff --git a/src/command/focus_all_tags.zig b/src/command/focus_all_tags.zig
index d2eef88..28e001d 100644
--- a/src/command/focus_all_tags.zig
+++ b/src/command/focus_all_tags.zig
@@ -15,11 +15,18 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
-const Arg = @import("../Command.zig").Arg;
+const std = @import("std");
+
+const Error = @import("../command.zig").Error;
const Seat = @import("../Seat.zig");
/// Set focus to all tags
-pub fn focusAllTags(seat: *Seat, arg: Arg) void {
+pub fn focusAllTags(
+ allocator: *std.mem.Allocator,
+ seat: *Seat,
+ args: []const []const u8,
+ failure_message: *[]const u8,
+) Error!void {
seat.focused_output.pending_focused_tags = 0xFFFFFFFF;
seat.input_manager.server.root.arrange();
}
diff --git a/src/command/focus_output.zig b/src/command/focus_output.zig
index 02b7999..b11664f 100644
--- a/src/command/focus_output.zig
+++ b/src/command/focus_output.zig
@@ -19,14 +19,23 @@ const std = @import("std");
const c = @import("../c.zig");
-const Arg = @import("../Command.zig").Arg;
+const Error = @import("../command.zig").Error;
+const Direction = @import("../command.zig").Direction;
const Output = @import("../Output.zig");
const Seat = @import("../Seat.zig");
/// Focus either the next or the previous output, depending on the bool passed.
/// Does nothing if there is only one output.
-pub fn focusOutput(seat: *Seat, arg: Arg) void {
- const direction = arg.direction;
+pub fn focusOutput(
+ allocator: *std.mem.Allocator,
+ seat: *Seat,
+ args: []const []const u8,
+ failure_message: *[]const u8,
+) Error!void {
+ if (args.len < 2) return Error.NotEnoughArguments;
+ if (args.len > 2) return Error.TooManyArguments;
+
+ const direction = try Direction.parse(args[1]);
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) {
diff --git a/src/command/focus_tag.zig b/src/command/focus_tag.zig
index edb3292..8f69e6e 100644
--- a/src/command/focus_tag.zig
+++ b/src/command/focus_tag.zig
@@ -15,12 +15,23 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
-const Arg = @import("../Command.zig").Arg;
+const std = @import("std");
+
+const Error = @import("../command.zig").Error;
const Seat = @import("../Seat.zig");
/// Switch focus to the passed tag.
-pub fn focusTag(seat: *Seat, arg: Arg) void {
- const tags = @as(u32, 1) << @intCast(u5, arg.uint - 1);
+pub fn focusTag(
+ allocator: *std.mem.Allocator,
+ seat: *Seat,
+ args: []const []const u8,
+ failure_message: *[]const u8,
+) Error!void {
+ if (args.len < 2) return Error.NotEnoughArguments;
+ if (args.len > 2) return Error.TooManyArguments;
+
+ const tag = try std.fmt.parseInt(u32, args[1], 10);
+ const tags = @as(u32, 1) << @intCast(u5, tag - 1);
seat.focused_output.pending_focused_tags = tags;
seat.input_manager.server.root.arrange();
}
diff --git a/src/command/layout.zig b/src/command/layout.zig
index f8e21ad..4a21050 100644
--- a/src/command/layout.zig
+++ b/src/command/layout.zig
@@ -15,14 +15,23 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
+const std = @import("std");
+
const c = @import("../c.zig");
-const Arg = @import("../Command.zig").Arg;
+const Error = @import("../command.zig").Error;
const Seat = @import("../Seat.zig");
-pub fn layout(seat: *Seat, arg: Arg) void {
- const layout_name = arg.str;
- seat.focused_output.layout = seat.focused_output.getLayoutByName(layout_name);
+pub fn layout(
+ allocator: *std.mem.Allocator,
+ seat: *Seat,
+ args: []const []const u8,
+ failure_message: *[]const u8,
+) Error!void {
+ if (args.len < 2) return Error.NotEnoughArguments;
+ if (args.len > 2) return Error.TooManyArguments;
+
+ seat.focused_output.layout = seat.focused_output.getLayoutByName(args[1]);
seat.focused_output.arrangeViews();
seat.input_manager.server.root.startTransaction();
}
diff --git a/src/command/mod_master_count.zig b/src/command/mod_master_count.zig
index bd2fde0..38a379e 100644
--- a/src/command/mod_master_count.zig
+++ b/src/command/mod_master_count.zig
@@ -19,12 +19,20 @@ const std = @import("std");
const c = @import("../c.zig");
-const Arg = @import("../Command.zig").Arg;
+const Error = @import("../command.zig").Error;
const Seat = @import("../Seat.zig");
/// Modify the number of master views
-pub fn modMasterCount(seat: *Seat, arg: Arg) void {
- const delta = arg.int;
+pub fn modMasterCount(
+ allocator: *std.mem.Allocator,
+ seat: *Seat,
+ args: []const []const u8,
+ failure_message: *[]const u8,
+) Error!void {
+ if (args.len < 2) return Error.NotEnoughArguments;
+ if (args.len > 2) return Error.TooManyArguments;
+
+ const delta = try std.fmt.parseInt(i32, args[1], 10);
const output = seat.focused_output;
output.master_count = @intCast(
u32,
diff --git a/src/command/mod_master_factor.zig b/src/command/mod_master_factor.zig
index 2e2a73c..ec8065a 100644
--- a/src/command/mod_master_factor.zig
+++ b/src/command/mod_master_factor.zig
@@ -19,12 +19,20 @@ const std = @import("std");
const c = @import("../c.zig");
-const Arg = @import("../Command.zig").Arg;
+const Error = @import("../command.zig").Error;
const Seat = @import("../Seat.zig");
/// Modify the percent of the width of the screen that the master views occupy.
-pub fn modMasterFactor(seat: *Seat, arg: Arg) void {
- const delta = arg.float;
+pub fn modMasterFactor(
+ allocator: *std.mem.Allocator,
+ seat: *Seat,
+ args: []const []const u8,
+ failure_message: *[]const u8,
+) Error!void {
+ if (args.len < 2) return Error.NotEnoughArguments;
+ if (args.len > 2) return Error.TooManyArguments;
+
+ const delta = try std.fmt.parseFloat(f64, args[1]);
const output = seat.focused_output;
const new_master_factor = std.math.min(
std.math.max(output.master_factor + delta, 0.05),
diff --git a/src/command/mode.zig b/src/command/mode.zig
index 706533c..fb03bb5 100644
--- a/src/command/mode.zig
+++ b/src/command/mode.zig
@@ -15,12 +15,21 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
-const Arg = @import("../Command.zig").Arg;
+const std = @import("std");
+
+const Error = @import("../command.zig").Error;
const Seat = @import("../Seat.zig");
/// Switch to the given mode
-pub fn mode(seat: *Seat, arg: Arg) void {
- const mode_name = arg.str;
+pub fn mode(
+ allocator: *std.mem.Allocator,
+ seat: *Seat,
+ args: []const []const u8,
+ failure_message: *[]const u8,
+) Error!void {
+ if (args.len < 2) return Error.NotEnoughArguments;
+ if (args.len > 2) return Error.TooManyArguments;
+
const config = seat.input_manager.server.config;
- seat.mode = config.getMode(mode_name);
+ seat.mode = config.getMode(args[1]);
}
diff --git a/src/command/send_to_output.zig b/src/command/send_to_output.zig
index 7e0bbbf..de92f6f 100644
--- a/src/command/send_to_output.zig
+++ b/src/command/send_to_output.zig
@@ -19,16 +19,23 @@ const std = @import("std");
const c = @import("../c.zig");
-const Arg = @import("../Command.zig").Arg;
+const Error = @import("../command.zig").Error;
+const Direction = @import("../command.zig").Direction;
const Output = @import("../Output.zig");
const Seat = @import("../Seat.zig");
/// Send the focused view to the the next or the previous output, depending on
/// the bool passed. Does nothing if there is only one output.
-pub fn sendToOutput(seat: *Seat, arg: Arg) void {
- @import("../log.zig").Log.Debug.log("send to output", .{});
-
- const direction = arg.direction;
+pub fn sendToOutput(
+ allocator: *std.mem.Allocator,
+ seat: *Seat,
+ args: []const []const u8,
+ failure_message: *[]const u8,
+) Error!void {
+ if (args.len < 2) return Error.NotEnoughArguments;
+ if (args.len > 2) return Error.TooManyArguments;
+
+ const direction = try Direction.parse(args[1]);
const root = &seat.input_manager.server.root;
if (seat.focused_view) |view| {
diff --git a/src/command/spawn.zig b/src/command/spawn.zig
index 61aedab..880483a 100644
--- a/src/command/spawn.zig
+++ b/src/command/spawn.zig
@@ -17,23 +17,31 @@
const std = @import("std");
-const c = @import("../c.zig");
-
-const Arg = @import("../Command.zig").Arg;
-const Log = @import("../log.zig").Log;
+const Error = @import("../command.zig").Error;
const Seat = @import("../Seat.zig");
/// Spawn a program.
-pub fn spawn(seat: *Seat, arg: Arg) void {
- const cmd = arg.str;
+pub fn spawn(
+ allocator: *std.mem.Allocator,
+ seat: *Seat,
+ args: []const []const u8,
+ failure_message: *[]const u8,
+) Error!void {
+ if (args.len < 2) return Error.NotEnoughArguments;
+
+ const cmd = try std.mem.join(allocator, " ", args[1..]);
+ defer allocator.free(cmd);
+
+ const child_args = [_][]const u8{ "/bin/sh", "-c", cmd };
+ const child = try std.ChildProcess.init(&child_args, allocator);
+ defer child.deinit();
- const argv = [_][]const u8{ "/bin/sh", "-c", cmd };
- const child = std.ChildProcess.init(&argv, std.heap.c_allocator) catch |err| {
- Log.Error.log("Failed to execute {}: {}", .{ cmd, err });
- return;
- };
std.ChildProcess.spawn(child) catch |err| {
- Log.Error.log("Failed to execute {}: {}", .{ cmd, err });
- return;
+ failure_message.* = try std.fmt.allocPrint(
+ allocator,
+ "failed to spawn {}: {}.",
+ .{ cmd, err },
+ );
+ return Error.CommandFailed;
};
}
diff --git a/src/command/tag_view.zig b/src/command/tag_view.zig
index fd74285..735481d 100644
--- a/src/command/tag_view.zig
+++ b/src/command/tag_view.zig
@@ -15,14 +15,25 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
+const std = @import("std");
+
const c = @import("../c.zig");
-const Arg = @import("../Command.zig").Arg;
+const Error = @import("../command.zig").Error;
const Seat = @import("../Seat.zig");
/// Set the tag of the focused view.
-pub fn tagView(seat: *Seat, arg: Arg) void {
- const tags = @as(u32, 1) << @intCast(u5, arg.uint - 1);
+pub fn tagView(
+ allocator: *std.mem.Allocator,
+ seat: *Seat,
+ args: []const []const u8,
+ failure_message: *[]const u8,
+) Error!void {
+ if (args.len < 2) return Error.NotEnoughArguments;
+ if (args.len > 2) return Error.TooManyArguments;
+
+ const tag = try std.fmt.parseInt(u32, args[1], 10);
+ const tags = @as(u32, 1) << @intCast(u5, tag - 1);
if (seat.focused_view) |view| {
if (view.current_tags != tags) {
view.pending_tags = tags;
diff --git a/src/command/tag_view_all_tags.zig b/src/command/tag_view_all_tags.zig
index 1b93233..2d187f3 100644
--- a/src/command/tag_view_all_tags.zig
+++ b/src/command/tag_view_all_tags.zig
@@ -15,13 +15,20 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
+const std = @import("std");
+
const c = @import("../c.zig");
-const Arg = @import("../Command.zig").Arg;
+const Error = @import("../command.zig").Error;
const Seat = @import("../Seat.zig");
/// Tag the focused view with all tags.
-pub fn tagViewAllTags(seat: *Seat, arg: Arg) void {
+pub fn tagViewAllTags(
+ allocator: *std.mem.Allocator,
+ seat: *Seat,
+ args: []const []const u8,
+ failure_message: *[]const u8,
+) Error!void {
if (seat.focused_view) |view| {
if (view.current_tags != 0xFFFFFFFF) {
view.pending_tags = 0xFFFFFFFF;
diff --git a/src/command/toggle_float.zig b/src/command/toggle_float.zig
index e890d73..25655e8 100644
--- a/src/command/toggle_float.zig
+++ b/src/command/toggle_float.zig
@@ -15,14 +15,22 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
+const std = @import("std");
+
const c = @import("../c.zig");
-const Arg = @import("../Command.zig").Arg;
+const Error = @import("../command.zig").Error;
const Seat = @import("../Seat.zig");
/// Make the focused view float or stop floating, depending on its current
/// state.
-pub fn toggleFloat(seat: *Seat, arg: Arg) void {
+pub fn toggleFloat(
+ allocator: *std.mem.Allocator,
+ seat: *Seat,
+ args: []const []const u8,
+ failure_message: *[]const u8,
+) Error!void {
+ if (args.len > 1) return Error.TooManyArguments;
if (seat.focused_view) |view| {
view.setFloating(!view.floating);
view.output.root.arrange();
diff --git a/src/command/toggle_tag_focus.zig b/src/command/toggle_tag_focus.zig
index 8a1a707..09761c7 100644
--- a/src/command/toggle_tag_focus.zig
+++ b/src/command/toggle_tag_focus.zig
@@ -15,14 +15,25 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
+const std = @import("std");
+
const c = @import("../c.zig");
-const Arg = @import("../Command.zig").Arg;
+const Error = @import("../command.zig").Error;
const Seat = @import("../Seat.zig");
/// Toggle focus of the passsed tags.
-pub fn toggleTagFocus(seat: *Seat, arg: Arg) void {
- const tags = @as(u32, 1) << @intCast(u5, arg.uint - 1);
+pub fn toggleTagFocus(
+ allocator: *std.mem.Allocator,
+ seat: *Seat,
+ args: []const []const u8,
+ failure_message: *[]const u8,
+) Error!void {
+ if (args.len < 2) return Error.NotEnoughArguments;
+ if (args.len > 2) return Error.TooManyArguments;
+
+ const tag = try std.fmt.parseInt(u32, args[1], 10);
+ const tags = @as(u32, 1) << @intCast(u5, tag - 1);
const output = seat.focused_output;
const new_focused_tags = output.current_focused_tags ^ tags;
if (new_focused_tags != 0) {
diff --git a/src/command/toggle_view_tag.zig b/src/command/toggle_view_tag.zig
index fa869b5..469a750 100644
--- a/src/command/toggle_view_tag.zig
+++ b/src/command/toggle_view_tag.zig
@@ -15,14 +15,25 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
+const std = @import("std");
+
const c = @import("../c.zig");
-const Arg = @import("../Command.zig").Arg;
+const Error = @import("../command.zig").Error;
const Seat = @import("../Seat.zig");
/// Toggle the passed tag of the focused view
-pub fn toggleViewTag(seat: *Seat, arg: Arg) void {
- const tags = @as(u32, 1) << @intCast(u5, arg.uint - 1);
+pub fn toggleViewTag(
+ allocator: *std.mem.Allocator,
+ seat: *Seat,
+ args: []const []const u8,
+ failure_message: *[]const u8,
+) Error!void {
+ if (args.len < 2) return Error.NotEnoughArguments;
+ if (args.len > 2) return Error.TooManyArguments;
+
+ const tag = try std.fmt.parseInt(u32, args[1], 10);
+ const tags = @as(u32, 1) << @intCast(u5, tag - 1);
if (seat.focused_view) |view| {
const new_tags = view.current_tags ^ tags;
if (new_tags != 0) {
diff --git a/src/command/zoom.zig b/src/command/zoom.zig
index b603a69..59156ab 100644
--- a/src/command/zoom.zig
+++ b/src/command/zoom.zig
@@ -15,16 +15,25 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
+const std = @import("std");
+
const c = @import("../c.zig");
-const Arg = @import("../Command.zig").Arg;
+const Error = @import("../command.zig").Error;
const Seat = @import("../Seat.zig");
const View = @import("../View.zig");
const ViewStack = @import("../view_stack.zig").ViewStack;
/// Bump the focused view to the top of the stack. If the view on the top of
/// the stack is focused, bump the second view to the top.
-pub fn zoom(seat: *Seat, arg: Arg) void {
+pub fn zoom(
+ allocator: *std.mem.Allocator,
+ seat: *Seat,
+ args: []const []const u8,
+ failure_message: *[]const u8,
+) Error!void {
+ if (args.len > 1) return Error.TooManyArguments;
+
if (seat.focused_view) |current_focus| {
const output = seat.focused_output;
const focused_node = @fieldParentPtr(ViewStack(View).Node, "view", current_focus);