From 36d9037f2c419756b00d1fe2dbeefca278bc2799 Mon Sep 17 00:00:00 2001 From: Tarmack Date: Thu, 11 Oct 2018 21:51:11 +0200 Subject: fix_edge_gaps: Allow negative values for outer gaps. While allowing negative values for the outer gaps it is still prevented that negative values move windows out of the container. This replaces the non-i3 option for edge_gaps. --- sway/commands/gaps.c | 50 +++++++++++++------------------------------------- 1 file changed, 13 insertions(+), 37 deletions(-) (limited to 'sway/commands/gaps.c') diff --git a/sway/commands/gaps.c b/sway/commands/gaps.c index 2e0876a9..042b415f 100644 --- a/sway/commands/gaps.c +++ b/sway/commands/gaps.c @@ -20,31 +20,6 @@ struct gaps_data { int amount; }; -// gaps edge_gaps on|off|toggle -static struct cmd_results *gaps_edge_gaps(int argc, char **argv) { - struct cmd_results *error; - if ((error = checkarg(argc, "gaps", EXPECTED_AT_LEAST, 2))) { - return error; - } - - if (strcmp(argv[1], "on") == 0) { - config->edge_gaps = true; - } else if (strcmp(argv[1], "off") == 0) { - config->edge_gaps = false; - } else if (strcmp(argv[1], "toggle") == 0) { - if (!config->active) { - return cmd_results_new(CMD_INVALID, "gaps", - "Cannot toggle gaps while not running."); - } - config->edge_gaps = !config->edge_gaps; - } else { - return cmd_results_new(CMD_INVALID, "gaps", - "gaps edge_gaps on|off|toggle"); - } - arrange_root(); - return cmd_results_new(CMD_SUCCESS, NULL, NULL); -} - // gaps inner|outer static struct cmd_results *gaps_set_defaults(int argc, char **argv) { struct cmd_results *error = checkarg(argc, "gaps", EXPECTED_EQUAL_TO, 2); @@ -68,15 +43,17 @@ static struct cmd_results *gaps_set_defaults(int argc, char **argv) { return cmd_results_new(CMD_INVALID, "gaps", "Expected 'gaps inner|outer '"); } - if (amount < 0) { - amount = 0; - } - if (inner) { - config->gaps_inner = amount; + config->gaps_inner = (amount >= 0) ? amount : 0; } else { config->gaps_outer = amount; } + + // Prevent negative outer gaps from moving windows out of the workspace. + if (config->gaps_outer < -config->gaps_inner) { + config->gaps_outer = -config->gaps_inner; + } + return cmd_results_new(CMD_SUCCESS, NULL, NULL); } @@ -95,8 +72,12 @@ static void configure_gaps(struct sway_workspace *ws, void *_data) { *prop -= data->amount; break; } - if (*prop < 0) { - *prop = 0; + // Prevent invalid gaps configurations. + if (ws->gaps_inner < 0) { + ws->gaps_inner = 0; + } + if (ws->gaps_outer < -ws->gaps_inner) { + ws->gaps_outer = -ws->gaps_inner; } arrange_workspace(ws); } @@ -156,7 +137,6 @@ static struct cmd_results *gaps_set_runtime(int argc, char **argv) { return cmd_results_new(CMD_SUCCESS, NULL, NULL); } -// gaps edge_gaps on|off|toggle // gaps inner|outer - sets defaults for workspaces // gaps inner|outer current|all set|plus|minus - runtime only struct cmd_results *cmd_gaps(int argc, char **argv) { @@ -165,10 +145,6 @@ struct cmd_results *cmd_gaps(int argc, char **argv) { return error; } - if (strcmp(argv[0], "edge_gaps") == 0) { - return gaps_edge_gaps(argc, argv); - } - if (argc == 2) { return gaps_set_defaults(argc, argv); } -- cgit v1.2.3-54-g00ecf