- struct Win * first_ceiling = win->prev; // first_ceiling determines column with;
- while (first_ceiling->curses_win->_begy != 1) // default: place window in new column
- first_ceiling = first_ceiling->prev; // next to it
- start.x = first_ceiling->curses_win->_begx + first_ceiling->width + 1;
- if (first_ceiling->width >= win->width) { // only place wins in prev column that fit into its width
- struct Win * win_p = first_ceiling;
- struct Win * lastrow_startwin = win_p;
- while (win_p != win) {
- if (win_p->curses_win->_begx == first_ceiling->curses_win->_begx)
- lastrow_startwin = win_p; // try to fit window at the end of the last row of windows
- win_p = win_p ->next; } // inside column; if failure, try opening a new row below
- int lastcol_start = win->prev->curses_win->_begx + win->prev->width + 1;
- if (win->width <= first_ceiling->curses_win->_begx + first_ceiling->width - lastcol_start
- && win->height <= lastrow_startwin->height) {
- start.x = lastcol_start;
- start.y = lastrow_startwin->curses_win->_begy; }
- else if (win->height < win_meta->height - (lastrow_startwin->curses_win->_begy + lastrow_startwin->height)
- && win->width <= first_ceiling->width) {
- start.x = first_ceiling->curses_win->_begx;
- start.y = lastrow_startwin->curses_win->_begy + lastrow_startwin->height + 1; } } } }
+ struct Win * win_up = win->prev;
+ struct Win * win_upup = win_up;
+ int widthdiff;
+ while (win_up != win_top) {
+ win_upup = win_up->prev;
+ while (1) {
+ if (getbegy(win_up->curses) != getbegy(win_upup->curses))
+ break;
+ win_upup = win_upup->prev; }
+ winprev_maxy = getbegy(win_upup->curses) + getmaxy(win_upup->curses);
+ widthdiff = (getbegx(win_upup->curses) + win_upup->width) - (getbegx(win_up->curses) + win_up->width);
+ if (win->height < win_meta->height - winprev_maxy && win->width < widthdiff) {
+ start.x = getbegx(win_up->curses) + win_up->width + 1; // else try to open new sub column under last
+ start.y = winprev_maxy + 1; // window below which enough space remains
+ break; }
+ win_up = win_upup; } } }