Skip to content

Commit

Permalink
Assign excess space more evenly when spreading out cells, from Torbjorn
Browse files Browse the repository at this point in the history
Lonnemark.
  • Loading branch information
nicm committed Dec 17, 2024
1 parent 6b32d19 commit e149d29
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit e149d29

Please sign in to comment.