diff --git a/include/sway/tree/node.h b/include/sway/tree/node.h index 5b8c19093..470ee3b5e 100644 --- a/include/sway/tree/node.h +++ b/include/sway/tree/node.h @@ -3,6 +3,9 @@ #include #include "list.h" +#define MIN_SANE_W 100 +#define MIN_SANE_H 60 + struct sway_root; struct sway_output; struct sway_workspace; diff --git a/include/util.h b/include/util.h index 6d9454e05..f359f28a3 100644 --- a/include/util.h +++ b/include/util.h @@ -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 diff --git a/sway/commands/resize.c b/sway/commands/resize.c index 440937f0d..f8449f9d4 100644 --- a/sway/commands/resize.c +++ b/sway/commands/resize.c @@ -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, diff --git a/sway/sway.5.scd b/sway/sway.5.scd index 90d7fed8e..0d825085b 100644 --- a/sway/sway.5.scd +++ b/sway/sway.5.scd @@ -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 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 diff --git a/sway/tree/container.c b/sway/tree/container.c index dd5b6d7bb..db4c2c7be 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -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; diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index 7d7422de5..2a4eef89d 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -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;