From e149d29803781436ff6496e151ceeb0779891e76 Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 17 Dec 2024 08:40:24 +0000 Subject: [PATCH] Assign excess space more evenly when spreading out cells, from Torbjorn Lonnemark. --- layout.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/layout.c b/layout.c index 7a63d36f..2832039c 100644 --- a/layout.c +++ b/layout.c @@ -1101,7 +1101,7 @@ layout_spread_cell(struct window *w, struct layout_cell *parent) { struct layout_cell *lc; struct style *sb_style = &w->active->scrollbar_style; - u_int number, each, size, this; + u_int number, each, size, this, remainder; int change, changed, status, scrollbars; number = 0; @@ -1130,20 +1130,31 @@ layout_spread_cell(struct window *w, struct layout_cell *parent) each = (size - (number - 1)) / number; if (each == 0) return (0); + /* + * Remaining space after assigning that which can be evenly + * distributed. + */ + remainder = size - (number * (each + 1)) + 1; changed = 0; TAILQ_FOREACH (lc, &parent->cells, entry) { - if (TAILQ_NEXT(lc, entry) == NULL) - each = size - ((each + 1) * (number - 1)); change = 0; if (parent->type == LAYOUT_LEFTRIGHT) { change = each - (int)lc->sx; + if (remainder > 0) { + change++; + remainder--; + } layout_resize_adjust(w, lc, LAYOUT_LEFTRIGHT, change); } else if (parent->type == LAYOUT_TOPBOTTOM) { if (layout_add_horizontal_border(w, lc, status)) this = each + 1; else this = each; + if (remainder > 0) { + this++; + remainder--; + } change = this - (int)lc->sy; layout_resize_adjust(w, lc, LAYOUT_TOPBOTTOM, change); }