Skip to content

Commit

Permalink
Limit gap sizing to sensible values
Browse files Browse the repository at this point in the history
Large inner gaps can lead to broken rendering with width/height going
negative. Limit the gaps so that they never make the windows smaller
than a minimum sensible size (the same used for the resize command).

Fixes swaywm#4294
  • Loading branch information
pedrocr committed Jul 1, 2019
1 parent 5c0396b commit ca44661
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
14 changes: 8 additions & 6 deletions sway/tree/container.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "log.h"
#include "stringop.h"

static const int MIN_SANE_W = 100, MIN_SANE_H = 60;

struct sway_container *container_create(struct sway_view *view) {
struct sway_container *c = calloc(1, sizeof(struct sway_container));
if (!c) {
Expand Down Expand Up @@ -1226,13 +1228,13 @@ void container_add_gaps(struct sway_container *c) {
}
}

int gaps1 = ws->gaps_inner / 2;
int gaps2 = ws->gaps_inner - gaps1;
int gaps_horizontal = MAX(0, ws->gaps_inner + MIN(0, c->width - ws->gaps_inner - MIN_SANE_W));
c->current_gaps.left = gaps_horizontal / 2;
c->current_gaps.right = gaps_horizontal - (gaps_horizontal / 2);

c->current_gaps.top = gaps1;
c->current_gaps.bottom = gaps2;
c->current_gaps.left = gaps1;
c->current_gaps.right = gaps2;
int gaps_vertical = MAX(0, ws->gaps_inner + MIN(0, c->height - ws->gaps_inner - MIN_SANE_H));
c->current_gaps.top = gaps_vertical / 2;
c->current_gaps.bottom = gaps_vertical - (gaps_vertical / 2);

c->x += c->current_gaps.left;
c->y += c->current_gaps.top;
Expand Down
21 changes: 12 additions & 9 deletions sway/tree/workspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <stdio.h>
#include <strings.h>
#include "stringop.h"
#include "pango.h"
#include "sway/input/input-manager.h"
#include "sway/input/cursor.h"
#include "sway/input/seat.h"
Expand All @@ -20,6 +21,8 @@
#include "log.h"
#include "util.h"

static const int MIN_SANE_W = 100, MIN_SANE_H = 60;

struct workspace_config *workspace_find_config(const char *ws_name) {
for (int i = 0; i < config->workspace_configs->length; ++i) {
struct workspace_config *wsc = config->workspace_configs->items[i];
Expand Down Expand Up @@ -746,15 +749,15 @@ void workspace_add_gaps(struct sway_workspace *ws) {
} 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;
// themselves. We use the opposite order for the two halves so that the
// sum adds up to the correct total gap size in all circumstances.
int gaps_horizontal = MAX(0, ws->gaps_inner + MIN(0, ws->width - ws->gaps_inner - MIN_SANE_W));
ws->current_gaps.left += gaps_horizontal - (gaps_horizontal / 2);
ws->current_gaps.right += gaps_horizontal / 2;

int gaps_vertical = MAX(0, ws->gaps_inner + MIN(0, ws->height - ws->gaps_inner - MIN_SANE_H));
ws->current_gaps.top += gaps_vertical - (gaps_vertical / 2);
ws->current_gaps.bottom += gaps_vertical / 2;
}

ws->x += ws->current_gaps.left;
Expand Down

0 comments on commit ca44661

Please sign in to comment.