aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/workspace.c
diff options
context:
space:
mode:
authorLibravatar Pedro CĂ´rte-Real <pedro@pedrocr.net>2019-07-06 12:45:32 +0100
committerLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-07-15 23:46:27 -0400
commit95c444de337fcf39d16cc4d9b26842177f24256a (patch)
treee0f4e09406b086958fd2e3377af1a24f1e1f877b /sway/tree/workspace.c
parentAvoid negative outer gaps (diff)
downloadsway-95c444de337fcf39d16cc4d9b26842177f24256a.tar.gz
sway-95c444de337fcf39d16cc4d9b26842177f24256a.tar.zst
sway-95c444de337fcf39d16cc4d9b26842177f24256a.zip
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
Diffstat (limited to 'sway/tree/workspace.c')
-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) {
706 ws->current_gaps.bottom = fmax(0, ws->current_gaps.bottom + ws->gaps_inner); 706 ws->current_gaps.bottom = fmax(0, ws->current_gaps.bottom + ws->gaps_inner);
707 ws->current_gaps.left = fmax(0, ws->current_gaps.left + ws->gaps_inner); 707 ws->current_gaps.left = fmax(0, ws->current_gaps.left + ws->gaps_inner);
708 708
709 // Now that we have the total gaps calculated we may need to clamp them in
710 // case they've made the available area too small
711 if (ws->width - ws->current_gaps.left - ws->current_gaps.right < MIN_SANE_W
712 && ws->current_gaps.left + ws->current_gaps.right > 0) {
713 int total_gap = fmax(0, ws->width - MIN_SANE_W);
714 double left_gap_frac = ((double)ws->current_gaps.left /
715 ((double)ws->current_gaps.left + (double)ws->current_gaps.right));
716 ws->current_gaps.left = left_gap_frac * total_gap;
717 ws->current_gaps.right = total_gap - ws->current_gaps.left;
718 }
719 if (ws->height - ws->current_gaps.top - ws->current_gaps.bottom < MIN_SANE_H
720 && ws->current_gaps.top + ws->current_gaps.bottom > 0) {
721 int total_gap = fmax(0, ws->height - MIN_SANE_H);
722 double top_gap_frac = ((double) ws->current_gaps.top /
723 ((double)ws->current_gaps.top + (double)ws->current_gaps.bottom));
724 ws->current_gaps.top = top_gap_frac * total_gap;
725 ws->current_gaps.bottom = total_gap - ws->current_gaps.top;
726 }
727
709 ws->x += ws->current_gaps.left; 728 ws->x += ws->current_gaps.left;
710 ws->y += ws->current_gaps.top; 729 ws->y += ws->current_gaps.top;
711 ws->width -= ws->current_gaps.left + ws->current_gaps.right; 730 ws->width -= ws->current_gaps.left + ws->current_gaps.right;