Limit inner gaps to sensible values

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 #4294
This commit is contained in:
Pedro Côrte-Real 2019-07-01 00:20:47 +01:00
parent 5c0396b3f1
commit b589767e9c
6 changed files with 33 additions and 16 deletions

View file

@ -3,6 +3,9 @@
#include <stdbool.h> #include <stdbool.h>
#include "list.h" #include "list.h"
#define MIN_SANE_W 100
#define MIN_SANE_H 60
struct sway_root; struct sway_root;
struct sway_output; struct sway_output;
struct sway_workspace; struct sway_workspace;

View file

@ -34,4 +34,9 @@ const char *sway_wl_output_subpixel_to_string(enum wl_output_subpixel subpixel);
bool set_cloexec(int fd, bool cloexec); bool set_cloexec(int fd, bool cloexec);
#undef MAX
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#undef MIN
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif #endif

View file

@ -15,8 +15,6 @@
#define AXIS_HORIZONTAL (WLR_EDGE_LEFT | WLR_EDGE_RIGHT) #define AXIS_HORIZONTAL (WLR_EDGE_LEFT | WLR_EDGE_RIGHT)
#define AXIS_VERTICAL (WLR_EDGE_TOP | WLR_EDGE_BOTTOM) #define AXIS_VERTICAL (WLR_EDGE_TOP | WLR_EDGE_BOTTOM)
static const int MIN_SANE_W = 100, MIN_SANE_H = 60;
enum resize_unit { enum resize_unit {
RESIZE_UNIT_PX, RESIZE_UNIT_PX,
RESIZE_UNIT_PPT, RESIZE_UNIT_PPT,

View file

@ -568,6 +568,9 @@ The default colors are:
This affects new workspaces only, and is used when the workspace doesn't This affects new workspaces only, and is used when the workspace doesn't
have its own gaps settings (see: workspace <ws> gaps ...). have its own gaps settings (see: workspace <ws> gaps ...).
If the gaps are too large and would make a view too narrow or short they
are adjusted to be smaller or even removed for that specific view.
*hide_edge_borders* [--i3] none|vertical|horizontal|both|smart|smart_no_gaps *hide_edge_borders* [--i3] none|vertical|horizontal|both|smart|smart_no_gaps
Hides window borders adjacent to the screen edges. Default is _none_. The Hides window borders adjacent to the screen edges. Default is _none_. The
_--i3_ option enables i3-compatible behavior to hide the title bar on tabbed _--i3_ option enables i3-compatible behavior to hide the title bar on tabbed

View file

@ -1226,13 +1226,17 @@ void container_add_gaps(struct sway_container *c) {
} }
} }
int gaps1 = ws->gaps_inner / 2; int gaps_horizontal = MAX(0, MIN(ws->gaps_inner, c->width - MIN_SANE_W));
int gaps2 = ws->gaps_inner - gaps1; int gaps_horizontal1 = gaps_horizontal / 2;
int gaps_horizontal2 = gaps_horizontal - gaps_horizontal1;
c->current_gaps.left = gaps_horizontal1;
c->current_gaps.right = gaps_horizontal2;
c->current_gaps.top = gaps1; int gaps_vertical = MAX(0, MIN(ws->gaps_inner, c->height - MIN_SANE_H));
c->current_gaps.bottom = gaps2; int gaps_vertical1 = gaps_vertical / 2;
c->current_gaps.left = gaps1; int gaps_vertical2 = gaps_vertical - gaps_vertical1;
c->current_gaps.right = gaps2; c->current_gaps.top = gaps_vertical1;
c->current_gaps.bottom = gaps_vertical2;
c->x += c->current_gaps.left; c->x += c->current_gaps.left;
c->y += c->current_gaps.top; c->y += c->current_gaps.top;

View file

@ -746,15 +746,19 @@ void workspace_add_gaps(struct sway_workspace *ws) {
} else { } else {
// For tiled containers we need to add the half-gap all around the edge // 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 // 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 // themselves. We use the opposite order for the two halves so that the
// up to the correct total gap size in all circumstances. // sum adds up to the correct total gap size in all circumstances.
int gaps1 = ws->gaps_inner / 2; int gaps_horizontal = MAX(0, MIN(ws->gaps_inner, ws->width - MIN_SANE_W));
int gaps2 = ws->gaps_inner - gaps1; int gaps_horizontal1 = gaps_horizontal / 2;
int gaps_horizontal2 = gaps_horizontal - gaps_horizontal1;
ws->current_gaps.left += gaps_horizontal2;
ws->current_gaps.right += gaps_horizontal1;
ws->current_gaps.top += gaps2; int gaps_vertical = MAX(0, MIN(ws->gaps_inner, ws->height - MIN_SANE_H));
ws->current_gaps.bottom += gaps1; int gaps_vertical1 = gaps_vertical / 2;
ws->current_gaps.left += gaps2; int gaps_vertical2 = gaps_vertical - gaps_vertical1;
ws->current_gaps.right += gaps1; ws->current_gaps.top += gaps_vertical2;
ws->current_gaps.bottom += gaps_vertical1;
} }
ws->x += ws->current_gaps.left; ws->x += ws->current_gaps.left;