command: Remove allocator arg
This commit is contained in:
parent
da59632cea
commit
89433073d6
@ -103,7 +103,7 @@ fn handleRequest(control: *zriver.ControlV1, request: zriver.ControlV1.Request,
|
|||||||
|
|
||||||
var out: ?[]const u8 = null;
|
var out: ?[]const u8 = null;
|
||||||
defer if (out) |s| util.gpa.free(s);
|
defer if (out) |s| util.gpa.free(s);
|
||||||
command.run(util.gpa, seat, args.items, &out) catch |err| {
|
command.run(seat, args.items, &out) catch |err| {
|
||||||
const failure_message = switch (err) {
|
const failure_message = switch (err) {
|
||||||
command.Error.OutOfMemory => {
|
command.Error.OutOfMemory => {
|
||||||
callback.getClient().postNoMemory();
|
callback.getClient().postNoMemory();
|
||||||
|
@ -361,7 +361,7 @@ fn runMappedCommand(self: *Self, mapping: *const Mapping) void {
|
|||||||
var out: ?[]const u8 = null;
|
var out: ?[]const u8 = null;
|
||||||
defer if (out) |s| util.gpa.free(s);
|
defer if (out) |s| util.gpa.free(s);
|
||||||
const args = mapping.command_args;
|
const args = mapping.command_args;
|
||||||
command.run(util.gpa, self, args, &out) catch |err| {
|
command.run(self, args, &out) catch |err| {
|
||||||
const failure_message = switch (err) {
|
const failure_message = switch (err) {
|
||||||
command.Error.Other => out.?,
|
command.Error.Other => out.?,
|
||||||
else => command.errToMsg(err),
|
else => command.errToMsg(err),
|
||||||
|
@ -38,7 +38,7 @@ pub const Orientation = enum {
|
|||||||
|
|
||||||
// zig fmt: off
|
// zig fmt: off
|
||||||
const command_impls = std.ComptimeStringMap(
|
const command_impls = std.ComptimeStringMap(
|
||||||
fn (std.mem.Allocator, *Seat, []const [:0]const u8, *?[]const u8) Error!void,
|
fn (*Seat, []const [:0]const u8, *?[]const u8) Error!void,
|
||||||
.{
|
.{
|
||||||
.{ "attach-mode", @import("command/attach_mode.zig").attachMode },
|
.{ "attach-mode", @import("command/attach_mode.zig").attachMode },
|
||||||
.{ "background-color", @import("command/config.zig").backgroundColor },
|
.{ "background-color", @import("command/config.zig").backgroundColor },
|
||||||
@ -118,7 +118,6 @@ pub const Error = error{
|
|||||||
/// The caller is then responsible for freeing that slice, which will be
|
/// The caller is then responsible for freeing that slice, which will be
|
||||||
/// allocated using the provided allocator.
|
/// allocated using the provided allocator.
|
||||||
pub fn run(
|
pub fn run(
|
||||||
allocator: std.mem.Allocator,
|
|
||||||
seat: *Seat,
|
seat: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
out: *?[]const u8,
|
out: *?[]const u8,
|
||||||
@ -126,7 +125,7 @@ pub fn run(
|
|||||||
assert(out.* == null);
|
assert(out.* == null);
|
||||||
if (args.len == 0) return Error.NoCommand;
|
if (args.len == 0) return Error.NoCommand;
|
||||||
const impl_fn = command_impls.get(args[0]) orelse return Error.UnknownCommand;
|
const impl_fn = command_impls.get(args[0]) orelse return Error.UnknownCommand;
|
||||||
try impl_fn(allocator, seat, args, out);
|
try impl_fn(seat, args, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return a short error message for the given error. Passing Error.Other is UB
|
/// Return a short error message for the given error. Passing Error.Other is UB
|
||||||
|
@ -17,15 +17,12 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const mem = std.mem;
|
const mem = std.mem;
|
||||||
|
|
||||||
const util = @import("../util.zig");
|
|
||||||
|
|
||||||
const server = &@import("../main.zig").server;
|
const server = &@import("../main.zig").server;
|
||||||
|
|
||||||
const Error = @import("../command.zig").Error;
|
const Error = @import("../command.zig").Error;
|
||||||
const Seat = @import("../Seat.zig");
|
const Seat = @import("../Seat.zig");
|
||||||
|
|
||||||
pub fn attachMode(
|
pub fn attachMode(
|
||||||
_: mem.Allocator,
|
|
||||||
_: *Seat,
|
_: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
_: *?[]const u8,
|
_: *?[]const u8,
|
||||||
|
@ -21,7 +21,6 @@ const Seat = @import("../Seat.zig");
|
|||||||
|
|
||||||
/// Close the focused view, if any.
|
/// Close the focused view, if any.
|
||||||
pub fn close(
|
pub fn close(
|
||||||
_: std.mem.Allocator,
|
|
||||||
seat: *Seat,
|
seat: *Seat,
|
||||||
_: []const [:0]const u8,
|
_: []const [:0]const u8,
|
||||||
_: *?[]const u8,
|
_: *?[]const u8,
|
||||||
|
@ -25,7 +25,6 @@ const Seat = @import("../Seat.zig");
|
|||||||
const Config = @import("../Config.zig");
|
const Config = @import("../Config.zig");
|
||||||
|
|
||||||
pub fn borderWidth(
|
pub fn borderWidth(
|
||||||
_: mem.Allocator,
|
|
||||||
_: *Seat,
|
_: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
_: *?[]const u8,
|
_: *?[]const u8,
|
||||||
@ -39,7 +38,6 @@ pub fn borderWidth(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn backgroundColor(
|
pub fn backgroundColor(
|
||||||
_: mem.Allocator,
|
|
||||||
_: *Seat,
|
_: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
_: *?[]const u8,
|
_: *?[]const u8,
|
||||||
@ -54,7 +52,6 @@ pub fn backgroundColor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn borderColorFocused(
|
pub fn borderColorFocused(
|
||||||
_: mem.Allocator,
|
|
||||||
_: *Seat,
|
_: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
_: *?[]const u8,
|
_: *?[]const u8,
|
||||||
@ -69,7 +66,6 @@ pub fn borderColorFocused(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn borderColorUnfocused(
|
pub fn borderColorUnfocused(
|
||||||
_: mem.Allocator,
|
|
||||||
_: *Seat,
|
_: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
_: *?[]const u8,
|
_: *?[]const u8,
|
||||||
@ -84,7 +80,6 @@ pub fn borderColorUnfocused(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn borderColorUrgent(
|
pub fn borderColorUrgent(
|
||||||
_: mem.Allocator,
|
|
||||||
_: *Seat,
|
_: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
_: *?[]const u8,
|
_: *?[]const u8,
|
||||||
@ -99,7 +94,6 @@ pub fn borderColorUrgent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn setCursorWarp(
|
pub fn setCursorWarp(
|
||||||
_: mem.Allocator,
|
|
||||||
_: *Seat,
|
_: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
_: *?[]const u8,
|
_: *?[]const u8,
|
||||||
|
@ -26,7 +26,6 @@ const Seat = @import("../Seat.zig");
|
|||||||
|
|
||||||
/// Declare a new keymap mode
|
/// Declare a new keymap mode
|
||||||
pub fn declareMode(
|
pub fn declareMode(
|
||||||
_: std.mem.Allocator,
|
|
||||||
_: *Seat,
|
_: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
_: *?[]const u8,
|
_: *?[]const u8,
|
||||||
|
@ -17,13 +17,13 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
const server = &@import("../main.zig").server;
|
const server = &@import("../main.zig").server;
|
||||||
|
const util = @import("../util.zig");
|
||||||
|
|
||||||
const Error = @import("../command.zig").Error;
|
const Error = @import("../command.zig").Error;
|
||||||
const Seat = @import("../Seat.zig");
|
const Seat = @import("../Seat.zig");
|
||||||
|
|
||||||
/// Switch to the given mode
|
/// Switch to the given mode
|
||||||
pub fn enterMode(
|
pub fn enterMode(
|
||||||
allocator: std.mem.Allocator,
|
|
||||||
seat: *Seat,
|
seat: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
out: *?[]const u8,
|
out: *?[]const u8,
|
||||||
@ -33,7 +33,7 @@ pub fn enterMode(
|
|||||||
|
|
||||||
if (seat.mode_id == 1) {
|
if (seat.mode_id == 1) {
|
||||||
out.* = try std.fmt.allocPrint(
|
out.* = try std.fmt.allocPrint(
|
||||||
allocator,
|
util.gpa,
|
||||||
"manually exiting mode 'locked' is not allowed",
|
"manually exiting mode 'locked' is not allowed",
|
||||||
.{},
|
.{},
|
||||||
);
|
);
|
||||||
@ -43,7 +43,7 @@ pub fn enterMode(
|
|||||||
const target_mode = args[1];
|
const target_mode = args[1];
|
||||||
const mode_id = server.config.mode_to_id.get(target_mode) orelse {
|
const mode_id = server.config.mode_to_id.get(target_mode) orelse {
|
||||||
out.* = try std.fmt.allocPrint(
|
out.* = try std.fmt.allocPrint(
|
||||||
allocator,
|
util.gpa,
|
||||||
"cannot enter non-existant mode '{s}'",
|
"cannot enter non-existant mode '{s}'",
|
||||||
.{target_mode},
|
.{target_mode},
|
||||||
);
|
);
|
||||||
@ -52,7 +52,7 @@ pub fn enterMode(
|
|||||||
|
|
||||||
if (mode_id == 1) {
|
if (mode_id == 1) {
|
||||||
out.* = try std.fmt.allocPrint(
|
out.* = try std.fmt.allocPrint(
|
||||||
allocator,
|
util.gpa,
|
||||||
"manually entering mode 'locked' is not allowed",
|
"manually entering mode 'locked' is not allowed",
|
||||||
.{},
|
.{},
|
||||||
);
|
);
|
||||||
|
@ -23,7 +23,6 @@ const Seat = @import("../Seat.zig");
|
|||||||
|
|
||||||
/// Exit the compositor, terminating the wayland session.
|
/// Exit the compositor, terminating the wayland session.
|
||||||
pub fn exit(
|
pub fn exit(
|
||||||
_: std.mem.Allocator,
|
|
||||||
_: *Seat,
|
_: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
_: *?[]const u8,
|
_: *?[]const u8,
|
||||||
|
@ -31,7 +31,6 @@ const FilterKind = enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub fn floatFilterAdd(
|
pub fn floatFilterAdd(
|
||||||
_: mem.Allocator,
|
|
||||||
_: *Seat,
|
_: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
_: *?[]const u8,
|
_: *?[]const u8,
|
||||||
@ -53,7 +52,6 @@ pub fn floatFilterAdd(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn floatFilterRemove(
|
pub fn floatFilterRemove(
|
||||||
_: mem.Allocator,
|
|
||||||
_: *Seat,
|
_: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
_: *?[]const u8,
|
_: *?[]const u8,
|
||||||
@ -72,7 +70,6 @@ pub fn floatFilterRemove(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn csdFilterAdd(
|
pub fn csdFilterAdd(
|
||||||
_: mem.Allocator,
|
|
||||||
_: *Seat,
|
_: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
_: *?[]const u8,
|
_: *?[]const u8,
|
||||||
@ -96,7 +93,6 @@ pub fn csdFilterAdd(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn csdFilterRemove(
|
pub fn csdFilterRemove(
|
||||||
_: mem.Allocator,
|
|
||||||
_: *Seat,
|
_: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
_: *?[]const u8,
|
_: *?[]const u8,
|
||||||
|
@ -17,14 +17,12 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
const server = &@import("../main.zig").server;
|
const server = &@import("../main.zig").server;
|
||||||
const util = @import("../util.zig");
|
|
||||||
|
|
||||||
const Config = @import("../Config.zig");
|
const Config = @import("../Config.zig");
|
||||||
const Error = @import("../command.zig").Error;
|
const Error = @import("../command.zig").Error;
|
||||||
const Seat = @import("../Seat.zig");
|
const Seat = @import("../Seat.zig");
|
||||||
|
|
||||||
pub fn focusFollowsCursor(
|
pub fn focusFollowsCursor(
|
||||||
_: std.mem.Allocator,
|
|
||||||
_: *Seat,
|
_: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
_: *?[]const u8,
|
_: *?[]const u8,
|
||||||
|
@ -27,7 +27,6 @@ const ViewStack = @import("../view_stack.zig").ViewStack;
|
|||||||
/// Focus either the next or the previous visible view, depending on the enum
|
/// 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.
|
/// passed. Does nothing if there are 1 or 0 views in the stack.
|
||||||
pub fn focusView(
|
pub fn focusView(
|
||||||
_: std.mem.Allocator,
|
|
||||||
seat: *Seat,
|
seat: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
_: *?[]const u8,
|
_: *?[]const u8,
|
||||||
|
@ -28,14 +28,13 @@ const InputConfig = @import("../InputConfig.zig");
|
|||||||
const InputManager = @import("../InputManager.zig");
|
const InputManager = @import("../InputManager.zig");
|
||||||
|
|
||||||
pub fn listInputs(
|
pub fn listInputs(
|
||||||
allocator: mem.Allocator,
|
|
||||||
_: *Seat,
|
_: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
out: *?[]const u8,
|
out: *?[]const u8,
|
||||||
) Error!void {
|
) Error!void {
|
||||||
if (args.len > 1) return error.TooManyArguments;
|
if (args.len > 1) return error.TooManyArguments;
|
||||||
|
|
||||||
var input_list = std.ArrayList(u8).init(allocator);
|
var input_list = std.ArrayList(u8).init(util.gpa);
|
||||||
const writer = input_list.writer();
|
const writer = input_list.writer();
|
||||||
var prev = false;
|
var prev = false;
|
||||||
|
|
||||||
@ -61,14 +60,13 @@ pub fn listInputs(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn listInputConfigs(
|
pub fn listInputConfigs(
|
||||||
allocator: mem.Allocator,
|
|
||||||
_: *Seat,
|
_: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
out: *?[]const u8,
|
out: *?[]const u8,
|
||||||
) Error!void {
|
) Error!void {
|
||||||
if (args.len > 1) return error.TooManyArguments;
|
if (args.len > 1) return error.TooManyArguments;
|
||||||
|
|
||||||
var input_list = std.ArrayList(u8).init(allocator);
|
var input_list = std.ArrayList(u8).init(util.gpa);
|
||||||
const writer = input_list.writer();
|
const writer = input_list.writer();
|
||||||
|
|
||||||
for (server.input_manager.input_configs.items) |*input_config, i| {
|
for (server.input_manager.input_configs.items) |*input_config, i| {
|
||||||
@ -126,7 +124,6 @@ pub fn listInputConfigs(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn input(
|
pub fn input(
|
||||||
_: mem.Allocator,
|
|
||||||
_: *Seat,
|
_: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
_: *?[]const u8,
|
_: *?[]const u8,
|
||||||
@ -140,8 +137,6 @@ pub fn input(
|
|||||||
const input_config = for (server.input_manager.input_configs.items) |*input_config| {
|
const input_config = for (server.input_manager.input_configs.items) |*input_config| {
|
||||||
if (mem.eql(u8, input_config.identifier, args[1])) break input_config;
|
if (mem.eql(u8, input_config.identifier, args[1])) break input_config;
|
||||||
} else blk: {
|
} else blk: {
|
||||||
// Use util.gpa instead of allocator to assure the identifier is
|
|
||||||
// allocated by the same allocator as the ArrayList.
|
|
||||||
try server.input_manager.input_configs.ensureUnusedCapacity(1);
|
try server.input_manager.input_configs.ensureUnusedCapacity(1);
|
||||||
server.input_manager.input_configs.appendAssumeCapacity(.{
|
server.input_manager.input_configs.appendAssumeCapacity(.{
|
||||||
.identifier = try util.gpa.dupe(u8, args[1]),
|
.identifier = try util.gpa.dupe(u8, args[1]),
|
||||||
|
@ -25,7 +25,6 @@ const Error = @import("../command.zig").Error;
|
|||||||
const Seat = @import("../Seat.zig");
|
const Seat = @import("../Seat.zig");
|
||||||
|
|
||||||
pub fn outputLayout(
|
pub fn outputLayout(
|
||||||
_: mem.Allocator,
|
|
||||||
seat: *Seat,
|
seat: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
_: *?[]const u8,
|
_: *?[]const u8,
|
||||||
@ -39,7 +38,6 @@ pub fn outputLayout(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn defaultLayout(
|
pub fn defaultLayout(
|
||||||
_: mem.Allocator,
|
|
||||||
_: *Seat,
|
_: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
_: *?[]const u8,
|
_: *?[]const u8,
|
||||||
@ -62,7 +60,6 @@ pub fn defaultLayout(
|
|||||||
/// riverctl send-layout-cmd rivertile "mod-main-factor -0.1"
|
/// riverctl send-layout-cmd rivertile "mod-main-factor -0.1"
|
||||||
/// riverctl send-layout-cmd rivertile "main-location top"
|
/// riverctl send-layout-cmd rivertile "main-location top"
|
||||||
pub fn sendLayoutCmd(
|
pub fn sendLayoutCmd(
|
||||||
_: mem.Allocator,
|
|
||||||
seat: *Seat,
|
seat: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
_: *?[]const u8,
|
_: *?[]const u8,
|
||||||
|
@ -34,7 +34,6 @@ const Seat = @import("../Seat.zig");
|
|||||||
/// Example:
|
/// Example:
|
||||||
/// map normal Mod4+Shift Return spawn foot
|
/// map normal Mod4+Shift Return spawn foot
|
||||||
pub fn map(
|
pub fn map(
|
||||||
allocator: mem.Allocator,
|
|
||||||
seat: *Seat,
|
seat: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
out: *?[]const u8,
|
out: *?[]const u8,
|
||||||
@ -50,9 +49,9 @@ pub fn map(
|
|||||||
const modifiers_raw = args[2 + offset];
|
const modifiers_raw = args[2 + offset];
|
||||||
const keysym_raw = args[3 + offset];
|
const keysym_raw = args[3 + offset];
|
||||||
|
|
||||||
const mode_id = try modeNameToId(allocator, mode_raw, out);
|
const mode_id = try modeNameToId(mode_raw, out);
|
||||||
const modifiers = try parseModifiers(allocator, modifiers_raw, out);
|
const modifiers = try parseModifiers(modifiers_raw, out);
|
||||||
const keysym = try parseKeysym(allocator, keysym_raw, out);
|
const keysym = try parseKeysym(keysym_raw, out);
|
||||||
|
|
||||||
const mode_mappings = &server.config.modes.items[mode_id].mappings;
|
const mode_mappings = &server.config.modes.items[mode_id].mappings;
|
||||||
|
|
||||||
@ -65,7 +64,7 @@ pub fn map(
|
|||||||
// Warn user if they overwrote an existing keybinding using riverctl.
|
// Warn user if they overwrote an existing keybinding using riverctl.
|
||||||
const opts = if (optionals.release) "-release " else "";
|
const opts = if (optionals.release) "-release " else "";
|
||||||
out.* = try fmt.allocPrint(
|
out.* = try fmt.allocPrint(
|
||||||
allocator,
|
util.gpa,
|
||||||
"overwrote an existing keybinding: {s} {s}{s} {s}",
|
"overwrote an existing keybinding: {s} {s}{s} {s}",
|
||||||
.{ mode_raw, opts, modifiers_raw, keysym_raw },
|
.{ mode_raw, opts, modifiers_raw, keysym_raw },
|
||||||
);
|
);
|
||||||
@ -83,7 +82,6 @@ pub fn map(
|
|||||||
/// Example:
|
/// Example:
|
||||||
/// map-pointer normal Mod4 BTN_LEFT move-view
|
/// map-pointer normal Mod4 BTN_LEFT move-view
|
||||||
pub fn mapPointer(
|
pub fn mapPointer(
|
||||||
allocator: mem.Allocator,
|
|
||||||
_: *Seat,
|
_: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
out: *?[]const u8,
|
out: *?[]const u8,
|
||||||
@ -91,9 +89,9 @@ pub fn mapPointer(
|
|||||||
if (args.len < 5) return Error.NotEnoughArguments;
|
if (args.len < 5) return Error.NotEnoughArguments;
|
||||||
if (args.len > 5) return Error.TooManyArguments;
|
if (args.len > 5) return Error.TooManyArguments;
|
||||||
|
|
||||||
const mode_id = try modeNameToId(allocator, args[1], out);
|
const mode_id = try modeNameToId(args[1], out);
|
||||||
const modifiers = try parseModifiers(allocator, args[2], out);
|
const modifiers = try parseModifiers(args[2], out);
|
||||||
const event_code = try parseEventCode(allocator, args[3], out);
|
const event_code = try parseEventCode(args[3], out);
|
||||||
|
|
||||||
const action = if (mem.eql(u8, args[4], "move-view"))
|
const action = if (mem.eql(u8, args[4], "move-view"))
|
||||||
PointerMapping.Action.move
|
PointerMapping.Action.move
|
||||||
@ -101,7 +99,7 @@ pub fn mapPointer(
|
|||||||
PointerMapping.Action.resize
|
PointerMapping.Action.resize
|
||||||
else {
|
else {
|
||||||
out.* = try fmt.allocPrint(
|
out.* = try fmt.allocPrint(
|
||||||
allocator,
|
util.gpa,
|
||||||
"invalid pointer action {s}, must be move-view or resize-view",
|
"invalid pointer action {s}, must be move-view or resize-view",
|
||||||
.{args[4]},
|
.{args[4]},
|
||||||
);
|
);
|
||||||
@ -122,11 +120,11 @@ pub fn mapPointer(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn modeNameToId(allocator: mem.Allocator, mode_name: []const u8, out: *?[]const u8) !usize {
|
fn modeNameToId(mode_name: []const u8, out: *?[]const u8) !usize {
|
||||||
const config = &server.config;
|
const config = &server.config;
|
||||||
return config.mode_to_id.get(mode_name) orelse {
|
return config.mode_to_id.get(mode_name) orelse {
|
||||||
out.* = try fmt.allocPrint(
|
out.* = try fmt.allocPrint(
|
||||||
allocator,
|
util.gpa,
|
||||||
"cannot add/remove mapping to/from non-existant mode '{s}'",
|
"cannot add/remove mapping to/from non-existant mode '{s}'",
|
||||||
.{mode_name},
|
.{mode_name},
|
||||||
);
|
);
|
||||||
@ -165,30 +163,26 @@ fn pointerMappingExists(
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parseEventCode(allocator: mem.Allocator, name: [:0]const u8, out: *?[]const u8) !u32 {
|
fn parseEventCode(name: [:0]const u8, out: *?[]const u8) !u32 {
|
||||||
const event_code = c.libevdev_event_code_from_name(c.EV_KEY, name);
|
const event_code = c.libevdev_event_code_from_name(c.EV_KEY, name);
|
||||||
if (event_code < 1) {
|
if (event_code < 1) {
|
||||||
out.* = try fmt.allocPrint(allocator, "unknown button {s}", .{name});
|
out.* = try fmt.allocPrint(util.gpa, "unknown button {s}", .{name});
|
||||||
return Error.Other;
|
return Error.Other;
|
||||||
}
|
}
|
||||||
|
|
||||||
return @intCast(u32, event_code);
|
return @intCast(u32, event_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parseKeysym(allocator: mem.Allocator, name: [:0]const u8, out: *?[]const u8) !xkb.Keysym {
|
fn parseKeysym(name: [:0]const u8, out: *?[]const u8) !xkb.Keysym {
|
||||||
const keysym = xkb.Keysym.fromName(name, .case_insensitive);
|
const keysym = xkb.Keysym.fromName(name, .case_insensitive);
|
||||||
if (keysym == .NoSymbol) {
|
if (keysym == .NoSymbol) {
|
||||||
out.* = try fmt.allocPrint(allocator, "invalid keysym '{s}'", .{name});
|
out.* = try fmt.allocPrint(util.gpa, "invalid keysym '{s}'", .{name});
|
||||||
return Error.Other;
|
return Error.Other;
|
||||||
}
|
}
|
||||||
return keysym;
|
return keysym;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parseModifiers(
|
fn parseModifiers(modifiers_str: []const u8, out: *?[]const u8) !wlr.Keyboard.ModifierMask {
|
||||||
allocator: mem.Allocator,
|
|
||||||
modifiers_str: []const u8,
|
|
||||||
out: *?[]const u8,
|
|
||||||
) !wlr.Keyboard.ModifierMask {
|
|
||||||
var it = mem.split(u8, modifiers_str, "+");
|
var it = mem.split(u8, modifiers_str, "+");
|
||||||
var modifiers = wlr.Keyboard.ModifierMask{};
|
var modifiers = wlr.Keyboard.ModifierMask{};
|
||||||
outer: while (it.next()) |mod_name| {
|
outer: while (it.next()) |mod_name| {
|
||||||
@ -210,7 +204,7 @@ fn parseModifiers(
|
|||||||
continue :outer;
|
continue :outer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out.* = try fmt.allocPrint(allocator, "invalid modifier '{s}'", .{mod_name});
|
out.* = try fmt.allocPrint(util.gpa, "invalid modifier '{s}'", .{mod_name});
|
||||||
return Error.Other;
|
return Error.Other;
|
||||||
}
|
}
|
||||||
return modifiers;
|
return modifiers;
|
||||||
@ -257,20 +251,15 @@ fn parseOptionalArgs(args: []const []const u8) OptionalArgsContainer {
|
|||||||
///
|
///
|
||||||
/// Example:
|
/// Example:
|
||||||
/// unmap normal Mod4+Shift Return
|
/// unmap normal Mod4+Shift Return
|
||||||
pub fn unmap(
|
pub fn unmap(seat: *Seat, args: []const [:0]const u8, out: *?[]const u8) Error!void {
|
||||||
allocator: mem.Allocator,
|
|
||||||
seat: *Seat,
|
|
||||||
args: []const [:0]const u8,
|
|
||||||
out: *?[]const u8,
|
|
||||||
) Error!void {
|
|
||||||
const optionals = parseOptionalArgs(args[1..]);
|
const optionals = parseOptionalArgs(args[1..]);
|
||||||
// offset caused by optional arguments
|
// offset caused by optional arguments
|
||||||
const offset = optionals.i;
|
const offset = optionals.i;
|
||||||
if (args.len - offset < 4) return Error.NotEnoughArguments;
|
if (args.len - offset < 4) return Error.NotEnoughArguments;
|
||||||
|
|
||||||
const mode_id = try modeNameToId(allocator, args[1 + offset], out);
|
const mode_id = try modeNameToId(args[1 + offset], out);
|
||||||
const modifiers = try parseModifiers(allocator, args[2 + offset], out);
|
const modifiers = try parseModifiers(args[2 + offset], out);
|
||||||
const keysym = try parseKeysym(allocator, args[3 + offset], out);
|
const keysym = try parseKeysym(args[3 + offset], out);
|
||||||
|
|
||||||
const mode_mappings = &server.config.modes.items[mode_id].mappings;
|
const mode_mappings = &server.config.modes.items[mode_id].mappings;
|
||||||
const mapping_idx = mappingExists(mode_mappings, modifiers, keysym, optionals.release) orelse return;
|
const mapping_idx = mappingExists(mode_mappings, modifiers, keysym, optionals.release) orelse return;
|
||||||
@ -288,18 +277,13 @@ pub fn unmap(
|
|||||||
///
|
///
|
||||||
/// Example:
|
/// Example:
|
||||||
/// unmap-pointer normal Mod4 BTN_LEFT
|
/// unmap-pointer normal Mod4 BTN_LEFT
|
||||||
pub fn unmapPointer(
|
pub fn unmapPointer(_: *Seat, args: []const [:0]const u8, out: *?[]const u8) Error!void {
|
||||||
allocator: mem.Allocator,
|
|
||||||
_: *Seat,
|
|
||||||
args: []const [:0]const u8,
|
|
||||||
out: *?[]const u8,
|
|
||||||
) Error!void {
|
|
||||||
if (args.len < 4) return Error.NotEnoughArguments;
|
if (args.len < 4) return Error.NotEnoughArguments;
|
||||||
if (args.len > 4) return Error.TooManyArguments;
|
if (args.len > 4) return Error.TooManyArguments;
|
||||||
|
|
||||||
const mode_id = try modeNameToId(allocator, args[1], out);
|
const mode_id = try modeNameToId(args[1], out);
|
||||||
const modifiers = try parseModifiers(allocator, args[2], out);
|
const modifiers = try parseModifiers(args[2], out);
|
||||||
const event_code = try parseEventCode(allocator, args[3], out);
|
const event_code = try parseEventCode(args[3], out);
|
||||||
|
|
||||||
const mode_pointer_mappings = &server.config.modes.items[mode_id].pointer_mappings;
|
const mode_pointer_mappings = &server.config.modes.items[mode_id].pointer_mappings;
|
||||||
const mapping_idx = pointerMappingExists(mode_pointer_mappings, modifiers, event_code) orelse return;
|
const mapping_idx = pointerMappingExists(mode_pointer_mappings, modifiers, event_code) orelse return;
|
||||||
|
@ -27,7 +27,6 @@ const View = @import("../View.zig");
|
|||||||
const Box = @import("../Box.zig");
|
const Box = @import("../Box.zig");
|
||||||
|
|
||||||
pub fn move(
|
pub fn move(
|
||||||
_: std.mem.Allocator,
|
|
||||||
seat: *Seat,
|
seat: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
_: *?[]const u8,
|
_: *?[]const u8,
|
||||||
@ -51,7 +50,6 @@ pub fn move(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn snap(
|
pub fn snap(
|
||||||
_: std.mem.Allocator,
|
|
||||||
seat: *Seat,
|
seat: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
_: *?[]const u8,
|
_: *?[]const u8,
|
||||||
@ -78,7 +76,6 @@ pub fn snap(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn resize(
|
pub fn resize(
|
||||||
_: std.mem.Allocator,
|
|
||||||
seat: *Seat,
|
seat: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
_: *?[]const u8,
|
_: *?[]const u8,
|
||||||
|
@ -29,7 +29,6 @@ const Output = @import("../Output.zig");
|
|||||||
const Seat = @import("../Seat.zig");
|
const Seat = @import("../Seat.zig");
|
||||||
|
|
||||||
pub fn focusOutput(
|
pub fn focusOutput(
|
||||||
_: mem.Allocator,
|
|
||||||
seat: *Seat,
|
seat: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
_: *?[]const u8,
|
_: *?[]const u8,
|
||||||
@ -49,7 +48,6 @@ pub fn focusOutput(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn sendToOutput(
|
pub fn sendToOutput(
|
||||||
_: mem.Allocator,
|
|
||||||
seat: *Seat,
|
seat: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
_: *?[]const u8,
|
_: *?[]const u8,
|
||||||
|
@ -23,7 +23,6 @@ const Seat = @import("../Seat.zig");
|
|||||||
|
|
||||||
/// Set the repeat rate and delay for all keyboards.
|
/// Set the repeat rate and delay for all keyboards.
|
||||||
pub fn setRepeat(
|
pub fn setRepeat(
|
||||||
_: std.mem.Allocator,
|
|
||||||
seat: *Seat,
|
seat: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
_: *?[]const u8,
|
_: *?[]const u8,
|
||||||
|
@ -18,13 +18,13 @@ const std = @import("std");
|
|||||||
const os = std.os;
|
const os = std.os;
|
||||||
|
|
||||||
const c = @import("../c.zig");
|
const c = @import("../c.zig");
|
||||||
|
const util = @import("../util.zig");
|
||||||
|
|
||||||
const Error = @import("../command.zig").Error;
|
const Error = @import("../command.zig").Error;
|
||||||
const Seat = @import("../Seat.zig");
|
const Seat = @import("../Seat.zig");
|
||||||
|
|
||||||
/// Spawn a program.
|
/// Spawn a program.
|
||||||
pub fn spawn(
|
pub fn spawn(
|
||||||
allocator: std.mem.Allocator,
|
|
||||||
_: *Seat,
|
_: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
out: *?[]const u8,
|
out: *?[]const u8,
|
||||||
@ -35,7 +35,7 @@ pub fn spawn(
|
|||||||
const child_args = [_:null]?[*:0]const u8{ "/bin/sh", "-c", args[1], null };
|
const child_args = [_:null]?[*:0]const u8{ "/bin/sh", "-c", args[1], null };
|
||||||
|
|
||||||
const pid = os.fork() catch {
|
const pid = os.fork() catch {
|
||||||
out.* = try std.fmt.allocPrint(allocator, "fork/execve failed", .{});
|
out.* = try std.fmt.allocPrint(util.gpa, "fork/execve failed", .{});
|
||||||
return Error.Other;
|
return Error.Other;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ pub fn spawn(
|
|||||||
if (!os.W.IFEXITED(ret.status) or
|
if (!os.W.IFEXITED(ret.status) or
|
||||||
(os.W.IFEXITED(ret.status) and os.W.EXITSTATUS(ret.status) != 0))
|
(os.W.IFEXITED(ret.status) and os.W.EXITSTATUS(ret.status) != 0))
|
||||||
{
|
{
|
||||||
out.* = try std.fmt.allocPrint(allocator, "fork/execve failed", .{});
|
out.* = try std.fmt.allocPrint(util.gpa, "fork/execve failed", .{});
|
||||||
return Error.Other;
|
return Error.Other;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,6 @@ const ViewStack = @import("../view_stack.zig").ViewStack;
|
|||||||
|
|
||||||
/// Swap the currently focused view with either the view higher or lower in the visible stack
|
/// Swap the currently focused view with either the view higher or lower in the visible stack
|
||||||
pub fn swap(
|
pub fn swap(
|
||||||
_: std.mem.Allocator,
|
|
||||||
seat: *Seat,
|
seat: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
_: *?[]const u8,
|
_: *?[]const u8,
|
||||||
|
@ -18,18 +18,18 @@ const std = @import("std");
|
|||||||
const mem = std.mem;
|
const mem = std.mem;
|
||||||
|
|
||||||
const server = &@import("../main.zig").server;
|
const server = &@import("../main.zig").server;
|
||||||
|
const util = @import("../util.zig");
|
||||||
|
|
||||||
const Error = @import("../command.zig").Error;
|
const Error = @import("../command.zig").Error;
|
||||||
const Seat = @import("../Seat.zig");
|
const Seat = @import("../Seat.zig");
|
||||||
|
|
||||||
/// Switch focus to the passed tags.
|
/// Switch focus to the passed tags.
|
||||||
pub fn setFocusedTags(
|
pub fn setFocusedTags(
|
||||||
allocator: mem.Allocator,
|
|
||||||
seat: *Seat,
|
seat: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
out: *?[]const u8,
|
out: *?[]const u8,
|
||||||
) Error!void {
|
) Error!void {
|
||||||
const tags = try parseTags(allocator, args, out);
|
const tags = try parseTags(args, out);
|
||||||
if (seat.focused_output.pending.tags != tags) {
|
if (seat.focused_output.pending.tags != tags) {
|
||||||
seat.focused_output.previous_tags = seat.focused_output.pending.tags;
|
seat.focused_output.previous_tags = seat.focused_output.pending.tags;
|
||||||
seat.focused_output.pending.tags = tags;
|
seat.focused_output.pending.tags = tags;
|
||||||
@ -41,23 +41,21 @@ pub fn setFocusedTags(
|
|||||||
|
|
||||||
/// Set the spawn tagmask
|
/// Set the spawn tagmask
|
||||||
pub fn spawnTagmask(
|
pub fn spawnTagmask(
|
||||||
allocator: mem.Allocator,
|
|
||||||
seat: *Seat,
|
seat: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
out: *?[]const u8,
|
out: *?[]const u8,
|
||||||
) Error!void {
|
) Error!void {
|
||||||
const tags = try parseTags(allocator, args, out);
|
const tags = try parseTags(args, out);
|
||||||
seat.focused_output.spawn_tagmask = tags;
|
seat.focused_output.spawn_tagmask = tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the tags of the focused view.
|
/// Set the tags of the focused view.
|
||||||
pub fn setViewTags(
|
pub fn setViewTags(
|
||||||
allocator: mem.Allocator,
|
|
||||||
seat: *Seat,
|
seat: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
out: *?[]const u8,
|
out: *?[]const u8,
|
||||||
) Error!void {
|
) Error!void {
|
||||||
const tags = try parseTags(allocator, args, out);
|
const tags = try parseTags(args, out);
|
||||||
if (seat.focused == .view) {
|
if (seat.focused == .view) {
|
||||||
const view = seat.focused.view;
|
const view = seat.focused.view;
|
||||||
view.pending.tags = tags;
|
view.pending.tags = tags;
|
||||||
@ -68,12 +66,11 @@ pub fn setViewTags(
|
|||||||
|
|
||||||
/// Toggle focus of the passsed tags.
|
/// Toggle focus of the passsed tags.
|
||||||
pub fn toggleFocusedTags(
|
pub fn toggleFocusedTags(
|
||||||
allocator: mem.Allocator,
|
|
||||||
seat: *Seat,
|
seat: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
out: *?[]const u8,
|
out: *?[]const u8,
|
||||||
) Error!void {
|
) Error!void {
|
||||||
const tags = try parseTags(allocator, args, out);
|
const tags = try parseTags(args, out);
|
||||||
const output = seat.focused_output;
|
const output = seat.focused_output;
|
||||||
const new_focused_tags = output.pending.tags ^ tags;
|
const new_focused_tags = output.pending.tags ^ tags;
|
||||||
if (new_focused_tags != 0) {
|
if (new_focused_tags != 0) {
|
||||||
@ -87,12 +84,11 @@ pub fn toggleFocusedTags(
|
|||||||
|
|
||||||
/// Toggle the passed tags of the focused view
|
/// Toggle the passed tags of the focused view
|
||||||
pub fn toggleViewTags(
|
pub fn toggleViewTags(
|
||||||
allocator: mem.Allocator,
|
|
||||||
seat: *Seat,
|
seat: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
out: *?[]const u8,
|
out: *?[]const u8,
|
||||||
) Error!void {
|
) Error!void {
|
||||||
const tags = try parseTags(allocator, args, out);
|
const tags = try parseTags(args, out);
|
||||||
if (seat.focused == .view) {
|
if (seat.focused == .view) {
|
||||||
const new_tags = seat.focused.view.pending.tags ^ tags;
|
const new_tags = seat.focused.view.pending.tags ^ tags;
|
||||||
if (new_tags != 0) {
|
if (new_tags != 0) {
|
||||||
@ -106,7 +102,6 @@ pub fn toggleViewTags(
|
|||||||
|
|
||||||
/// Switch focus to tags that were selected previously
|
/// Switch focus to tags that were selected previously
|
||||||
pub fn focusPreviousTags(
|
pub fn focusPreviousTags(
|
||||||
_: mem.Allocator,
|
|
||||||
seat: *Seat,
|
seat: *Seat,
|
||||||
args: []const []const u8,
|
args: []const []const u8,
|
||||||
_: *?[]const u8,
|
_: *?[]const u8,
|
||||||
@ -124,7 +119,6 @@ pub fn focusPreviousTags(
|
|||||||
|
|
||||||
/// Set the tags of the focused view to the tags that were selected previously
|
/// Set the tags of the focused view to the tags that were selected previously
|
||||||
pub fn sendToPreviousTags(
|
pub fn sendToPreviousTags(
|
||||||
_: mem.Allocator,
|
|
||||||
seat: *Seat,
|
seat: *Seat,
|
||||||
args: []const []const u8,
|
args: []const []const u8,
|
||||||
_: *?[]const u8,
|
_: *?[]const u8,
|
||||||
@ -140,7 +134,6 @@ pub fn sendToPreviousTags(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn parseTags(
|
fn parseTags(
|
||||||
allocator: mem.Allocator,
|
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
out: *?[]const u8,
|
out: *?[]const u8,
|
||||||
) Error!u32 {
|
) Error!u32 {
|
||||||
@ -150,7 +143,7 @@ fn parseTags(
|
|||||||
const tags = try std.fmt.parseInt(u32, args[1], 10);
|
const tags = try std.fmt.parseInt(u32, args[1], 10);
|
||||||
|
|
||||||
if (tags == 0) {
|
if (tags == 0) {
|
||||||
out.* = try std.fmt.allocPrint(allocator, "tags may not be 0", .{});
|
out.* = try std.fmt.allocPrint(util.gpa, "tags may not be 0", .{});
|
||||||
return Error.Other;
|
return Error.Other;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@ const Seat = @import("../Seat.zig");
|
|||||||
/// Make the focused view float or stop floating, depending on its current
|
/// Make the focused view float or stop floating, depending on its current
|
||||||
/// state.
|
/// state.
|
||||||
pub fn toggleFloat(
|
pub fn toggleFloat(
|
||||||
_: std.mem.Allocator,
|
|
||||||
seat: *Seat,
|
seat: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
_: *?[]const u8,
|
_: *?[]const u8,
|
||||||
|
@ -24,7 +24,6 @@ const Seat = @import("../Seat.zig");
|
|||||||
|
|
||||||
/// Toggle fullscreen state of the currently focused view
|
/// Toggle fullscreen state of the currently focused view
|
||||||
pub fn toggleFullscreen(
|
pub fn toggleFullscreen(
|
||||||
_: std.mem.Allocator,
|
|
||||||
seat: *Seat,
|
seat: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
_: *?[]const u8,
|
_: *?[]const u8,
|
||||||
|
@ -20,7 +20,6 @@ const Error = @import("../command.zig").Error;
|
|||||||
const Seat = @import("../Seat.zig");
|
const Seat = @import("../Seat.zig");
|
||||||
|
|
||||||
pub fn xcursorTheme(
|
pub fn xcursorTheme(
|
||||||
_: std.mem.Allocator,
|
|
||||||
seat: *Seat,
|
seat: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
_: *?[]const u8,
|
_: *?[]const u8,
|
||||||
|
@ -26,7 +26,6 @@ const ViewStack = @import("../view_stack.zig").ViewStack;
|
|||||||
/// Bump the focused view to the top of the stack. If the view on the top of
|
/// 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.
|
/// the stack is focused, bump the second view to the top.
|
||||||
pub fn zoom(
|
pub fn zoom(
|
||||||
_: std.mem.Allocator,
|
|
||||||
seat: *Seat,
|
seat: *Seat,
|
||||||
args: []const [:0]const u8,
|
args: []const [:0]const u8,
|
||||||
_: *?[]const u8,
|
_: *?[]const u8,
|
||||||
|
Loading…
Reference in New Issue
Block a user