mirror of
https://github.com/swaywm/sway.git
synced 2026-04-27 06:46:25 -04:00
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:
parent
5c0396b3f1
commit
b589767e9c
6 changed files with 33 additions and 16 deletions
|
|
@ -3,6 +3,9 @@
|
|||
#include <stdbool.h>
|
||||
#include "list.h"
|
||||
|
||||
#define MIN_SANE_W 100
|
||||
#define MIN_SANE_H 60
|
||||
|
||||
struct sway_root;
|
||||
struct sway_output;
|
||||
struct sway_workspace;
|
||||
|
|
|
|||
|
|
@ -34,4 +34,9 @@ const char *sway_wl_output_subpixel_to_string(enum wl_output_subpixel subpixel);
|
|||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -15,8 +15,6 @@
|
|||
#define AXIS_HORIZONTAL (WLR_EDGE_LEFT | WLR_EDGE_RIGHT)
|
||||
#define AXIS_VERTICAL (WLR_EDGE_TOP | WLR_EDGE_BOTTOM)
|
||||
|
||||
static const int MIN_SANE_W = 100, MIN_SANE_H = 60;
|
||||
|
||||
enum resize_unit {
|
||||
RESIZE_UNIT_PX,
|
||||
RESIZE_UNIT_PPT,
|
||||
|
|
|
|||
|
|
@ -568,6 +568,9 @@ The default colors are:
|
|||
This affects new workspaces only, and is used when the workspace doesn't
|
||||
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
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1226,13 +1226,17 @@ 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, MIN(ws->gaps_inner, c->width - MIN_SANE_W));
|
||||
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;
|
||||
c->current_gaps.bottom = gaps2;
|
||||
c->current_gaps.left = gaps1;
|
||||
c->current_gaps.right = gaps2;
|
||||
int gaps_vertical = MAX(0, MIN(ws->gaps_inner, c->height - MIN_SANE_H));
|
||||
int gaps_vertical1 = gaps_vertical / 2;
|
||||
int gaps_vertical2 = gaps_vertical - gaps_vertical1;
|
||||
c->current_gaps.top = gaps_vertical1;
|
||||
c->current_gaps.bottom = gaps_vertical2;
|
||||
|
||||
c->x += c->current_gaps.left;
|
||||
c->y += c->current_gaps.top;
|
||||
|
|
|
|||
|
|
@ -746,15 +746,19 @@ 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;
|
||||
// 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, MIN(ws->gaps_inner, ws->width - MIN_SANE_W));
|
||||
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;
|
||||
ws->current_gaps.bottom += gaps1;
|
||||
ws->current_gaps.left += gaps2;
|
||||
ws->current_gaps.right += gaps1;
|
||||
int gaps_vertical = MAX(0, MIN(ws->gaps_inner, ws->height - MIN_SANE_H));
|
||||
int gaps_vertical1 = gaps_vertical / 2;
|
||||
int gaps_vertical2 = gaps_vertical - gaps_vertical1;
|
||||
ws->current_gaps.top += gaps_vertical2;
|
||||
ws->current_gaps.bottom += gaps_vertical1;
|
||||
}
|
||||
|
||||
ws->x += ws->current_gaps.left;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue