From c9458b9fb1034b1fd9a946aa85d4a7c1f07f2af3 Mon Sep 17 00:00:00 2001 From: bR3iN Date: Wed, 21 Jul 2021 14:08:29 +0200 Subject: Add `gaps toggle ` command Add a subcommand for `gaps` that allows to toggle gaps at runtime. This functionality is part of i3-gaps since [1] but is missing in sway. [1] https://github.com/Airblader/i3/pull/264 --- sway/commands/gaps.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'sway/commands/gaps.c') diff --git a/sway/commands/gaps.c b/sway/commands/gaps.c index 021df843..1deeb56e 100644 --- a/sway/commands/gaps.c +++ b/sway/commands/gaps.c @@ -11,7 +11,8 @@ enum gaps_op { GAPS_OP_SET, GAPS_OP_ADD, - GAPS_OP_SUBTRACT + GAPS_OP_SUBTRACT, + GAPS_OP_TOGGLE }; struct gaps_data { @@ -102,6 +103,9 @@ static void apply_gaps_op(int *prop, enum gaps_op op, int amount) { case GAPS_OP_SUBTRACT: *prop -= amount; break; + case GAPS_OP_TOGGLE: + *prop = *prop ? 0 : amount; + break; } } @@ -133,9 +137,9 @@ static void configure_gaps(struct sway_workspace *ws, void *_data) { } // gaps inner|outer|horizontal|vertical|top|right|bottom|left current|all -// set|plus|minus +// set|plus|minus|toggle static const char expected_runtime[] = "'gaps inner|outer|horizontal|vertical|" - "top|right|bottom|left current|all set|plus|minus '"; + "top|right|bottom|left current|all set|plus|minus|toggle '"; static struct cmd_results *gaps_set_runtime(int argc, char **argv) { struct cmd_results *error = checkarg(argc, "gaps", EXPECTED_EQUAL_TO, 4); if (error) { @@ -180,6 +184,8 @@ static struct cmd_results *gaps_set_runtime(int argc, char **argv) { data.operation = GAPS_OP_ADD; } else if (strcasecmp(argv[2], "minus") == 0) { data.operation = GAPS_OP_SUBTRACT; + } else if (strcasecmp(argv[2], "toggle") == 0) { + data.operation = GAPS_OP_TOGGLE; } else { return cmd_results_new(CMD_INVALID, "Expected %s", expected_runtime); } @@ -200,7 +206,7 @@ static struct cmd_results *gaps_set_runtime(int argc, char **argv) { } // gaps inner|outer|| - sets defaults for workspaces -// gaps inner|outer|| current|all set|plus|minus - runtime only +// gaps inner|outer|| current|all set|plus|minus|toggle - runtime only // = horizontal|vertical // = top|right|bottom|left struct cmd_results *cmd_gaps(int argc, char **argv) { -- cgit v1.2.3