diff options
-rw-r--r-- | include/config.h | 1 | ||||
-rw-r--r-- | sway/commands.c | 19 | ||||
-rw-r--r-- | sway/config.c | 1 | ||||
-rw-r--r-- | sway/container.c | 2 | ||||
-rw-r--r-- | sway/layout.c | 2 | ||||
-rw-r--r-- | sway/sway.5.txt | 4 |
6 files changed, 27 insertions, 2 deletions
diff --git a/include/config.h b/include/config.h index d77872ee..9356140d 100644 --- a/include/config.h +++ b/include/config.h @@ -181,6 +181,7 @@ struct sway_config { bool seamless_mouse; bool edge_gaps; + bool smart_gaps; int gaps_inner; int gaps_outer; }; diff --git a/sway/commands.c b/sway/commands.c index e03eef24..4da411c4 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -68,6 +68,7 @@ static sway_cmd cmd_reload; static sway_cmd cmd_resize; static sway_cmd cmd_scratchpad; static sway_cmd cmd_set; +static sway_cmd cmd_smart_gaps; static sway_cmd cmd_split; static sway_cmd cmd_splith; static sway_cmd cmd_splitt; @@ -1480,6 +1481,23 @@ static struct cmd_results *cmd_gaps(int argc, char **argv) { return cmd_results_new(CMD_SUCCESS, NULL, NULL); } +static struct cmd_results *cmd_smart_gaps(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "smart_gaps", EXPECTED_EQUAL_TO, 1))) { + return error; + } + + if (strcasecmp(argv[0], "on") == 0) { + config->smart_gaps = true; + } else if (strcasecmp(argv[0], "off") == 0) { + config->smart_gaps = false; + } else { + return cmd_results_new(CMD_INVALID, "smart_gaps", "Expected 'smart_gaps <on|off>'"); + } + + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} + static struct cmd_results *cmd_kill(int argc, char **argv) { if (config->reading) return cmd_results_new(CMD_FAILURE, "kill", "Can't be used in config file."); if (!config->active) return cmd_results_new(CMD_FAILURE, "kill", "Can only be used when sway is running."); @@ -2048,6 +2066,7 @@ static struct cmd_handler handlers[] = { { "scratchpad", cmd_scratchpad }, { "seamless_mouse", cmd_seamless_mouse }, { "set", cmd_set }, + { "smart_gaps", cmd_smart_gaps }, { "split", cmd_split }, { "splith", cmd_splith }, { "splitt", cmd_splitt }, diff --git a/sway/config.c b/sway/config.c index 296e164c..ebf7546d 100644 --- a/sway/config.c +++ b/sway/config.c @@ -170,6 +170,7 @@ static void config_defaults(struct sway_config *config) { config->reading = false; config->edge_gaps = true; + config->smart_gaps = false; config->gaps_inner = 0; config->gaps_outer = 0; diff --git a/sway/container.c b/sway/container.c index e4c20bc9..9330a3de 100644 --- a/sway/container.c +++ b/sway/container.c @@ -675,7 +675,7 @@ int swayc_gap(swayc_t *container) { return container->gaps >= 0 ? container->gaps : config->gaps_inner; } else if (container->type == C_WORKSPACE) { int base = container->gaps >= 0 ? container->gaps : config->gaps_outer; - if (config->edge_gaps) { + if (config->edge_gaps && !(config->smart_gaps && container->children->length == 1)) { // the inner gap is created via a margin around each window which // is half the gap size, so the workspace also needs half a gap // size to make the outermost gap the same size (excluding the diff --git a/sway/layout.c b/sway/layout.c index e9998bc8..d9c4598f 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -406,7 +406,7 @@ void update_geometry(swayc_t *container) { if (op->focused == ws) { wlc_view_bring_to_front(container->handle); } - } else if (!config->edge_gaps && gap > 0) { + } else if ((!config->edge_gaps && gap > 0) || (config->smart_gaps && ws->children->length == 1)) { // Remove gap against the workspace edges. Because a pixel is not // divisable, depending on gap size and the number of siblings our view // might be at the workspace edge without being exactly so (thus test diff --git a/sway/sway.5.txt b/sway/sway.5.txt index 7a87bb44..e73beb81 100644 --- a/sway/sway.5.txt +++ b/sway/sway.5.txt @@ -154,6 +154,10 @@ or triggered at runtime. workspace (or current workspace), and _current_ changes gaps for the current view or workspace. +**smart_gaps** <on|off>:: + If smart_gaps are _on_ then gaps will only be enabled if a workspace has more + than one child container. + **mode** <mode_name>:: Switches to the given mode_name. the default mode is simply _default_. To create a new mode in config append _{_ to this command, the following lines |