=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/layout.c,v retrieving revision 1.27 retrieving revision 1.28 diff -c -r1.27 -r1.28 *** src/usr.bin/tmux/layout.c 2016/04/29 15:00:48 1.27 --- src/usr.bin/tmux/layout.c 2016/08/03 09:07:02 1.28 *************** *** 1,4 **** ! /* $OpenBSD: layout.c,v 1.27 2016/04/29 15:00:48 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: layout.c,v 1.28 2016/08/03 09:07:02 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott *************** *** 32,41 **** * cell a pointer to its parent cell. */ ! static int layout_resize_pane_grow(struct layout_cell *, enum layout_type, ! int); ! static int layout_resize_pane_shrink(struct layout_cell *, enum layout_type, int); static int layout_need_status(struct layout_cell *, int); struct layout_cell * --- 32,43 ---- * cell a pointer to its parent cell. */ ! static u_int layout_resize_check(struct window *, struct layout_cell *, ! enum layout_type); ! static int layout_resize_pane_grow(struct window *, struct layout_cell *, enum layout_type, int); + static int layout_resize_pane_shrink(struct window *, struct layout_cell *, + enum layout_type, int); static int layout_need_status(struct layout_cell *, int); struct layout_cell * *************** *** 282,314 **** } /* Calculate how much size is available to be removed from a cell. */ ! u_int ! layout_resize_check(struct layout_cell *lc, enum layout_type type) { struct layout_cell *lcchild; u_int available, minimum; if (lc->type == LAYOUT_WINDOWPANE) { /* Space available in this cell only. */ if (type == LAYOUT_LEFTRIGHT) available = lc->sx; ! else available = lc->sy; ! ! if (available > PANE_MINIMUM) ! available -= PANE_MINIMUM; else available = 0; } else if (lc->type == type) { /* Same type: total of available space in all child cells. */ available = 0; TAILQ_FOREACH(lcchild, &lc->cells, entry) ! available += layout_resize_check(lcchild, type); } else { /* Different type: minimum of available space in child cells. */ minimum = UINT_MAX; TAILQ_FOREACH(lcchild, &lc->cells, entry) { ! available = layout_resize_check(lcchild, type); if (available < minimum) minimum = available; } --- 284,321 ---- } /* Calculate how much size is available to be removed from a cell. */ ! static u_int ! layout_resize_check(struct window *w, struct layout_cell *lc, ! enum layout_type type) { struct layout_cell *lcchild; u_int available, minimum; if (lc->type == LAYOUT_WINDOWPANE) { /* Space available in this cell only. */ + minimum = PANE_MINIMUM; if (type == LAYOUT_LEFTRIGHT) available = lc->sx; ! else { available = lc->sy; ! minimum += layout_need_status(lc, ! options_get_number(w->options, ! "pane-border-status") == 1); ! } ! if (available > minimum) ! available -= minimum; else available = 0; } else if (lc->type == type) { /* Same type: total of available space in all child cells. */ available = 0; TAILQ_FOREACH(lcchild, &lc->cells, entry) ! available += layout_resize_check(w, lcchild, type); } else { /* Different type: minimum of available space in child cells. */ minimum = UINT_MAX; TAILQ_FOREACH(lcchild, &lc->cells, entry) { ! available = layout_resize_check(w, lcchild, type); if (available < minimum) minimum = available; } *************** *** 323,329 **** * expects the change to have already been bounded to the space available. */ void ! layout_resize_adjust(struct layout_cell *lc, enum layout_type type, int change) { struct layout_cell *lcchild; --- 330,337 ---- * expects the change to have already been bounded to the space available. */ void ! layout_resize_adjust(struct window *w, struct layout_cell *lc, ! enum layout_type type, int change) { struct layout_cell *lcchild; *************** *** 340,346 **** /* Child cell runs in a different direction. */ if (lc->type != type) { TAILQ_FOREACH(lcchild, &lc->cells, entry) ! layout_resize_adjust(lcchild, type, change); return; } --- 348,354 ---- /* Child cell runs in a different direction. */ if (lc->type != type) { TAILQ_FOREACH(lcchild, &lc->cells, entry) ! layout_resize_adjust(w, lcchild, type, change); return; } *************** *** 353,364 **** if (change == 0) break; if (change > 0) { ! layout_resize_adjust(lcchild, type, 1); change--; continue; } ! if (layout_resize_check(lcchild, type) > 0) { ! layout_resize_adjust(lcchild, type, -1); change++; } } --- 361,372 ---- if (change == 0) break; if (change > 0) { ! layout_resize_adjust(w, lcchild, type, 1); change--; continue; } ! if (layout_resize_check(w, lcchild, type) > 0) { ! layout_resize_adjust(w, lcchild, type, -1); change++; } } *************** *** 367,373 **** /* Destroy a cell and redistribute the space. */ void ! layout_destroy_cell(struct layout_cell *lc, struct layout_cell **lcroot) { struct layout_cell *lcother, *lcparent; --- 375,382 ---- /* Destroy a cell and redistribute the space. */ void ! layout_destroy_cell(struct window *w, struct layout_cell *lc, ! struct layout_cell **lcroot) { struct layout_cell *lcother, *lcparent; *************** *** 388,396 **** else lcother = TAILQ_PREV(lc, layout_cells, entry); if (lcparent->type == LAYOUT_LEFTRIGHT) ! layout_resize_adjust(lcother, lcparent->type, lc->sx + 1); else ! layout_resize_adjust(lcother, lcparent->type, lc->sy + 1); /* Remove this from the parent's list. */ TAILQ_REMOVE(&lcparent->cells, lc, entry); --- 397,405 ---- else lcother = TAILQ_PREV(lc, layout_cells, entry); if (lcparent->type == LAYOUT_LEFTRIGHT) ! layout_resize_adjust(w, lcother, lcparent->type, lc->sx + 1); else ! layout_resize_adjust(w, lcother, lcparent->type, lc->sy + 1); /* Remove this from the parent's list. */ TAILQ_REMOVE(&lcparent->cells, lc, entry); *************** *** 454,460 **** * window size. */ xchange = sx - w->sx; ! xlimit = layout_resize_check(lc, LAYOUT_LEFTRIGHT); if (xchange < 0 && xchange < -xlimit) xchange = -xlimit; if (xlimit == 0) { --- 463,469 ---- * window size. */ xchange = sx - w->sx; ! xlimit = layout_resize_check(w, lc, LAYOUT_LEFTRIGHT); if (xchange < 0 && xchange < -xlimit) xchange = -xlimit; if (xlimit == 0) { *************** *** 464,474 **** xchange = sx - lc->sx; } if (xchange != 0) ! layout_resize_adjust(lc, LAYOUT_LEFTRIGHT, xchange); /* Adjust vertically in a similar fashion. */ ychange = sy - w->sy; ! ylimit = layout_resize_check(lc, LAYOUT_TOPBOTTOM); if (ychange < 0 && ychange < -ylimit) ychange = -ylimit; if (ylimit == 0) { --- 473,483 ---- xchange = sx - lc->sx; } if (xchange != 0) ! layout_resize_adjust(w, lc, LAYOUT_LEFTRIGHT, xchange); /* Adjust vertically in a similar fashion. */ ychange = sy - w->sy; ! ylimit = layout_resize_check(w, lc, LAYOUT_TOPBOTTOM); if (ychange < 0 && ychange < -ylimit) ychange = -ylimit; if (ylimit == 0) { *************** *** 478,484 **** ychange = sy - lc->sy; } if (ychange != 0) ! layout_resize_adjust(lc, LAYOUT_TOPBOTTOM, ychange); /* Fix cell offsets. */ layout_fix_offsets(lc); --- 487,493 ---- ychange = sy - lc->sy; } if (ychange != 0) ! layout_resize_adjust(w, lc, LAYOUT_TOPBOTTOM, ychange); /* Fix cell offsets. */ layout_fix_offsets(lc); *************** *** 522,529 **** void layout_resize_pane(struct window_pane *wp, enum layout_type type, int change) { ! struct layout_cell *lc, *lcparent; ! int needed, size; lc = wp->layout_cell; --- 531,539 ---- void layout_resize_pane(struct window_pane *wp, enum layout_type type, int change) { ! struct window *w = wp->window; ! struct layout_cell *lc, *lcparent; ! int needed, size; lc = wp->layout_cell; *************** *** 544,553 **** needed = change; while (needed != 0) { if (change > 0) { ! size = layout_resize_pane_grow(lc, type, needed); needed -= size; } else { ! size = layout_resize_pane_shrink(lc, type, needed); needed += size; } --- 554,563 ---- needed = change; while (needed != 0) { if (change > 0) { ! size = layout_resize_pane_grow(w, lc, type, needed); needed -= size; } else { ! size = layout_resize_pane_shrink(w, lc, type, needed); needed += size; } *************** *** 563,570 **** /* Helper function to grow pane. */ static int ! layout_resize_pane_grow(struct layout_cell *lc, enum layout_type type, ! int needed) { struct layout_cell *lcadd, *lcremove; u_int size; --- 573,580 ---- /* Helper function to grow pane. */ static int ! layout_resize_pane_grow(struct window *w, struct layout_cell *lc, ! enum layout_type type, int needed) { struct layout_cell *lcadd, *lcremove; u_int size; *************** *** 575,581 **** /* Look towards the tail for a suitable cell for reduction. */ lcremove = TAILQ_NEXT(lc, entry); while (lcremove != NULL) { ! size = layout_resize_check(lcremove, type); if (size > 0) break; lcremove = TAILQ_NEXT(lcremove, entry); --- 585,591 ---- /* Look towards the tail for a suitable cell for reduction. */ lcremove = TAILQ_NEXT(lc, entry); while (lcremove != NULL) { ! size = layout_resize_check(w, lcremove, type); if (size > 0) break; lcremove = TAILQ_NEXT(lcremove, entry); *************** *** 585,591 **** if (lcremove == NULL) { lcremove = TAILQ_PREV(lc, layout_cells, entry); while (lcremove != NULL) { ! size = layout_resize_check(lcremove, type); if (size > 0) break; lcremove = TAILQ_PREV(lcremove, layout_cells, entry); --- 595,601 ---- if (lcremove == NULL) { lcremove = TAILQ_PREV(lc, layout_cells, entry); while (lcremove != NULL) { ! size = layout_resize_check(w, lcremove, type); if (size > 0) break; lcremove = TAILQ_PREV(lcremove, layout_cells, entry); *************** *** 597,611 **** /* Change the cells. */ if (size > (u_int) needed) size = needed; ! layout_resize_adjust(lcadd, type, size); ! layout_resize_adjust(lcremove, type, -size); return (size); } /* Helper function to shrink pane. */ static int ! layout_resize_pane_shrink(struct layout_cell *lc, enum layout_type type, ! int needed) { struct layout_cell *lcadd, *lcremove; u_int size; --- 607,621 ---- /* Change the cells. */ if (size > (u_int) needed) size = needed; ! layout_resize_adjust(w, lcadd, type, size); ! layout_resize_adjust(w, lcremove, type, -size); return (size); } /* Helper function to shrink pane. */ static int ! layout_resize_pane_shrink(struct window *w, struct layout_cell *lc, ! enum layout_type type, int needed) { struct layout_cell *lcadd, *lcremove; u_int size; *************** *** 613,619 **** /* Shrinking. Find cell to remove from by walking towards head. */ lcremove = lc; do { ! size = layout_resize_check(lcremove, type); if (size != 0) break; lcremove = TAILQ_PREV(lcremove, layout_cells, entry); --- 623,629 ---- /* Shrinking. Find cell to remove from by walking towards head. */ lcremove = lc; do { ! size = layout_resize_check(w, lcremove, type); if (size != 0) break; lcremove = TAILQ_PREV(lcremove, layout_cells, entry); *************** *** 629,636 **** /* Change the cells. */ if (size > (u_int) -needed) size = -needed; ! layout_resize_adjust(lcadd, type, size); ! layout_resize_adjust(lcremove, type, -size); return (size); } --- 639,646 ---- /* Change the cells. */ if (size > (u_int) -needed) size = -needed; ! layout_resize_adjust(w, lcadd, type, size); ! layout_resize_adjust(w, lcremove, type, -size); return (size); } *************** *** 769,781 **** void layout_close_pane(struct window_pane *wp) { /* Remove the cell. */ ! layout_destroy_cell(wp->layout_cell, &wp->window->layout_root); /* Fix pane offsets and sizes. */ ! if (wp->window->layout_root != NULL) { ! layout_fix_offsets(wp->window->layout_root); ! layout_fix_panes(wp->window, wp->window->sx, wp->window->sy); } ! notify_window_layout_changed(wp->window); } --- 779,793 ---- void layout_close_pane(struct window_pane *wp) { + struct window *w = wp->window; + /* Remove the cell. */ ! layout_destroy_cell(w, wp->layout_cell, &w->layout_root); /* Fix pane offsets and sizes. */ ! if (w->layout_root != NULL) { ! layout_fix_offsets(w->layout_root); ! layout_fix_panes(w, w->sx, w->sy); } ! notify_window_layout_changed(w); }