- struct Win * first_ceiling = win->prev; // first_ceiling determines column with;
- while (getbegy(first_ceiling->curses_win) != 1) // default: place window in new column
- first_ceiling = first_ceiling->prev; // next to it
- start.x = getbegx(first_ceiling->curses_win) + 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 (getbegx(win_p->curses_win) == getbegx(first_ceiling->curses_win))
- 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 = getbegx(win->prev->curses_win) + win->prev->width + 1;
- if (win->width <= getbegx(first_ceiling->curses_win) + first_ceiling->width - lastcol_start
- && win->height <= lastrow_startwin->height) {
- start.x = lastcol_start;
- start.y = getbegy(lastrow_startwin->curses_win); }
- else if (win->height < win_meta->height - (getbegy(lastrow_startwin->curses_win) + lastrow_startwin->height)
- && win->width <= first_ceiling->width) {
- start.x = getbegx(first_ceiling->curses_win);
- start.y = getbegy(lastrow_startwin->curses_win) + lastrow_startwin->height + 1; } } } }
- return start; }
-
-void update_windows (struct WinMeta * win_meta, struct Win * win) {
+ struct Win * win_up = win->prev;
+ struct Win * win_upup = win_up;
+ uint16_t widthdiff;
+ while (win_up != win_top) {
+ win_upup = win_up->prev;
+ while (1) {
+ if (win_up->start.y != win_upup->start.y)
+ break;
+ win_upup = win_upup->prev; }
+ winprev_maxy = win_upup->start.y + getmaxy(win_upup->curses);
+ widthdiff = (win_upup->start.x + win_upup->width) - (win_up->start.x + win_up->width);
+ if (win->height < win_meta->height - winprev_maxy && win->width < widthdiff) {
+ win->start.x = win_up->start.x + win_up->width + 1; // else try to open new sub column under last
+ win->start.y = winprev_maxy + 1; // window below which enough space remains
+ break; }
+ win_up = win_upup; } } } }
+
+static void update_windows (struct WinMeta * win_meta, struct Win * win) {