diff --git a/include/config.h b/include/config.h index d77872ee3..9356140de 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 e03eef245..4da411c43 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 '"); + } + + 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 296e164cc..ebf7546de 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 e4c20bc9e..9330a3deb 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 e9998bc8f..d9c4598f0 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 7a87bb44d..e73beb81c 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** :: + If smart_gaps are _on_ then gaps will only be enabled if a workspace has more + than one child container. + **mode** :: 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