# HG changeset patch # Parent 151b3edef04b13ede6e60c5567421867ef534b55 diff --git a/layout-set.c b/layout-set.c --- a/layout-set.c +++ b/layout-set.c @@ -126,6 +126,7 @@ struct window_pane *wp; struct layout_cell *lc, *lcnew; u_int i, n, width, xoff; + int rem; layout_print_cell(w->layout_root, __func__, 1); @@ -138,6 +139,7 @@ width = (w->sx - (n - 1)) / n; if (width < PANE_MINIMUM) width = PANE_MINIMUM; + rem = w->sx - (width + 1) * n + 1; /* Free the old root and construct a new. */ layout_free(w); @@ -150,7 +152,7 @@ TAILQ_FOREACH(wp, &w->panes, entry) { /* Create child cell. */ lcnew = layout_create_cell(lc); - layout_set_size(lcnew, width, w->sy, xoff, 0); + layout_set_size(lcnew, width + (rem-- > 0), w->sy, xoff, 0); layout_make_leaf(lcnew, wp); TAILQ_INSERT_TAIL(&lc->cells, lcnew, entry); @@ -158,12 +160,6 @@ xoff += width + 1; } - /* Allocate any remaining space. */ - if (w->sx > xoff - 1) { - lc = TAILQ_LAST(&lc->cells, layout_cells); - layout_resize_adjust(lc, LAYOUT_LEFTRIGHT, w->sx - (xoff - 1)); - } - /* Fix cell offsets. */ layout_fix_offsets(lc); layout_fix_panes(w, w->sx, w->sy); @@ -179,6 +175,7 @@ struct window_pane *wp; struct layout_cell *lc, *lcnew; u_int i, n, height, yoff; + int rem; layout_print_cell(w->layout_root, __func__, 1); @@ -191,6 +188,7 @@ height = (w->sy - (n - 1)) / n; if (height < PANE_MINIMUM) height = PANE_MINIMUM; + rem = w->sy - (height + 1) * n + 1; /* Free the old root and construct a new. */ layout_free(w); @@ -203,7 +201,7 @@ TAILQ_FOREACH(wp, &w->panes, entry) { /* Create child cell. */ lcnew = layout_create_cell(lc); - layout_set_size(lcnew, w->sx, height, 0, yoff); + layout_set_size(lcnew, w->sx, height + (rem-- > 0), 0, yoff); layout_make_leaf(lcnew, wp); TAILQ_INSERT_TAIL(&lc->cells, lcnew, entry); @@ -211,12 +209,6 @@ yoff += height + 1; } - /* Allocate any remaining space. */ - if (w->sy > yoff - 1) { - lc = TAILQ_LAST(&lc->cells, layout_cells); - layout_resize_adjust(lc, LAYOUT_TOPBOTTOM, w->sy - (yoff - 1)); - } - /* Fix cell offsets. */ layout_fix_offsets(lc); layout_fix_panes(w, w->sx, w->sy); @@ -233,6 +225,7 @@ struct layout_cell *lc, *lcmain, *lcrow, *lcchild; u_int n, mainheight, otherheight, width, height; u_int used, i, j, columns, rows, totalrows; + int rem; layout_print_cell(w->layout_root, __func__, 1); @@ -249,6 +242,7 @@ rows = 1 + (n - 1) / columns; columns = 1 + (n - 1) / rows; width = (w->sx - (n - 1)) / columns; + rem = w->sx - (width + 1) * columns + 1; /* Get the main pane height and add one for separator line. */ mainheight = options_get_number(&w->options, "main-pane-height") + 1; @@ -312,7 +306,7 @@ for (i = 0; i < columns; i++) { /* Create and add a pane cell. */ lcchild = layout_create_cell(lcrow); - layout_set_size(lcchild, width, height, 0, 0); + layout_set_size(lcchild, width + (rem-- > 0), height, 0, 0); layout_make_leaf(lcchild, wp); TAILQ_INSERT_TAIL(&lcrow->cells, lcchild, entry); @@ -320,15 +314,6 @@ if ((wp = TAILQ_NEXT(wp, entry)) == NULL) break; } - - /* Adjust the row to fit the full width if necessary. */ - if (i == columns) - i--; - used = ((i + 1) * (width + 1)) - 1; - if (w->sx <= used) - continue; - lcchild = TAILQ_LAST(&lcrow->cells, layout_cells); - layout_resize_adjust(lcchild, LAYOUT_LEFTRIGHT, w->sx - used); } /* Adjust the last row height to fit if necessary. */ @@ -354,6 +339,7 @@ struct layout_cell *lc, *lcmain, *lccolumn, *lcchild; u_int n, mainwidth, otherwidth, width, height; u_int used, i, j, columns, rows, totalcolumns; + int rem; layout_print_cell(w->layout_root, __func__, 1); @@ -370,6 +356,7 @@ columns = 1 + (n - 1) / rows; rows = 1 + (n - 1) / columns; height = (w->sy - (n - 1)) / rows; + rem = w->sy - (height + 1) * rows + 1; /* Get the main pane width and add one for separator line. */ mainwidth = options_get_number(&w->options, "main-pane-width") + 1; @@ -433,7 +420,7 @@ for (i = 0; i < rows; i++) { /* Create and add a pane cell. */ lcchild = layout_create_cell(lccolumn); - layout_set_size(lcchild, width, height, 0, 0); + layout_set_size(lcchild, width, height + (rem-- > 0), 0, 0); layout_make_leaf(lcchild, wp); TAILQ_INSERT_TAIL(&lccolumn->cells, lcchild, entry); @@ -441,15 +428,6 @@ if ((wp = TAILQ_NEXT(wp, entry)) == NULL) break; } - - /* Adjust the column to fit the full height if necessary. */ - if (i == rows) - i--; - used = ((i + 1) * (height + 1)) - 1; - if (w->sy <= used) - continue; - lcchild = TAILQ_LAST(&lccolumn->cells, layout_cells); - layout_resize_adjust(lcchild, LAYOUT_TOPBOTTOM, w->sy - used); } /* Adjust the last column width to fit if necessary. */ @@ -475,6 +453,8 @@ struct layout_cell *lc, *lcrow, *lcchild; u_int n, width, height, used; u_int i, j, columns, rows; + int wrem, wrem1, hrem; + u_int width1, height1; layout_print_cell(w->layout_root, __func__, 1); @@ -498,12 +478,13 @@ height = (w->sy - (rows - 1)) / rows; if (height < PANE_MINIMUM) height = PANE_MINIMUM; + wrem = w->sx - (width + 1) * columns + 1; + hrem = w->sy - (height + 1) * rows + 1; /* Free old tree and create a new root. */ layout_free(w); lc = w->layout_root = layout_create_cell(NULL); - layout_set_size(lc, (width + 1) * columns - 1, - (height + 1) * rows - 1, 0, 0); + layout_set_size(lc, w->sx, w->sy, 0, 0); layout_make_node(lc, LAYOUT_TOPBOTTOM); /* Create a grid of the cells. */ @@ -515,7 +496,8 @@ /* Create the new row. */ lcrow = layout_create_cell(lc); - layout_set_size(lcrow, w->sx, height, 0, 0); + height1 = height + (hrem-- > 0); + layout_set_size(lcrow, w->sx, height1, 0, 0); TAILQ_INSERT_TAIL(&lc->cells, lcrow, entry); /* If only one column, just use the row directly. */ @@ -526,13 +508,17 @@ } /* Add in the columns. */ + wrem1 = wrem; + used = 0; layout_make_node(lcrow, LAYOUT_LEFTRIGHT); for (i = 0; i < columns; i++) { /* Create and add a pane cell. */ lcchild = layout_create_cell(lcrow); - layout_set_size(lcchild, width, height, 0, 0); + width1 = width + (wrem1-- > 0); + layout_set_size(lcchild, width1, height1, 0, 0); layout_make_leaf(lcchild, wp); TAILQ_INSERT_TAIL(&lcrow->cells, lcchild, entry); + used += width1 + 1; /* Move to the next cell. */ if ((wp = TAILQ_NEXT(wp, entry)) == NULL) @@ -543,22 +529,13 @@ * Adjust the row and columns to fit the full width if * necessary. */ - if (i == columns) - i--; - used = ((i + 1) * (width + 1)) - 1; + used--; if (w->sx <= used) continue; lcchild = TAILQ_LAST(&lcrow->cells, layout_cells); layout_resize_adjust(lcchild, LAYOUT_LEFTRIGHT, w->sx - used); } - /* Adjust the last row height to fit if necessary. */ - used = (rows * height) + rows - 1; - if (w->sy > used) { - lcrow = TAILQ_LAST(&lc->cells, layout_cells); - layout_resize_adjust(lcrow, LAYOUT_TOPBOTTOM, w->sy - used); - } - /* Fix cell offsets. */ layout_fix_offsets(lc); layout_fix_panes(w, w->sx, w->sy);