From 36d9037f2c419756b00d1fe2dbeefca278bc2799 Mon Sep 17 00:00:00 2001 From: Tarmack Date: Thu, 11 Oct 2018 21:51:11 +0200 Subject: [PATCH] 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. --- include/sway/config.h | 1 - sway/commands/gaps.c | 50 ++++++++++----------------------------- sway/commands/workspace.c | 16 ++++++++++--- sway/config.c | 1 - sway/sway.5.scd | 8 ++----- sway/tree/workspace.c | 7 ++---- 6 files changed, 30 insertions(+), 53 deletions(-) diff --git a/include/sway/config.h b/include/sway/config.h index bc02c0fd1..ca17a645e 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -389,7 +389,6 @@ struct sway_config { bool show_marks; bool tiling_drag; - bool edge_gaps; bool smart_gaps; int gaps_inner; int gaps_outer; diff --git a/sway/commands/gaps.c b/sway/commands/gaps.c index 2e0876a9f..042b415f3 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); } diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c index 63f296415..61aa443d8 100644 --- a/sway/commands/workspace.c +++ b/sway/commands/workspace.c @@ -1,5 +1,6 @@ #define _XOPEN_SOURCE 500 #include +#include #include #include #include "sway/commands.h" @@ -20,8 +21,8 @@ static struct workspace_config *workspace_config_find_or_create(char *ws_name) { return NULL; } wsc->workspace = strdup(ws_name); - wsc->gaps_inner = -1; - wsc->gaps_outer = -1; + wsc->gaps_inner = INT_MIN; + wsc->gaps_outer = INT_MIN; list_add(config->workspace_configs, wsc); return wsc; } @@ -94,7 +95,16 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { return cmd_results_new(CMD_FAILURE, "workspace gaps", "Expected 'workspace gaps inner|outer '"); } - *prop = val >= 0 ? val : 0; + *prop = val; + + // Prevent invalid gaps configurations. + if (wsc->gaps_inner < 0) { + wsc->gaps_inner = 0; + } + if (wsc->gaps_outer < -wsc->gaps_inner) { + wsc->gaps_outer = -wsc->gaps_inner; + } + } else { if (config->reading || !config->active) { return cmd_results_new(CMD_DEFER, "workspace", NULL); diff --git a/sway/config.c b/sway/config.c index f239ba1d9..89b894647 100644 --- a/sway/config.c +++ b/sway/config.c @@ -234,7 +234,6 @@ static void config_defaults(struct sway_config *config) { config->show_marks = true; config->tiling_drag = true; - config->edge_gaps = true; config->smart_gaps = false; config->gaps_inner = 0; config->gaps_outer = 0; diff --git a/sway/sway.5.scd b/sway/sway.5.scd index f7b778cfa..2e1d13a81 100644 --- a/sway/sway.5.scd +++ b/sway/sway.5.scd @@ -420,15 +420,11 @@ The default colors are: _focus\_wrapping force_. This is only available for convenience. Please use _focus\_wrapping_ instead when possible. -*gaps* edge\_gaps on|off|toggle - When _on_, gaps will be added between windows and workspace edges if the - inner gap is nonzero. When _off_, gaps will only be added between views. - _toggle_ cannot be used in the configuration file. - *gaps* inner|outer Sets default _amount_ pixels of _inner_ or _outer_ gap, where the inner affects spacing around each view and outer affects the spacing around each - workspace. Outer gaps are in addition to inner gaps. + workspace. Outer gaps are in addition to inner gaps. To reduce or remove + outer gaps, outer gaps can be set to a negative value. This affects new workspaces only, and is used when the workspace doesn't have its own gaps settings (see: workspace gaps inner|outer ). diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index d76505607..a1282c1e9 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -73,10 +73,10 @@ struct sway_workspace *workspace_create(struct sway_output *output, if (name) { struct workspace_config *wsc = workspace_find_config(name); if (wsc) { - if (wsc->gaps_outer != -1) { + if (wsc->gaps_outer != INT_MIN) { ws->gaps_outer = wsc->gaps_outer; } - if (wsc->gaps_inner != -1) { + if (wsc->gaps_inner != INT_MIN) { ws->gaps_inner = wsc->gaps_inner; } } @@ -618,9 +618,6 @@ void workspace_add_gaps(struct sway_workspace *ws) { if (ws->current_gaps > 0) { return; } - if (!config->edge_gaps) { - return; - } if (config->smart_gaps) { struct sway_seat *seat = input_manager_get_default_seat(input_manager); struct sway_container *focus =