ref: 10bcc7adcfd5e0e980bb156de8a38fe5a6484a33
parent: 6b8f9267ec3a0b62a6a1d2e112f508de61c25900
author: cancel <cancel@cancel.fm>
date: Mon Jan 6 00:53:16 EST 2020
Fix dialogs and menus when terminal is resized big->small->big Used regular curses newwin WINDOWs before. Now uses newpad/subpad. The buffers will be clipped correctly to the visible terminal area, and will not be erased when the window is made too small and then resized to be big again.
--- a/term_util.c
+++ b/term_util.c
@@ -142,8 +142,13 @@
}
qnav_stack.blocks[qnav_stack.count] = qb;
++qnav_stack.count;
- qb->outer_window = newwin(total_h, total_w, top, left);
- qb->content_window = derwin(qb->outer_window, height, width, 1, 1);
+ qb->outer_window = newpad(total_h, total_w);
+ // This used to be derwin when when used newwin instead of newpad -- not sure
+ // if we should use derwin or subpad now. subpad is probably more compatible.
+ // ncurses docs state that it handles it correctly, unlike some others?
+ qb->content_window = subpad(qb->outer_window, height, width, 1, 1);
+ qb->y = top;
+ qb->x = left;
qnav_stack.stack_changed = true;
}
--- a/term_util.h
+++ b/term_util.h
@@ -64,6 +64,7 @@
WINDOW* outer_window;
WINDOW* content_window;
char const* title;
+ int y, x;
} Qblock;
typedef struct {
--- a/tui_main.c
+++ b/tui_main.c
@@ -2668,6 +2668,9 @@
wnoutrefresh(cont_window);
drew_any = true;
}
+ int term_h, term_w;
+ if (qnav_stack.count > 0) // todo lame, move this
+ getmaxyx(stdscr, term_h, term_w);
for (Usz i = 0; i < qnav_stack.count; ++i) {
Qblock* qb = qnav_stack.blocks[i];
if (qnav_stack.stack_changed) {
@@ -2684,8 +2687,21 @@
break;
}
}
- touchwin(qb->outer_window);
- wnoutrefresh(qb->outer_window);
+ touchwin(qb->outer_window); // here? or after continue?
+ if (term_h < 1 || term_w < 1)
+ continue;
+ int qbwin_h, qbwin_w;
+ getmaxyx(qb->outer_window, qbwin_h, qbwin_w);
+ int qbwin_endy = qb->y + qbwin_h;
+ int qbwin_endx = qb->x + qbwin_w;
+ if (qbwin_endy >= term_h)
+ qbwin_endy = term_h - 1;
+ if (qbwin_endx >= term_w)
+ qbwin_endx = term_w - 1;
+ if (qb->y >= qbwin_endy || qb->x >= qbwin_endx)
+ continue;
+ pnoutrefresh(qb->outer_window, 0, 0, qb->y, qb->x, qbwin_endy,
+ qbwin_endx);
drew_any = true;
}
qnav_stack.stack_changed = false;