Skip to content

Commit

Permalink
Prevent workspace gaps from ending up negative
Browse files Browse the repository at this point in the history
Since outer gaps can be negative we need to robustly prevent the
resulting gaps from ending up negative. The previous code only did this
on workspace creation but the gaps can change after that.

Fixes #4304
  • Loading branch information
pedrocr committed Jul 4, 2019
1 parent 9cbf3be commit e43469d
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions sway/tree/workspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,6 @@ struct sway_output *workspace_get_initial_output(const char *name) {
return root->outputs->length ? root->outputs->items[0] : root->noop_output;
}

static void prevent_invalid_outer_gaps(struct sway_workspace *ws) {
if (ws->gaps_outer.top < -ws->gaps_inner) {
ws->gaps_outer.top = -ws->gaps_inner;
}
if (ws->gaps_outer.right < -ws->gaps_inner) {
ws->gaps_outer.right = -ws->gaps_inner;
}
if (ws->gaps_outer.bottom < -ws->gaps_inner) {
ws->gaps_outer.bottom = -ws->gaps_inner;
}
if (ws->gaps_outer.left < -ws->gaps_inner) {
ws->gaps_outer.left = -ws->gaps_inner;
}
}

struct sway_workspace *workspace_create(struct sway_output *output,
const char *name) {
if (output == NULL) {
Expand Down Expand Up @@ -111,9 +96,6 @@ struct sway_workspace *workspace_create(struct sway_output *output,
if (wsc->gaps_inner != INT_MIN) {
ws->gaps_inner = wsc->gaps_inner;
}
// Since default outer gaps can be smaller than the negation of
// workspace specific inner gaps, check outer gaps again
prevent_invalid_outer_gaps(ws);

// Add output priorities
for (int i = 0; i < wsc->outputs->length; ++i) {
Expand Down Expand Up @@ -759,6 +741,14 @@ void workspace_add_gaps(struct sway_workspace *ws) {
ws->current_gaps.bottom += gaps_vertical1;
}

// Prevent the resulting gaps from turning out negative, since outer gaps can
// be negative and nothing ensures they will not be larger than the current
// inner gaps.
ws->current_gaps.left = MAX(0, ws->current_gaps.left);
ws->current_gaps.right = MAX(0, ws->current_gaps.right);
ws->current_gaps.top = MAX(0, ws->current_gaps.top);
ws->current_gaps.bottom = MAX(0, ws->current_gaps.bottom);

// 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 &&
Expand Down

0 comments on commit e43469d

Please sign in to comment.