aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPedro CĂ´rte-Real <pedro@pedrocr.net>2019-07-06 12:45:32 +0100
committerBrian Ashworth <bosrsf04@gmail.com>2019-07-15 23:46:27 -0400
commit95c444de337fcf39d16cc4d9b26842177f24256a (patch)
treee0f4e09406b086958fd2e3377af1a24f1e1f877b
parent99192a92f942f120f8cd0c6037c613325677a332 (diff)
downloadsway-95c444de337fcf39d16cc4d9b26842177f24256a.tar.xz
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
-rw-r--r--sway/tree/workspace.c19
1 files changed, 19 insertions, 0 deletions
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;