sway

i3-compatible Wayland compositor
git clone https://git.awy.one/sway
Log | Files | Refs | README | LICENSE

commit 51ad2676d0bed4b2f0a3de5d118ce80d3d4e2eb2
parent 2507a5e44719134b4bb417913217850ce694dd5f
Author: Drew DeVault <sir@cmpwn.com>
Date:   Thu, 25 Oct 2018 17:10:36 +0200

Merge pull request #2975 from RyanDwyer/deny-commands-when-no-outputs

Deny several commands when there's no outputs connected
Diffstat:
Msway/commands/floating.c | 4++++
Msway/commands/focus.c | 4++++
Msway/commands/fullscreen.c | 4++++
Msway/commands/gaps.c | 4++++
Msway/commands/kill.c | 4++++
Msway/commands/layout.c | 4++++
Msway/commands/move.c | 4++++
Msway/commands/rename.c | 4++++
Msway/commands/resize.c | 4++++
Msway/commands/scratchpad.c | 4++++
Msway/commands/split.c | 4++++
Msway/commands/swap.c | 4++++
Msway/commands/workspace.c | 4++++
13 files changed, 52 insertions(+), 0 deletions(-)

diff --git a/sway/commands/floating.c b/sway/commands/floating.c @@ -15,6 +15,10 @@ struct cmd_results *cmd_floating(int argc, char **argv) { if ((error = checkarg(argc, "floating", EXPECTED_EQUAL_TO, 1))) { return error; } + if (!root->outputs->length) { + return cmd_results_new(CMD_INVALID, "floating", + "Can't run this command while there's no outputs connected."); + } struct sway_container *container = config->handler_context.container; struct sway_workspace *workspace = config->handler_context.workspace; if (!container && workspace->tiling->length == 0) { diff --git a/sway/commands/focus.c b/sway/commands/focus.c @@ -224,6 +224,10 @@ struct cmd_results *cmd_focus(int argc, char **argv) { if (config->reading || !config->active) { return cmd_results_new(CMD_DEFER, NULL, NULL); } + if (!root->outputs->length) { + return cmd_results_new(CMD_INVALID, "focus", + "Can't run this command while there's no outputs connected."); + } struct sway_node *node = config->handler_context.node; struct sway_container *container = config->handler_context.container; struct sway_workspace *workspace = config->handler_context.workspace; diff --git a/sway/commands/fullscreen.c b/sway/commands/fullscreen.c @@ -12,6 +12,10 @@ struct cmd_results *cmd_fullscreen(int argc, char **argv) { if ((error = checkarg(argc, "fullscreen", EXPECTED_AT_MOST, 1))) { return error; } + if (!root->outputs->length) { + return cmd_results_new(CMD_INVALID, "fullscreen", + "Can't run this command while there's no outputs connected."); + } struct sway_node *node = config->handler_context.node; struct sway_container *container = config->handler_context.container; struct sway_workspace *workspace = config->handler_context.workspace; diff --git a/sway/commands/gaps.c b/sway/commands/gaps.c @@ -88,6 +88,10 @@ static struct cmd_results *gaps_set_runtime(int argc, char **argv) { if (error) { return error; } + if (!root->outputs->length) { + return cmd_results_new(CMD_INVALID, "gaps", + "Can't run this command while there's no outputs connected."); + } struct gaps_data data; diff --git a/sway/commands/kill.c b/sway/commands/kill.c @@ -14,6 +14,10 @@ static void close_container_iterator(struct sway_container *con, void *data) { } struct cmd_results *cmd_kill(int argc, char **argv) { + if (!root->outputs->length) { + return cmd_results_new(CMD_INVALID, "kill", + "Can't run this command while there's no outputs connected."); + } struct sway_container *con = config->handler_context.container; struct sway_workspace *ws = config->handler_context.workspace; diff --git a/sway/commands/layout.c b/sway/commands/layout.c @@ -99,6 +99,10 @@ struct cmd_results *cmd_layout(int argc, char **argv) { if ((error = checkarg(argc, "layout", EXPECTED_AT_LEAST, 1))) { return error; } + if (!root->outputs->length) { + return cmd_results_new(CMD_INVALID, "layout", + "Can't run this command while there's no outputs connected."); + } struct sway_container *container = config->handler_context.container; struct sway_workspace *workspace = config->handler_context.workspace; diff --git a/sway/commands/move.c b/sway/commands/move.c @@ -844,6 +844,10 @@ struct cmd_results *cmd_move(int argc, char **argv) { if ((error = checkarg(argc, "move", EXPECTED_AT_LEAST, 1))) { return error; } + if (!root->outputs->length) { + return cmd_results_new(CMD_INVALID, "move", + "Can't run this command while there's no outputs connected."); + } if (strcasecmp(argv[0], "left") == 0) { return cmd_move_in_direction(MOVE_LEFT, argc, argv); diff --git a/sway/commands/rename.c b/sway/commands/rename.c @@ -20,6 +20,10 @@ struct cmd_results *cmd_rename(int argc, char **argv) { if ((error = checkarg(argc, "rename", EXPECTED_AT_LEAST, 3))) { return error; } + if (!root->outputs->length) { + return cmd_results_new(CMD_INVALID, "rename", + "Can't run this command while there's no outputs connected."); + } if (strcasecmp(argv[0], "workspace") != 0) { return cmd_results_new(CMD_INVALID, "rename", expected_syntax); } diff --git a/sway/commands/resize.c b/sway/commands/resize.c @@ -671,6 +671,10 @@ static struct cmd_results *cmd_resize_adjust(int argc, char **argv, } struct cmd_results *cmd_resize(int argc, char **argv) { + if (!root->outputs->length) { + return cmd_results_new(CMD_INVALID, "resize", + "Can't run this command while there's no outputs connected."); + } struct sway_container *current = config->handler_context.container; if (!current) { return cmd_results_new(CMD_INVALID, "resize", "Cannot resize nothing"); diff --git a/sway/commands/scratchpad.c b/sway/commands/scratchpad.c @@ -87,6 +87,10 @@ struct cmd_results *cmd_scratchpad(int argc, char **argv) { return cmd_results_new(CMD_INVALID, "scratchpad", "Expected 'scratchpad show'"); } + if (!root->outputs->length) { + return cmd_results_new(CMD_INVALID, "scratchpad", + "Can't run this command while there's no outputs connected."); + } if (!root->scratchpad->length) { return cmd_results_new(CMD_INVALID, "scratchpad", "Scratchpad is empty"); diff --git a/sway/commands/split.c b/sway/commands/split.c @@ -28,6 +28,10 @@ struct cmd_results *cmd_split(int argc, char **argv) { if ((error = checkarg(argc, "split", EXPECTED_EQUAL_TO, 1))) { return error; } + if (!root->outputs->length) { + return cmd_results_new(CMD_INVALID, "split", + "Can't run this command while there's no outputs connected."); + } if (strcasecmp(argv[0], "v") == 0 || strcasecmp(argv[0], "vertical") == 0) { return do_split(L_VERT); } else if (strcasecmp(argv[0], "h") == 0 || diff --git a/sway/commands/swap.c b/sway/commands/swap.c @@ -171,6 +171,10 @@ struct cmd_results *cmd_swap(int argc, char **argv) { if ((error = checkarg(argc, "swap", EXPECTED_AT_LEAST, 4))) { return error; } + if (!root->outputs->length) { + return cmd_results_new(CMD_INVALID, "swap", + "Can't run this command while there's no outputs connected."); + } if (strcasecmp(argv[0], "container") || strcasecmp(argv[1], "with")) { return cmd_results_new(CMD_INVALID, "swap", EXPECTED_SYNTAX); diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c @@ -38,6 +38,10 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { if ((error = checkarg(argc, "workspace", EXPECTED_AT_LEAST, 1))) { return error; } + if (!root->outputs->length) { + return cmd_results_new(CMD_INVALID, "workspace", + "Can't run this command while there's no outputs connected."); + } int output_location = -1; int gaps_location = -1;