X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/%7B%7Bdeck_id%7D%7D/cards/%7B%7Bcard_id%7D%7D/static/git-logo.png?a=blobdiff_plain;f=windows.c;h=62faa489873e8ed42d1d50135c5fb55165dc7cf8;hb=74c8b64f280289572e4246f47c4d0a0e10fd1a45;hp=ef2e25fe4b5d310676a8e0ddb9e1193bedf5b542;hpb=cd5664da7685fccf97cd9027e3c193ebbf27a649;p=plomrogue diff --git a/windows.c b/windows.c index ef2e25f..62faa48 100644 --- a/windows.c +++ b/windows.c @@ -14,6 +14,7 @@ struct Corners { struct yx bl; struct yx br; }; +static void refit_pad (struct WinMeta *); static struct yx place_window (struct WinMeta *, struct Win *); static void update_windows (struct WinMeta *, struct Win *); static void destroy_window (struct Win *); @@ -59,6 +60,17 @@ extern void append_window (struct WinMeta * win_meta, struct Win * win) { win_meta->chain_end = win; update_windows(win_meta, win); } +static void refit_pad (struct WinMeta * win_meta) { +// Fit pad width to minimum width demanded by current windows' geometries. + uint16_t lastwincol = 0; + struct Win * win_p = win_meta->chain_start; + while (win_p != 0) { + if (win_p->startx + win_p->width > lastwincol + 1) + lastwincol = win_p->startx + win_p->width - 1; + win_p = win_p->next; } + if (getmaxx(win_meta->pad) != lastwincol) + wresize(win_meta->pad, getmaxy(win_meta->pad), lastwincol + 2); } + extern void suspend_window (struct WinMeta * win_meta, struct Win * win) { // Destroy win, suspend from chain. Update geometry of following rows and pad, as well as activity selection. destroy_window(win); @@ -79,15 +91,8 @@ extern void suspend_window (struct WinMeta * win_meta, struct Win * win) { win_meta->active = win->prev; } win->prev = 0; win->next = 0; - if (0 == pad_refitted) { // Refit pad if necessary. - uint16_t lastwincol = 0; - struct Win * win_p = win_meta->chain_start; - while (win_p != 0) { - if (getbegx(win_p->curses) + win_p->width > lastwincol + 1) - lastwincol = getbegx(win_p->curses) + win_p->width - 1; - win_p = win_p->next; } - if (getmaxx(win_meta->pad) != lastwincol) - wresize(win_meta->pad, getmaxy(win_meta->pad), lastwincol + 2); } } + if (0 == pad_refitted) // Refit pad if necessary. + refit_pad(win_meta); } static struct yx place_window (struct WinMeta * win_meta, struct Win * win) { // Based on position and sizes of previous window, find fitting place for current window. @@ -127,16 +132,8 @@ static void update_windows (struct WinMeta * win_meta, struct Win * win) { if (0 != win->curses) destroy_window (win); struct yx startyx = place_window(win_meta, win); - uint16_t lastwincol = 0; - struct Win * win_p = win_meta->chain_start; - while (win_p != 0) { - if (win_p != win && getbegx(win_p->curses) + win_p->width > lastwincol + 1) - lastwincol = getbegx(win_p->curses) + win_p->width - 1; - else if (win_p == win && startyx.x + win->width > lastwincol + 1) - lastwincol = startyx.x + win->width - 1; - win_p = win_p->next; } - if (getmaxx(win_meta->pad) != lastwincol) - wresize(win_meta->pad, getmaxy(win_meta->pad), lastwincol + 2); + win->startx = startyx.x; + refit_pad(win_meta); win->curses = subpad(win_meta->pad, win->height, win->width, startyx.y, startyx.x); if (0 != win->next) update_windows (win_meta, win->next); } @@ -264,13 +261,12 @@ extern void cycle_active_window (struct WinMeta * win_meta, char dir) { extern void shift_active_window (struct WinMeta * win_meta, char dir) { // Move active window forward/backward in window chain. If jumping beyond start/end, move to other chain end. if (0 != win_meta->active && win_meta->chain_start != win_meta->chain_end && (dir == 'f' || dir == 'b')) { - struct Win * win_shift = win_meta->active; + struct Win * win_shift = win_meta->active, * win_p, * win_p_next; char wrap = 0; if ((dir == 'f' && win_shift == win_meta->chain_end) || (dir == 'b' && win_shift == win_meta->chain_start)) wrap = 1; uint16_t i, i_max; - struct Win * win_p, * win_p_next; for (i_max = 1, win_p = win_meta->chain_start; win_p != win_meta->chain_end; i_max++) win_p = win_p->next; struct Win ** wins = malloc(i_max * sizeof(struct Win *));