From 5c0396b3f161345171fae194761740ee5a5d8d6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20C=C3=B4rte-Real?= Date: Sun, 30 Jun 2019 23:42:28 +0100 Subject: [PATCH] Make inner gaps apply evenly across all windows To make sure inner gaps don't generate unequally sized windows always apply a total of one inner gap to all children. Doing just this would result in half-gaps around the workspace border so compensate for that by adding gaps to the workspace. Fixes #4296 --- sway/tree/container.c | 11 +++++++---- sway/tree/workspace.c | 12 ++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/sway/tree/container.c b/sway/tree/container.c index 9046ae27d..dd5b6d7bb 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -1226,10 +1226,13 @@ void container_add_gaps(struct sway_container *c) { } } - c->current_gaps.top = c->y == ws->y ? ws->gaps_inner : 0; - c->current_gaps.right = ws->gaps_inner; - c->current_gaps.bottom = ws->gaps_inner; - c->current_gaps.left = c->x == ws->x ? ws->gaps_inner : 0; + int gaps1 = ws->gaps_inner / 2; + int gaps2 = ws->gaps_inner - gaps1; + + c->current_gaps.top = gaps1; + c->current_gaps.bottom = gaps2; + c->current_gaps.left = gaps1; + c->current_gaps.right = gaps2; c->x += c->current_gaps.left; c->y += c->current_gaps.top; diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index 914b6a9de..7d7422de5 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -743,6 +743,18 @@ void workspace_add_gaps(struct sway_workspace *ws) { ws->current_gaps.right += ws->gaps_inner; ws->current_gaps.bottom += ws->gaps_inner; ws->current_gaps.left += ws->gaps_inner; + } else { + // For tiled containers we need to add the half-gap all around the edge + // to match the half gaps that the children have all already added around + // themselves. We use the opposite gaps1/gaps2 order so that the sum adds + // up to the correct total gap size in all circumstances. + int gaps1 = ws->gaps_inner / 2; + int gaps2 = ws->gaps_inner - gaps1; + + ws->current_gaps.top += gaps2; + ws->current_gaps.bottom += gaps1; + ws->current_gaps.left += gaps2; + ws->current_gaps.right += gaps1; } ws->x += ws->current_gaps.left;