From abc5fbfaec5159de7e3f6043e61c00b81787a9f2 Mon Sep 17 00:00:00 2001 From: "S. Christoffer Eliesen" Date: Wed, 4 Nov 2015 02:55:38 +0100 Subject: [PATCH] Learn "gaps edge_gaps ". When yes, the old behaviour of adding half the inner gap around each view is used. When no, don't add any gap when an edge of the view aligns with the workspace. The result is inner gap only between views, not against the workspace edge. The algorithm is not perfect because it means the extra space is distributed amongst edge-aligned views only, but it's simple, looks good and it works. --- include/config.h | 1 + sway.5.txt | 5 +++++ sway/commands.c | 17 ++++++++++++++++- sway/config.c | 1 + sway/layout.c | 20 +++++++++++++++++++- 5 files changed, 42 insertions(+), 2 deletions(-) diff --git a/include/config.h b/include/config.h index 56fba691..636d3ec0 100644 --- a/include/config.h +++ b/include/config.h @@ -57,6 +57,7 @@ struct sway_config { bool auto_back_and_forth; bool seamless_mouse; + bool edge_gaps; int gaps_inner; int gaps_outer; }; diff --git a/sway.5.txt b/sway.5.txt index 5659a107..ab2bdedb 100644 --- a/sway.5.txt +++ b/sway.5.txt @@ -68,6 +68,11 @@ Commands **fullscreen**:: Toggles fullscreen status for the focused view. +**gaps** edge_gaps :: + Whether or not to add gaps between views and workspace edges if amount of + inner gap is not zero. When _no_, no gap is added where the view is aligned to + the workspace edge, effectively creating gaps only between views. + **gaps** :: Sets default _amount_ pixels as the gap between each view, and around each workspace. diff --git a/sway/commands.c b/sway/commands.c index 19b8e1a9..2cfda07c 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -761,7 +761,8 @@ static struct cmd_results *cmd_gaps(int argc, char **argv) { return error; } const char* expected_syntax = - "Expected 'gaps '"; + "Expected 'gaps edge_gaps ' or " + "'gaps '"; const char *amount_str = argv[0]; // gaps amount if (argc >= 1 && isdigit(*amount_str)) { @@ -789,6 +790,20 @@ static struct cmd_results *cmd_gaps(int argc, char **argv) { } arrange_windows(&root_container, -1, -1); return cmd_results_new(CMD_SUCCESS, NULL, NULL); + } else if (argc == 2 && strcasecmp(argv[0], "edge_gaps") == 0) { + // gaps edge_gaps + if (strcasecmp(argv[1], "toggle") == 0) { + if (config->reading) { + return cmd_results_new(CMD_FAILURE, "gaps edge_gaps toggle", + "Can't be used in config file."); + } + config->edge_gaps = !config->edge_gaps; + } else { + config->edge_gaps = + (strcasecmp(argv[1], "yes") == 0 || strcasecmp(argv[1], "on") == 0); + } + arrange_windows(&root_container, -1, -1); + return cmd_results_new(CMD_SUCCESS, NULL, NULL); } // gaps inner|outer current|all set|plus|minus n if (argc < 4 || config->reading) { diff --git a/sway/config.c b/sway/config.c index 7e0b22f9..20e4919d 100644 --- a/sway/config.c +++ b/sway/config.c @@ -105,6 +105,7 @@ static void config_defaults(struct sway_config *config) { config->seamless_mouse = true; config->reading = false; + config->edge_gaps = false; config->gaps_inner = 0; config->gaps_outer = 0; } diff --git a/sway/layout.c b/sway/layout.c index c6a05107..3bc297a6 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -367,9 +367,27 @@ void update_geometry(swayc_t *container) { if (op->focused == ws) { wlc_view_bring_to_front(container->handle); } + } else if (!config->edge_gaps && gap > 0) { + // 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 + // with gap, and align correctly). + if (container->x - gap <= ws->x) { + geometry.origin.x = ws->x; + geometry.size.w = container->width - gap/2; + } + if (container->y - gap <= ws->y) { + geometry.origin.y = ws->y; + geometry.size.h = container->height - gap/2; + } + if (container->x + container->width + gap >= ws->x + ws->width) { + geometry.size.w = ws->width - geometry.origin.x; + } + if (container->y + container->height + gap >= ws->y + ws->height) { + geometry.size.h = ws->height - geometry.origin.y; + } } wlc_view_set_geometry(container->handle, 0, &geometry); - return; } static void arrange_windows_r(swayc_t *container, double width, double height) {