command: allow output on success, refactor
This commit is contained in:
@ -17,8 +17,6 @@
|
||||
|
||||
const std = @import("std");
|
||||
|
||||
const c = @import("../c.zig");
|
||||
|
||||
const Error = @import("../command.zig").Error;
|
||||
const Seat = @import("../Seat.zig");
|
||||
|
||||
@ -27,11 +25,9 @@ pub fn close(
|
||||
allocator: *std.mem.Allocator,
|
||||
seat: *Seat,
|
||||
args: []const []const u8,
|
||||
failure_message: *[]const u8,
|
||||
out: *?[]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.
|
||||
view.close();
|
||||
}
|
||||
// Note: we don't call arrange() here as it will be called
|
||||
// automatically when the view is unmapped.
|
||||
if (seat.focused_view) |view| view.close();
|
||||
}
|
||||
|
@ -17,7 +17,6 @@
|
||||
|
||||
const std = @import("std");
|
||||
|
||||
const c = @import("../c.zig");
|
||||
const util = @import("../util.zig");
|
||||
|
||||
const Error = @import("../command.zig").Error;
|
||||
@ -29,7 +28,7 @@ pub fn declareMode(
|
||||
allocator: *std.mem.Allocator,
|
||||
seat: *Seat,
|
||||
args: []const []const u8,
|
||||
failure_message: *[]const u8,
|
||||
out: *?[]const u8,
|
||||
) Error!void {
|
||||
if (args.len < 2) return Error.NotEnoughArguments;
|
||||
if (args.len > 2) return Error.TooManyArguments;
|
||||
@ -38,17 +37,17 @@ pub fn declareMode(
|
||||
const new_mode_name = args[1];
|
||||
|
||||
if (config.mode_to_id.get(new_mode_name) != null) {
|
||||
failure_message.* = try std.fmt.allocPrint(
|
||||
out.* = try std.fmt.allocPrint(
|
||||
allocator,
|
||||
"mode '{}' already exists and cannot be re-declared",
|
||||
.{new_mode_name},
|
||||
);
|
||||
return Error.CommandFailed;
|
||||
return Error.Other;
|
||||
}
|
||||
|
||||
const owned_name = try std.mem.dupe(util.gpa, u8, new_mode_name);
|
||||
errdefer util.gpa.free(owned_name);
|
||||
try config.mode_to_id.putNoClobber(owned_name, config.modes.items.len);
|
||||
errdefer _ = config.mode_to_id.remove(owned_name);
|
||||
try config.modes.append(std.ArrayList(Mapping).init(allocator));
|
||||
try config.modes.append(std.ArrayList(Mapping).init(util.gpa));
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ pub fn enterMode(
|
||||
allocator: *std.mem.Allocator,
|
||||
seat: *Seat,
|
||||
args: []const []const u8,
|
||||
failure_message: *[]const u8,
|
||||
out: *?[]const u8,
|
||||
) Error!void {
|
||||
if (args.len < 2) return Error.NotEnoughArguments;
|
||||
if (args.len > 2) return Error.TooManyArguments;
|
||||
@ -33,11 +33,11 @@ pub fn enterMode(
|
||||
const config = seat.input_manager.server.config;
|
||||
const target_mode = args[1];
|
||||
seat.mode_id = config.mode_to_id.getValue(target_mode) orelse {
|
||||
failure_message.* = try std.fmt.allocPrint(
|
||||
out.* = try std.fmt.allocPrint(
|
||||
allocator,
|
||||
"cannot enter non-existant mode '{}'",
|
||||
.{target_mode},
|
||||
);
|
||||
return Error.CommandFailed;
|
||||
return Error.Other;
|
||||
};
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ pub fn exit(
|
||||
allocator: *std.mem.Allocator,
|
||||
seat: *Seat,
|
||||
args: []const []const u8,
|
||||
failure_message: *[]const u8,
|
||||
out: *?[]const u8,
|
||||
) Error!void {
|
||||
if (args.len > 1) return Error.TooManyArguments;
|
||||
c.wl_display_terminate(seat.input_manager.server.wl_display);
|
||||
|
@ -17,10 +17,8 @@
|
||||
|
||||
const std = @import("std");
|
||||
|
||||
const c = @import("../c.zig");
|
||||
|
||||
const Error = @import("../command.zig").Error;
|
||||
const Direction = @import("../command.zig").Direction;
|
||||
const Error = @import("../command.zig").Error;
|
||||
const Output = @import("../Output.zig");
|
||||
const Seat = @import("../Seat.zig");
|
||||
|
||||
@ -30,13 +28,14 @@ pub fn focusOutput(
|
||||
allocator: *std.mem.Allocator,
|
||||
seat: *Seat,
|
||||
args: []const []const u8,
|
||||
failure_message: *[]const u8,
|
||||
out: *?[]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) {
|
||||
std.debug.assert(root.outputs.len == 0);
|
||||
|
@ -17,10 +17,8 @@
|
||||
|
||||
const std = @import("std");
|
||||
|
||||
const c = @import("../c.zig");
|
||||
|
||||
const Error = @import("../command.zig").Error;
|
||||
const Direction = @import("../command.zig").Direction;
|
||||
const Error = @import("../command.zig").Error;
|
||||
const Seat = @import("../Seat.zig");
|
||||
const View = @import("../View.zig");
|
||||
const ViewStack = @import("../view_stack.zig").ViewStack;
|
||||
@ -31,7 +29,7 @@ pub fn focusView(
|
||||
allocator: *std.mem.Allocator,
|
||||
seat: *Seat,
|
||||
args: []const []const u8,
|
||||
failure_message: *[]const u8,
|
||||
out: *?[]const u8,
|
||||
) Error!void {
|
||||
if (args.len < 2) return Error.NotEnoughArguments;
|
||||
if (args.len > 2) return Error.TooManyArguments;
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
const std = @import("std");
|
||||
|
||||
const c = @import("../c.zig");
|
||||
const util = @import("../util.zig");
|
||||
|
||||
const Error = @import("../command.zig").Error;
|
||||
const Seat = @import("../Seat.zig");
|
||||
@ -26,12 +26,12 @@ pub fn layout(
|
||||
allocator: *std.mem.Allocator,
|
||||
seat: *Seat,
|
||||
args: []const []const u8,
|
||||
failure_message: *[]const u8,
|
||||
out: *?[]const u8,
|
||||
) Error!void {
|
||||
if (args.len < 2) return Error.NotEnoughArguments;
|
||||
|
||||
allocator.free(seat.focused_output.layout);
|
||||
seat.focused_output.layout = try std.mem.join(allocator, " ", args[1..]);
|
||||
util.gpa.free(seat.focused_output.layout);
|
||||
seat.focused_output.layout = try std.mem.join(util.gpa, " ", args[1..]);
|
||||
|
||||
seat.focused_output.arrangeViews();
|
||||
seat.input_manager.server.root.startTransaction();
|
||||
|
@ -18,6 +18,7 @@
|
||||
const std = @import("std");
|
||||
|
||||
const c = @import("../c.zig");
|
||||
const util = @import("../util.zig");
|
||||
|
||||
const Error = @import("../command.zig").Error;
|
||||
const Mapping = @import("../Mapping.zig");
|
||||
@ -46,7 +47,7 @@ pub fn map(
|
||||
allocator: *std.mem.Allocator,
|
||||
seat: *Seat,
|
||||
args: []const []const u8,
|
||||
failure_message: *[]const u8,
|
||||
out: *?[]const u8,
|
||||
) Error!void {
|
||||
if (args.len < 4) return Error.NotEnoughArguments;
|
||||
|
||||
@ -54,12 +55,12 @@ pub fn map(
|
||||
const config = seat.input_manager.server.config;
|
||||
const target_mode = args[1];
|
||||
const mode_id = config.mode_to_id.getValue(target_mode) orelse {
|
||||
failure_message.* = try std.fmt.allocPrint(
|
||||
out.* = try std.fmt.allocPrint(
|
||||
allocator,
|
||||
"cannot add mapping to non-existant mode '{}p'",
|
||||
.{target_mode},
|
||||
);
|
||||
return Error.CommandFailed;
|
||||
return Error.Other;
|
||||
};
|
||||
|
||||
// Parse the modifiers
|
||||
@ -72,12 +73,12 @@ pub fn map(
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
failure_message.* = try std.fmt.allocPrint(
|
||||
out.* = try std.fmt.allocPrint(
|
||||
allocator,
|
||||
"invalid modifier '{}'",
|
||||
.{mod_name},
|
||||
);
|
||||
return Error.CommandFailed;
|
||||
return Error.Other;
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,26 +87,26 @@ pub fn map(
|
||||
defer allocator.free(keysym_name);
|
||||
const keysym = c.xkb_keysym_from_name(keysym_name, .XKB_KEYSYM_CASE_INSENSITIVE);
|
||||
if (keysym == c.XKB_KEY_NoSymbol) {
|
||||
failure_message.* = try std.fmt.allocPrint(
|
||||
out.* = try std.fmt.allocPrint(
|
||||
allocator,
|
||||
"invalid keysym '{}'",
|
||||
.{args[3]},
|
||||
);
|
||||
return Error.CommandFailed;
|
||||
return Error.Other;
|
||||
}
|
||||
|
||||
// Check if the mapping already exists
|
||||
const mode_mappings = &config.modes.items[mode_id];
|
||||
for (mode_mappings.items) |existant_mapping| {
|
||||
if (existant_mapping.modifiers == modifiers and existant_mapping.keysym == keysym) {
|
||||
failure_message.* = try std.fmt.allocPrint(
|
||||
out.* = try std.fmt.allocPrint(
|
||||
allocator,
|
||||
"a mapping for modifiers '{}' and keysym '{}' already exists",
|
||||
.{ args[2], args[3] },
|
||||
);
|
||||
return Error.CommandFailed;
|
||||
return Error.Other;
|
||||
}
|
||||
}
|
||||
|
||||
try mode_mappings.append(try Mapping.init(allocator, keysym, modifiers, args[4..]));
|
||||
try mode_mappings.append(try Mapping.init(util.gpa, keysym, modifiers, args[4..]));
|
||||
}
|
||||
|
@ -17,8 +17,6 @@
|
||||
|
||||
const std = @import("std");
|
||||
|
||||
const c = @import("../c.zig");
|
||||
|
||||
const Error = @import("../command.zig").Error;
|
||||
const Seat = @import("../Seat.zig");
|
||||
|
||||
@ -27,16 +25,13 @@ pub fn modMasterCount(
|
||||
allocator: *std.mem.Allocator,
|
||||
seat: *Seat,
|
||||
args: []const []const u8,
|
||||
failure_message: *[]const u8,
|
||||
out: *?[]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,
|
||||
std.math.max(0, @intCast(i32, output.master_count) + delta),
|
||||
);
|
||||
output.master_count = @intCast(u32, std.math.max(0, @intCast(i32, output.master_count) + delta));
|
||||
seat.input_manager.server.root.arrange();
|
||||
}
|
||||
|
@ -17,8 +17,6 @@
|
||||
|
||||
const std = @import("std");
|
||||
|
||||
const c = @import("../c.zig");
|
||||
|
||||
const Error = @import("../command.zig").Error;
|
||||
const Seat = @import("../Seat.zig");
|
||||
|
||||
@ -27,17 +25,14 @@ pub fn modMasterFactor(
|
||||
allocator: *std.mem.Allocator,
|
||||
seat: *Seat,
|
||||
args: []const []const u8,
|
||||
failure_message: *[]const u8,
|
||||
out: *?[]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),
|
||||
0.95,
|
||||
);
|
||||
const new_master_factor = std.math.min(std.math.max(output.master_factor + delta, 0.05), 0.95);
|
||||
if (new_master_factor != output.master_factor) {
|
||||
output.master_factor = new_master_factor;
|
||||
seat.input_manager.server.root.arrange();
|
||||
|
@ -17,10 +17,8 @@
|
||||
|
||||
const std = @import("std");
|
||||
|
||||
const c = @import("../c.zig");
|
||||
|
||||
const Error = @import("../command.zig").Error;
|
||||
const Direction = @import("../command.zig").Direction;
|
||||
const Error = @import("../command.zig").Error;
|
||||
const Output = @import("../Output.zig");
|
||||
const Seat = @import("../Seat.zig");
|
||||
|
||||
@ -30,7 +28,7 @@ pub fn sendToOutput(
|
||||
allocator: *std.mem.Allocator,
|
||||
seat: *Seat,
|
||||
args: []const []const u8,
|
||||
failure_message: *[]const u8,
|
||||
out: *?[]const u8,
|
||||
) Error!void {
|
||||
if (args.len < 2) return Error.NotEnoughArguments;
|
||||
if (args.len > 2) return Error.TooManyArguments;
|
||||
@ -45,7 +43,7 @@ pub fn sendToOutput(
|
||||
return;
|
||||
}
|
||||
|
||||
// Send to the next/preg output in the list if there is one, else wrap
|
||||
// Send to the next/prev output in the list if there is one, else wrap
|
||||
const current_node = @fieldParentPtr(std.TailQueue(Output).Node, "data", view.output);
|
||||
const destination_output = switch (direction) {
|
||||
.Next => if (current_node.next) |node| &node.data else &root.outputs.first.?.data,
|
||||
|
@ -35,13 +35,12 @@ pub fn setOption(
|
||||
allocator: *std.mem.Allocator,
|
||||
seat: *Seat,
|
||||
args: []const []const u8,
|
||||
failure_message: *[]const u8,
|
||||
out: *?[]const u8,
|
||||
) Error!void {
|
||||
if (args.len < 3) return Error.NotEnoughArguments;
|
||||
if (args.len > 3) return Error.TooManyArguments;
|
||||
|
||||
const config = &seat.input_manager.server.config;
|
||||
|
||||
const option = std.meta.stringToEnum(Option, args[1]) orelse return Error.UnknownOption;
|
||||
|
||||
// Assign value to option.
|
||||
@ -59,7 +58,7 @@ pub fn setOption(
|
||||
}
|
||||
|
||||
/// Parse a color in the format #RRGGBB or #RRGGBBAA
|
||||
pub fn parseRgba(string: []const u8) ![4]f32 {
|
||||
fn parseRgba(string: []const u8) ![4]f32 {
|
||||
if (string[0] != '#' or (string.len != 7 and string.len != 9)) return error.InvalidRgba;
|
||||
|
||||
const r = try std.fmt.parseInt(u8, string[1..3], 16);
|
||||
|
@ -25,7 +25,7 @@ pub fn spawn(
|
||||
allocator: *std.mem.Allocator,
|
||||
seat: *Seat,
|
||||
args: []const []const u8,
|
||||
failure_message: *[]const u8,
|
||||
out: *?[]const u8,
|
||||
) Error!void {
|
||||
if (args.len < 2) return Error.NotEnoughArguments;
|
||||
|
||||
@ -37,11 +37,11 @@ pub fn spawn(
|
||||
defer child.deinit();
|
||||
|
||||
std.ChildProcess.spawn(child) catch |err| {
|
||||
failure_message.* = try std.fmt.allocPrint(
|
||||
out.* = try std.fmt.allocPrint(
|
||||
allocator,
|
||||
"failed to spawn {}: {}.",
|
||||
.{ cmd, err },
|
||||
);
|
||||
return Error.CommandFailed;
|
||||
return Error.Other;
|
||||
};
|
||||
}
|
||||
|
@ -25,9 +25,9 @@ pub fn setFocusedTags(
|
||||
allocator: *std.mem.Allocator,
|
||||
seat: *Seat,
|
||||
args: []const []const u8,
|
||||
failure_message: *[]const u8,
|
||||
out: *?[]const u8,
|
||||
) Error!void {
|
||||
const tags = try parseTags(allocator, args, failure_message);
|
||||
const tags = try parseTags(allocator, args, out);
|
||||
if (seat.focused_output.current_focused_tags != tags) {
|
||||
seat.focused_output.pending_focused_tags = tags;
|
||||
seat.input_manager.server.root.arrange();
|
||||
@ -39,9 +39,9 @@ pub fn setViewTags(
|
||||
allocator: *std.mem.Allocator,
|
||||
seat: *Seat,
|
||||
args: []const []const u8,
|
||||
failure_message: *[]const u8,
|
||||
out: *?[]const u8,
|
||||
) Error!void {
|
||||
const tags = try parseTags(allocator, args, failure_message);
|
||||
const tags = try parseTags(allocator, args, out);
|
||||
if (seat.focused_view) |view| {
|
||||
if (view.current_tags != tags) {
|
||||
view.pending_tags = tags;
|
||||
@ -55,9 +55,9 @@ pub fn toggleFocusedTags(
|
||||
allocator: *std.mem.Allocator,
|
||||
seat: *Seat,
|
||||
args: []const []const u8,
|
||||
failure_message: *[]const u8,
|
||||
out: *?[]const u8,
|
||||
) Error!void {
|
||||
const tags = try parseTags(allocator, args, failure_message);
|
||||
const tags = try parseTags(allocator, args, out);
|
||||
const output = seat.focused_output;
|
||||
const new_focused_tags = output.current_focused_tags ^ tags;
|
||||
if (new_focused_tags != 0) {
|
||||
@ -71,9 +71,9 @@ pub fn toggleViewTags(
|
||||
allocator: *std.mem.Allocator,
|
||||
seat: *Seat,
|
||||
args: []const []const u8,
|
||||
failure_message: *[]const u8,
|
||||
out: *?[]const u8,
|
||||
) Error!void {
|
||||
const tags = try parseTags(allocator, args, failure_message);
|
||||
const tags = try parseTags(allocator, args, out);
|
||||
if (seat.focused_view) |view| {
|
||||
const new_tags = view.current_tags ^ tags;
|
||||
if (new_tags != 0) {
|
||||
@ -86,7 +86,7 @@ pub fn toggleViewTags(
|
||||
fn parseTags(
|
||||
allocator: *std.mem.Allocator,
|
||||
args: []const []const u8,
|
||||
failure_message: *[]const u8,
|
||||
out: *?[]const u8,
|
||||
) Error!u32 {
|
||||
if (args.len < 2) return Error.NotEnoughArguments;
|
||||
if (args.len > 2) return Error.TooManyArguments;
|
||||
@ -94,8 +94,8 @@ fn parseTags(
|
||||
const tags = try std.fmt.parseInt(u32, args[1], 10);
|
||||
|
||||
if (tags == 0) {
|
||||
failure_message.* = try std.fmt.allocPrint(allocator, "tagmask may not be 0", .{});
|
||||
return Error.CommandFailed;
|
||||
out.* = try std.fmt.allocPrint(allocator, "tagmask may not be 0", .{});
|
||||
return Error.Other;
|
||||
}
|
||||
|
||||
return tags;
|
||||
|
@ -17,8 +17,6 @@
|
||||
|
||||
const std = @import("std");
|
||||
|
||||
const c = @import("../c.zig");
|
||||
|
||||
const Error = @import("../command.zig").Error;
|
||||
const Seat = @import("../Seat.zig");
|
||||
|
||||
@ -28,7 +26,7 @@ pub fn toggleFloat(
|
||||
allocator: *std.mem.Allocator,
|
||||
seat: *Seat,
|
||||
args: []const []const u8,
|
||||
failure_message: *[]const u8,
|
||||
out: *?[]const u8,
|
||||
) Error!void {
|
||||
if (args.len > 1) return Error.TooManyArguments;
|
||||
if (seat.focused_view) |view| {
|
||||
|
@ -17,8 +17,6 @@
|
||||
|
||||
const std = @import("std");
|
||||
|
||||
const c = @import("../c.zig");
|
||||
|
||||
const Error = @import("../command.zig").Error;
|
||||
const Seat = @import("../Seat.zig");
|
||||
const View = @import("../View.zig");
|
||||
@ -30,7 +28,7 @@ pub fn zoom(
|
||||
allocator: *std.mem.Allocator,
|
||||
seat: *Seat,
|
||||
args: []const []const u8,
|
||||
failure_message: *[]const u8,
|
||||
out: *?[]const u8,
|
||||
) Error!void {
|
||||
if (args.len > 1) return Error.TooManyArguments;
|
||||
|
||||
|
Reference in New Issue
Block a user