=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/layout-set.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- src/usr.bin/tmux/layout-set.c 2010/04/25 20:28:13 1.6 +++ src/usr.bin/tmux/layout-set.c 2010/12/08 19:57:03 1.7 @@ -1,4 +1,4 @@ -/* $OpenBSD: layout-set.c,v 1.6 2010/04/25 20:28:13 nicm Exp $ */ +/* $OpenBSD: layout-set.c,v 1.7 2010/12/08 19:57:03 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -135,10 +135,9 @@ return; /* How many can we fit? */ - if (w->sx / n < PANE_MINIMUM + 1) - width = PANE_MINIMUM + 1; - else - width = w->sx / n; + width = (w->sx - (n - 1)) / n; + if (width < PANE_MINIMUM) + width = PANE_MINIMUM; /* Free the old root and construct a new. */ layout_free(w); @@ -151,12 +150,12 @@ TAILQ_FOREACH(wp, &w->panes, entry) { /* Create child cell. */ lcnew = layout_create_cell(lc); - layout_set_size(lcnew, width - 1, w->sy, xoff, 0); + layout_set_size(lcnew, width, w->sy, xoff, 0); layout_make_leaf(lcnew, wp); TAILQ_INSERT_TAIL(&lc->cells, lcnew, entry); i++; - xoff += width; + xoff += width + 1; } /* Allocate any remaining space. */ @@ -189,10 +188,9 @@ return; /* How many can we fit? */ - if (w->sy / n < PANE_MINIMUM + 1) - height = PANE_MINIMUM + 1; - else - height = w->sy / n; + height = (w->sy - (n - 1)) / n; + if (height < PANE_MINIMUM) + height = PANE_MINIMUM; /* Free the old root and construct a new. */ layout_free(w); @@ -205,12 +203,12 @@ TAILQ_FOREACH(wp, &w->panes, entry) { /* Create child cell. */ lcnew = layout_create_cell(lc); - layout_set_size(lcnew, w->sx, height - 1, 0, yoff); + layout_set_size(lcnew, w->sx, height, 0, yoff); layout_make_leaf(lcnew, wp); TAILQ_INSERT_TAIL(&lc->cells, lcnew, entry); i++; - yoff += height; + yoff += height + 1; } /* Allocate any remaining space. */ @@ -244,13 +242,13 @@ return; n--; /* take off main pane */ - /* How many rows and columns will be needed? */ - columns = w->sx / (PANE_MINIMUM + 1); /* maximum columns */ + /* How many rows and columns will be needed, not counting main? */ + columns = (w->sx + 1) / (PANE_MINIMUM + 1); /* maximum columns */ if (columns == 0) columns = 1; rows = 1 + (n - 1) / columns; columns = 1 + (n - 1) / rows; - width = w->sx / columns; + width = (w->sx - (n - 1)) / columns; /* Get the main pane height and add one for separator line. */ mainheight = options_get_number(&w->options, "main-pane-height") + 1; @@ -264,14 +262,14 @@ mainheight = PANE_MINIMUM + 2; else mainheight = w->sy - totalrows; - height = PANE_MINIMUM + 1; + height = PANE_MINIMUM; } else - height = (w->sy - mainheight) / rows; + height = (w->sy - mainheight - (rows - 1)) / rows; /* Free old tree and create a new root. */ layout_free(w); lc = w->layout_root = layout_create_cell(NULL); - layout_set_size(lc, w->sx, mainheight + rows * height, 0, 0); + layout_set_size(lc, w->sx, mainheight + rows * (height + 1) - 1, 0, 0); layout_make_node(lc, LAYOUT_TOPBOTTOM); /* Create the main pane. */ @@ -289,7 +287,7 @@ /* Create the new row. */ lcrow = layout_create_cell(lc); - layout_set_size(lcrow, w->sx, height - 1, 0, 0); + layout_set_size(lcrow, w->sx, height, 0, 0); TAILQ_INSERT_TAIL(&lc->cells, lcrow, entry); /* If only one column, just use the row directly. */ @@ -304,7 +302,7 @@ for (i = 0; i < columns; i++) { /* Create and add a pane cell. */ lcchild = layout_create_cell(lcrow); - layout_set_size(lcchild, width - 1, height - 1, 0, 0); + layout_set_size(lcchild, width, height, 0, 0); layout_make_leaf(lcchild, wp); TAILQ_INSERT_TAIL(&lcrow->cells, lcchild, entry); @@ -316,7 +314,7 @@ /* Adjust the row to fit the full width if necessary. */ if (i == columns) i--; - used = ((i + 1) * width) - 1; + used = ((i + 1) * (width + 1)) - 1; if (w->sx <= used) continue; lcchild = TAILQ_LAST(&lcrow->cells, layout_cells); @@ -324,7 +322,7 @@ } /* Adjust the last row height to fit if necessary. */ - used = mainheight + (rows * height) - 1; + used = mainheight + (rows * height) + rows - 1; if (w->sy > used) { lcrow = TAILQ_LAST(&lc->cells, layout_cells); layout_resize_adjust(lcrow, LAYOUT_TOPBOTTOM, w->sy - used); @@ -355,13 +353,13 @@ return; n--; /* take off main pane */ - /* How many rows and columns will be needed? */ - rows = w->sy / (PANE_MINIMUM + 1); /* maximum rows */ + /* How many rows and columns will be needed, not counting main? */ + rows = (w->sy + 1) / (PANE_MINIMUM + 1); /* maximum rows */ if (rows == 0) rows = 1; columns = 1 + (n - 1) / rows; rows = 1 + (n - 1) / columns; - height = w->sy / rows; + height = (w->sy - (n - 1)) / rows; /* Get the main pane width and add one for separator line. */ mainwidth = options_get_number(&w->options, "main-pane-width") + 1; @@ -375,14 +373,14 @@ mainwidth = PANE_MINIMUM + 2; else mainwidth = w->sx - totalcolumns; - width = PANE_MINIMUM + 1; + width = PANE_MINIMUM; } else - width = (w->sx - mainwidth) / columns; + width = (w->sx - mainwidth - (columns - 1)) / columns; /* Free old tree and create a new root. */ layout_free(w); lc = w->layout_root = layout_create_cell(NULL); - layout_set_size(lc, mainwidth + columns * width, w->sy, 0, 0); + layout_set_size(lc, mainwidth + columns * (width + 1) - 1, w->sy, 0, 0); layout_make_node(lc, LAYOUT_LEFTRIGHT); /* Create the main pane. */ @@ -400,7 +398,7 @@ /* Create the new column. */ lccolumn = layout_create_cell(lc); - layout_set_size(lccolumn, width - 1, w->sy, 0, 0); + layout_set_size(lccolumn, width, w->sy, 0, 0); TAILQ_INSERT_TAIL(&lc->cells, lccolumn, entry); /* If only one row, just use the row directly. */ @@ -415,7 +413,7 @@ for (i = 0; i < rows; i++) { /* Create and add a pane cell. */ lcchild = layout_create_cell(lccolumn); - layout_set_size(lcchild, width - 1, height - 1, 0, 0); + layout_set_size(lcchild, width, height, 0, 0); layout_make_leaf(lcchild, wp); TAILQ_INSERT_TAIL(&lccolumn->cells, lcchild, entry); @@ -427,7 +425,7 @@ /* Adjust the column to fit the full height if necessary. */ if (i == rows) i--; - used = ((i + 1) * height) - 1; + used = ((i + 1) * (height + 1)) - 1; if (w->sy <= used) continue; lcchild = TAILQ_LAST(&lccolumn->cells, layout_cells); @@ -435,7 +433,7 @@ } /* Adjust the last column width to fit if necessary. */ - used = mainwidth + (columns * width) - 1; + used = mainwidth + (columns * width) + columns - 1; if (w->sx > used) { lccolumn = TAILQ_LAST(&lc->cells, layout_cells); layout_resize_adjust(lccolumn, LAYOUT_LEFTRIGHT, w->sx - used); @@ -474,17 +472,18 @@ } /* What width and height should they be? */ - width = w->sx / columns; - if (width < PANE_MINIMUM + 1) - width = PANE_MINIMUM + 1; - height = w->sy / rows; - if (width < PANE_MINIMUM + 1) - width = PANE_MINIMUM + 1; + width = (w->sx - (columns - 1)) / columns; + if (width < PANE_MINIMUM) + width = PANE_MINIMUM; + height = (w->sy - (rows - 1)) / rows; + if (height < PANE_MINIMUM) + height = PANE_MINIMUM; /* Free old tree and create a new root. */ layout_free(w); lc = w->layout_root = layout_create_cell(NULL); - layout_set_size(lc, width * columns, height * rows, 0, 0); + layout_set_size(lc, (width + 1) * columns - 1, + (height + 1) * rows - 1, 0, 0); layout_make_node(lc, LAYOUT_TOPBOTTOM); /* Create a grid of the cells. */ @@ -496,7 +495,7 @@ /* Create the new row. */ lcrow = layout_create_cell(lc); - layout_set_size(lcrow, w->sx, height - 1, 0, 0); + layout_set_size(lcrow, w->sx, height, 0, 0); TAILQ_INSERT_TAIL(&lc->cells, lcrow, entry); /* If only one column, just use the row directly. */ @@ -511,7 +510,7 @@ for (i = 0; i < columns; i++) { /* Create and add a pane cell. */ lcchild = layout_create_cell(lcrow); - layout_set_size(lcchild, width - 1, height - 1, 0, 0); + layout_set_size(lcchild, width, height, 0, 0); layout_make_leaf(lcchild, wp); TAILQ_INSERT_TAIL(&lcrow->cells, lcchild, entry); @@ -526,7 +525,7 @@ */ if (i == columns) i--; - used = ((i + 1) * width) - 1; + used = ((i + 1) * (width + 1)) - 1; if (w->sx <= used) continue; lcchild = TAILQ_LAST(&lcrow->cells, layout_cells); @@ -534,7 +533,7 @@ } /* Adjust the last row height to fit if necessary. */ - used = (rows * height) - 1; + 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);