2020-05-19 13:59:50 -07:00
|
|
|
// This file is part of river, a dynamic tiling wayland compositor.
|
|
|
|
//
|
2020-11-11 11:30:21 -08:00
|
|
|
// Copyright 2020 The River Developers
|
2020-05-19 13:59:50 -07:00
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
2022-01-31 10:33:22 -08:00
|
|
|
// the Free Software Foundation, version 3.
|
2020-05-19 13:59:50 -07:00
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// 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");
|
2022-02-07 13:07:27 -08:00
|
|
|
const assert = std.debug.assert;
|
2020-05-19 13:59:50 -07:00
|
|
|
|
|
|
|
const Seat = @import("Seat.zig");
|
|
|
|
|
2020-05-26 13:55:07 -07:00
|
|
|
pub const Direction = enum {
|
2020-07-15 04:02:58 -07:00
|
|
|
next,
|
|
|
|
previous,
|
2020-05-19 13:59:50 -07:00
|
|
|
};
|
|
|
|
|
2020-10-06 18:00:57 -07:00
|
|
|
pub const PhysicalDirection = enum {
|
|
|
|
up,
|
|
|
|
down,
|
|
|
|
left,
|
|
|
|
right,
|
|
|
|
};
|
|
|
|
|
|
|
|
pub const Orientation = enum {
|
|
|
|
horizontal,
|
|
|
|
vertical,
|
|
|
|
};
|
|
|
|
|
2020-05-19 13:59:50 -07:00
|
|
|
// zig fmt: off
|
2021-08-11 17:07:41 -07:00
|
|
|
const command_impls = std.ComptimeStringMap(
|
2022-11-04 16:29:51 -07:00
|
|
|
*const fn (*Seat, []const [:0]const u8, *?[]const u8) Error!void,
|
2021-08-11 17:07:41 -07:00
|
|
|
.{
|
2024-01-03 06:33:13 -08:00
|
|
|
.{ "attach-mode", @import("command/attach_mode.zig").defaultAttachMode },
|
2021-08-11 17:07:41 -07:00
|
|
|
.{ "background-color", @import("command/config.zig").backgroundColor },
|
|
|
|
.{ "border-color-focused", @import("command/config.zig").borderColorFocused },
|
|
|
|
.{ "border-color-unfocused", @import("command/config.zig").borderColorUnfocused },
|
|
|
|
.{ "border-color-urgent", @import("command/config.zig").borderColorUrgent },
|
|
|
|
.{ "border-width", @import("command/config.zig").borderWidth },
|
|
|
|
.{ "close", @import("command/close.zig").close },
|
|
|
|
.{ "declare-mode", @import("command/declare_mode.zig").declareMode },
|
2024-01-03 06:33:13 -08:00
|
|
|
.{ "default-attach-mode", @import("command/attach_mode.zig").defaultAttachMode },
|
2021-08-11 17:07:41 -07:00
|
|
|
.{ "default-layout", @import("command/layout.zig").defaultLayout },
|
|
|
|
.{ "enter-mode", @import("command/enter_mode.zig").enterMode },
|
|
|
|
.{ "exit", @import("command/exit.zig").exit },
|
|
|
|
.{ "focus-follows-cursor", @import("command/focus_follows_cursor.zig").focusFollowsCursor },
|
|
|
|
.{ "focus-output", @import("command/output.zig").focusOutput },
|
|
|
|
.{ "focus-previous-tags", @import("command/tags.zig").focusPreviousTags },
|
2023-07-07 21:30:27 -07:00
|
|
|
.{ "focus-view", @import("command/view_operations.zig").focusView },
|
2022-02-27 15:39:10 -08:00
|
|
|
.{ "hide-cursor", @import("command/cursor.zig").cursor },
|
2021-08-11 17:07:41 -07:00
|
|
|
.{ "input", @import("command/input.zig").input },
|
2023-03-12 07:40:42 -07:00
|
|
|
.{ "keyboard-group-add", @import("command/keyboard_group.zig").keyboardGroupAdd },
|
|
|
|
.{ "keyboard-group-create", @import("command/keyboard_group.zig").keyboardGroupCreate },
|
|
|
|
.{ "keyboard-group-destroy", @import("command/keyboard_group.zig").keyboardGroupDestroy },
|
|
|
|
.{ "keyboard-group-remove", @import("command/keyboard_group.zig").keyboardGroupRemove },
|
|
|
|
.{ "keyboard-layout", @import("command/keyboard.zig").keyboardLayout },
|
2023-08-12 12:30:55 -07:00
|
|
|
.{ "keyboard-layout-file", @import("command/keyboard.zig").keyboardLayoutFile },
|
2021-08-11 17:07:41 -07:00
|
|
|
.{ "list-input-configs", @import("command/input.zig").listInputConfigs},
|
|
|
|
.{ "list-inputs", @import("command/input.zig").listInputs },
|
2023-03-12 07:40:42 -07:00
|
|
|
.{ "list-rules", @import("command/rule.zig").listRules},
|
2021-08-11 17:07:41 -07:00
|
|
|
.{ "map", @import("command/map.zig").map },
|
|
|
|
.{ "map-pointer", @import("command/map.zig").mapPointer },
|
2022-02-07 05:51:23 -08:00
|
|
|
.{ "map-switch", @import("command/map.zig").mapSwitch },
|
2021-08-11 17:07:41 -07:00
|
|
|
.{ "move", @import("command/move.zig").move },
|
2024-01-03 06:33:13 -08:00
|
|
|
.{ "output-attach-mode", @import("command/attach_mode.zig").outputAttachMode },
|
2021-08-11 17:07:41 -07:00
|
|
|
.{ "output-layout", @import("command/layout.zig").outputLayout },
|
|
|
|
.{ "resize", @import("command/move.zig").resize },
|
2023-03-12 07:40:42 -07:00
|
|
|
.{ "rule-add", @import("command/rule.zig").ruleAdd },
|
|
|
|
.{ "rule-del", @import("command/rule.zig").ruleDel },
|
2021-08-11 17:07:41 -07:00
|
|
|
.{ "send-layout-cmd", @import("command/layout.zig").sendLayoutCmd },
|
|
|
|
.{ "send-to-output", @import("command/output.zig").sendToOutput },
|
|
|
|
.{ "send-to-previous-tags", @import("command/tags.zig").sendToPreviousTags },
|
|
|
|
.{ "set-cursor-warp", @import("command/config.zig").setCursorWarp },
|
|
|
|
.{ "set-focused-tags", @import("command/tags.zig").setFocusedTags },
|
|
|
|
.{ "set-repeat", @import("command/set_repeat.zig").setRepeat },
|
|
|
|
.{ "set-view-tags", @import("command/tags.zig").setViewTags },
|
|
|
|
.{ "snap", @import("command/move.zig").snap },
|
|
|
|
.{ "spawn", @import("command/spawn.zig").spawn },
|
|
|
|
.{ "spawn-tagmask", @import("command/tags.zig").spawnTagmask },
|
2023-07-07 21:30:27 -07:00
|
|
|
.{ "swap", @import("command/view_operations.zig").swap},
|
2021-08-11 17:07:41 -07:00
|
|
|
.{ "toggle-float", @import("command/toggle_float.zig").toggleFloat },
|
|
|
|
.{ "toggle-focused-tags", @import("command/tags.zig").toggleFocusedTags },
|
|
|
|
.{ "toggle-fullscreen", @import("command/toggle_fullscreen.zig").toggleFullscreen },
|
|
|
|
.{ "toggle-view-tags", @import("command/tags.zig").toggleViewTags },
|
|
|
|
.{ "unmap", @import("command/map.zig").unmap },
|
|
|
|
.{ "unmap-pointer", @import("command/map.zig").unmapPointer },
|
2022-02-07 05:51:23 -08:00
|
|
|
.{ "unmap-switch", @import("command/map.zig").unmapSwitch },
|
2021-08-11 17:07:41 -07:00
|
|
|
.{ "xcursor-theme", @import("command/xcursor_theme.zig").xcursorTheme },
|
|
|
|
.{ "zoom", @import("command/zoom.zig").zoom },
|
|
|
|
},
|
|
|
|
);
|
2020-05-19 13:59:50 -07:00
|
|
|
// zig fmt: on
|
|
|
|
|
2020-05-24 06:18:57 -07:00
|
|
|
pub const Error = error{
|
|
|
|
NoCommand,
|
|
|
|
UnknownCommand,
|
|
|
|
NotEnoughArguments,
|
|
|
|
TooManyArguments,
|
|
|
|
Overflow,
|
2021-06-03 20:51:15 -07:00
|
|
|
InvalidButton,
|
2020-05-24 06:18:57 -07:00
|
|
|
InvalidCharacter,
|
|
|
|
InvalidDirection,
|
2023-03-12 07:40:42 -07:00
|
|
|
InvalidGlob,
|
2020-10-06 18:00:57 -07:00
|
|
|
InvalidPhysicalDirection,
|
2022-02-06 06:41:40 -08:00
|
|
|
InvalidOutputIndicator,
|
2020-10-06 18:00:57 -07:00
|
|
|
InvalidOrientation,
|
2020-06-13 04:09:43 -07:00
|
|
|
InvalidRgba,
|
2020-10-03 13:09:15 -07:00
|
|
|
InvalidValue,
|
2023-08-12 12:30:55 -07:00
|
|
|
CannotReadFile,
|
|
|
|
CannotParseFile,
|
2020-06-09 08:28:48 -07:00
|
|
|
UnknownOption,
|
2021-08-15 05:49:11 -07:00
|
|
|
ConflictingOptions,
|
2020-05-24 06:18:57 -07:00
|
|
|
OutOfMemory,
|
2020-06-26 08:57:03 -07:00
|
|
|
Other,
|
2020-05-24 06:18:57 -07:00
|
|
|
};
|
|
|
|
|
2020-05-26 13:55:07 -07:00
|
|
|
/// Run a command for the given Seat. The `args` parameter is similar to the
|
|
|
|
/// classic argv in that the command to be run is passed as the first argument.
|
2020-06-26 08:57:03 -07:00
|
|
|
/// The optional slice passed as the out parameter must initially be set to
|
|
|
|
/// null. If the command produces output or Error.Other is returned, the slice
|
|
|
|
/// will be set to the output of the command or a failure message, respectively.
|
|
|
|
/// The caller is then responsible for freeing that slice, which will be
|
|
|
|
/// allocated using the provided allocator.
|
2020-05-26 13:55:07 -07:00
|
|
|
pub fn run(
|
|
|
|
seat: *Seat,
|
2021-07-14 15:13:16 -07:00
|
|
|
args: []const [:0]const u8,
|
2020-06-26 08:57:03 -07:00
|
|
|
out: *?[]const u8,
|
2020-05-26 13:55:07 -07:00
|
|
|
) Error!void {
|
2022-02-07 13:07:27 -08:00
|
|
|
assert(out.* == null);
|
2020-05-26 13:55:07 -07:00
|
|
|
if (args.len == 0) return Error.NoCommand;
|
2021-08-11 17:07:41 -07:00
|
|
|
const impl_fn = command_impls.get(args[0]) orelse return Error.UnknownCommand;
|
2022-02-08 03:27:32 -08:00
|
|
|
try impl_fn(seat, args, out);
|
2020-05-19 13:59:50 -07:00
|
|
|
}
|
2020-06-26 09:43:20 -07:00
|
|
|
|
2023-03-12 07:40:42 -07:00
|
|
|
/// Return a short error message for the given error. Passing Error.Other is invalid.
|
2020-06-26 09:43:20 -07:00
|
|
|
pub fn errToMsg(err: Error) [:0]const u8 {
|
|
|
|
return switch (err) {
|
|
|
|
Error.NoCommand => "no command given",
|
|
|
|
Error.UnknownCommand => "unknown command",
|
|
|
|
Error.UnknownOption => "unknown option",
|
2021-08-15 05:49:11 -07:00
|
|
|
Error.ConflictingOptions => "options conflict",
|
2020-06-26 09:43:20 -07:00
|
|
|
Error.NotEnoughArguments => "not enough arguments",
|
|
|
|
Error.TooManyArguments => "too many arguments",
|
|
|
|
Error.Overflow => "value out of bounds",
|
2021-06-03 20:51:15 -07:00
|
|
|
Error.InvalidButton => "invalid button",
|
2020-06-26 09:43:20 -07:00
|
|
|
Error.InvalidCharacter => "invalid character in argument",
|
|
|
|
Error.InvalidDirection => "invalid direction. Must be 'next' or 'previous'",
|
2023-03-12 07:40:42 -07:00
|
|
|
Error.InvalidGlob => "invalid glob. '*' is only allowed as the first and/or last character",
|
2020-10-06 18:00:57 -07:00
|
|
|
Error.InvalidPhysicalDirection => "invalid direction. Must be 'up', 'down', 'left' or 'right'",
|
2022-02-06 06:41:40 -08:00
|
|
|
Error.InvalidOutputIndicator => "invalid indicator for an output. Must be 'next', 'previous', 'up', 'down', 'left', 'right' or a valid output name",
|
2020-10-06 18:00:57 -07:00
|
|
|
Error.InvalidOrientation => "invalid orientation. Must be 'horizontal', or 'vertical'",
|
2021-07-26 11:36:46 -07:00
|
|
|
Error.InvalidRgba => "invalid color format, must be hexadecimal 0xRRGGBB or 0xRRGGBBAA",
|
2020-10-03 13:09:15 -07:00
|
|
|
Error.InvalidValue => "invalid value",
|
2023-08-12 12:30:55 -07:00
|
|
|
Error.CannotReadFile => "cannot read file",
|
|
|
|
Error.CannotParseFile => "cannot parse file",
|
2020-06-26 09:43:20 -07:00
|
|
|
Error.OutOfMemory => "out of memory",
|
|
|
|
Error.Other => unreachable,
|
|
|
|
};
|
|
|
|
}
|