From 95c444de337fcf39d16cc4d9b26842177f24256a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20C=C3=B4rte-Real?= Date: Sat, 6 Jul 2019 12:45:32 +0100 Subject: [PATCH] Sanity check gaps on the outside of the workspace Avoid gaps that are too large around the workspace that you end up without any usable space for children. Fixes #4308 --- sway/tree/workspace.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index aca35529..d6819c61 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -706,6 +706,25 @@ void workspace_add_gaps(struct sway_workspace *ws) { ws->current_gaps.bottom = fmax(0, ws->current_gaps.bottom + ws->gaps_inner); ws->current_gaps.left = fmax(0, ws->current_gaps.left + ws->gaps_inner); + // Now that we have the total gaps calculated we may need to clamp them in + // case they've made the available area too small + if (ws->width - ws->current_gaps.left - ws->current_gaps.right < MIN_SANE_W + && ws->current_gaps.left + ws->current_gaps.right > 0) { + int total_gap = fmax(0, ws->width - MIN_SANE_W); + double left_gap_frac = ((double)ws->current_gaps.left / + ((double)ws->current_gaps.left + (double)ws->current_gaps.right)); + ws->current_gaps.left = left_gap_frac * total_gap; + ws->current_gaps.right = total_gap - ws->current_gaps.left; + } + if (ws->height - ws->current_gaps.top - ws->current_gaps.bottom < MIN_SANE_H + && ws->current_gaps.top + ws->current_gaps.bottom > 0) { + int total_gap = fmax(0, ws->height - MIN_SANE_H); + double top_gap_frac = ((double) ws->current_gaps.top / + ((double)ws->current_gaps.top + (double)ws->current_gaps.bottom)); + ws->current_gaps.top = top_gap_frac * total_gap; + ws->current_gaps.bottom = total_gap - ws->current_gaps.top; + } + ws->x += ws->current_gaps.left; ws->y += ws->current_gaps.top; ws->width -= ws->current_gaps.left + ws->current_gaps.right;