- struct Win * first_ceiling = win->prev; // first_ceiling determines column with;
- while (first_ceiling->start_y != 0) // default: place window in new column
- first_ceiling = first_ceiling->prev; // next to it
- win->start_x = first_ceiling->start_x + first_ceiling->width;
- if (first_ceiling->width >= win->width) { // only place windows 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->start_x == first_ceiling->start_x)
- lastrow_startwin = win_p; // try to fit window at the end of the last
- win_p = win_p ->next; } // row of windows inside the column; if
- int lastcol_start = win->prev->start_x + win->prev->width; // that fails, try to open a new row below
- if (win->width <= first_ceiling->start_x + first_ceiling->width - lastcol_start
- && win->height <= lastrow_startwin->height) {
- win->start_x = lastcol_start;
- win->start_y = lastrow_startwin->start_y; }
- else if (win->height <= win_meta->height - (lastrow_startwin->start_y + lastrow_startwin->height)
- && win->width <= first_ceiling->width) {
- win->start_x = first_ceiling->start_x;
- win->start_y = lastrow_startwin->start_y + lastrow_startwin->height; } } } } }
-
-void update_windows (struct WinMeta * win_meta, struct Win * win) {
-// Update geometry of win and its next of kin. Before, destroy window, if visible. After, (re-)build it.
- if (0 != win->curses_win)
- destroy_window (win);
- place_window(win_meta, win);
- if (win->start_y + win->height < win_meta->height) // dependent on window position,
- win->border_down = 1; // append space for borders to be drawn
- else
- win->border_down = 0;
- if (win->start_x > 0)
- win->border_left = 1;
- else
- win->border_left = 0;
- win->curses_win = newwin(win->height + win->border_down, win->width + win->border_left, win->start_y, win->start_x - win->border_left);
- if (0 != win->next)
- update_windows (win_meta, win->next); }
-
-void destroy_window (struct Win * win) {
-// Undraw and delete window.
- undraw_window (win->curses_win);
- delwin(win->curses_win);
- win->curses_win = 0; }
-
-void draw_windows (struct WinMeta * win_meta, struct Win * win) {
-// Draw all windows from the current one on.
- draw_window(win_meta, win);
- if (0 != win->next)
- draw_windows (win_meta, win->next); }
-
-void draw_all_windows (struct WinMeta * win_meta) {
-// Draw all windows from the chain start on.
- if (win_meta->chain_start)
- draw_windows (win_meta, win_meta->chain_start); }
-
-void draw_window(struct WinMeta * win_meta, struct Win * win) {
-// Draw win's content, including border and title (the latter dependent on space available for it).
- char ls = '|';
- char rs = '|';
- char ts = '-';
- char bs = '-';
- char tl = '-';
- char tr = '+';
- char bl = '|';
- char br = '|';
- if (1 == win->border_down) {
- bl = '+';
- br = '+'; }
- if (1 == win->border_left)
- tl = '+';
- wborder(win->curses_win, ls, rs, ts, bs, tl, tr, bl, br);
- char min_title_length_visible = 3; // 1 char minimal, plus 2 chars for decoration left/right of title
- if (win->width > min_title_length_visible) {
- int title_length = strlen(win->title);
- int title_offset = (((win->width) - (title_length + 2)) / 2) + win->border_left; // + 2 is for decoration
- if (title_offset < win->border_left)
- title_offset = win->border_left;
- int length_visible = strnlen(win->title, win->width - min_title_length_visible);
+ struct Win * w_up = w->prev;
+ struct Win * w_upup = w_up;
+ uint16_t widthdiff;
+ while (w_up != w_top) {
+ w_upup = w_up->prev;
+ while (1) {
+ if (w_up->start.y != w_upup->start.y)
+ break;
+ w_upup = w_upup->prev; }
+ w_prev_maxy = w_upup->start.y + getmaxy(w_upup->frame.curses_win);
+ widthdiff = (w_upup->start.x + w_upup->frame.size.x) - (w_up->start.x + w_up->frame.size.x);
+ if (w->frame.size.y < win_meta->pad.size.y - w_prev_maxy && w->frame.size.x < widthdiff) {
+ w->start.x = w_up->start.x + w_up->frame.size.x + 1 ; // else try to open new sub column under
+ w->start.y = w_prev_maxy + 1; // last window below which enough space remains
+ break; }
+ w_up = w_upup; } } } }
+
+static void update_windows (struct WinMeta * wmeta, struct Win * w) {
+// Update geometry of win and its next of kin. Destroy (if visible), (re-)build window. If need, resize pad.
+ if (0 != w->frame.curses_win)
+ destroy_window (w);
+ place_window(wmeta, w);
+ refit_pad(wmeta);
+ w->frame.curses_win=subpad(wmeta->pad.curses_win, w->frame.size.y, w->frame.size.x, w->start.y, w->start.x);
+ if (0 != w->next)
+ update_windows (wmeta, w->next); }
+
+static void destroy_window (struct Win * win) {
+// Delete window.
+ delwin(win->frame.curses_win);
+ win->frame.curses_win = 0; }
+
+static void draw_win_borders (struct Win * win, char active) {
+// Draw borders of window win, including title. Decorate in a special way if window is marked as active.
+ uint16_t y, x;
+ for (y = win->start.y; y <= win->start.y + win->frame.size.y; y++) {
+ mvwaddch(wgetparent(win->frame.curses_win), y, win->start.x - 1, '|');
+ mvwaddch(wgetparent(win->frame.curses_win), y, win->start.x + win->frame.size.x, '|'); }
+ for (x = win->start.x; x <= win->start.x + win->frame.size.x; x++) {
+ mvwaddch(wgetparent(win->frame.curses_win), win->start.y - 1, x, '-');
+ mvwaddch(wgetparent(win->frame.curses_win), win->start.y + win->frame.size.y, x, '-'); }
+ char min_title_length_visible = 3; // 1 char minimal, plus 2 chars for decoration left/right of title
+ if (win->frame.size.x >= min_title_length_visible) {
+ uint16_t title_offset = 0;
+ if (win->frame.size.x > strlen(win->title) + 2)
+ title_offset = (win->frame.size.x - (strlen(win->title) + 2)) / 2; // + 2 is for decoration
+ uint16_t length_visible = strnlen(win->title, win->frame.size.x - 2);