AUTO RESIZING NOW WORKS WELL
This commit is contained in:
parent
6cc80f32a3
commit
2ad6e4e104
3 changed files with 29 additions and 54 deletions
33
cli/tree.c
33
cli/tree.c
|
|
@ -3,6 +3,7 @@
|
|||
#include <string.h>
|
||||
|
||||
#include "curse.h"
|
||||
#include "ncurses.h"
|
||||
#include "tree.h"
|
||||
|
||||
/* Internal allocator method for crs_node structures.
|
||||
|
|
@ -152,14 +153,19 @@ static int bifurcate_dims(const struct crs_nodedims *const parent_dims,
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* NOTE: resize_node calls wnoutrefresh(3x), which expects
|
||||
* NOTE: a call doupdate(3x) call afterwards to flush ncurses
|
||||
* NOTE: virtual screen to the physical screen.
|
||||
*/
|
||||
static void resize_node(struct crs_node *const node,
|
||||
struct crs_nodedims *const new_dims) {
|
||||
if (node->type == NODE_WINDOW) {
|
||||
/* Window Node */
|
||||
resizemv_window(new_dims->x, new_dims->y, new_dims->width, new_dims->height,
|
||||
node->win);
|
||||
wrefresh(node->win);
|
||||
free(new_dims);
|
||||
|
||||
wnoutrefresh(node->win);
|
||||
} else {
|
||||
/* Abstract Node */
|
||||
assert(node->type == NODE_ABSTRACT);
|
||||
|
|
@ -256,17 +262,26 @@ void resize_tree(struct crs_tree *const tree, struct crs_nodedims *const dims) {
|
|||
}
|
||||
|
||||
void ct_update(struct crs_tree *const tree) {
|
||||
struct crs_nodedims *term_dims;
|
||||
struct crs_nodedims * term_dims;
|
||||
int term_width, term_height;
|
||||
const int key = wgetch(curscr);
|
||||
|
||||
int term_width, term_height, win_width, win_height;
|
||||
termsize(term_width, term_height);
|
||||
nodesize(tree->root, &win_width, &win_height);
|
||||
/* Check if window size has changed, I assume ncurses already binds
|
||||
* a SIGWINCH handler so we can do this instead (TODO: sighandler?) */
|
||||
if (win_width != term_width || win_height != term_height) {
|
||||
/* ncurses binds a SIGWINCH handler if SIGWINCH has SIG_DFL disposition
|
||||
* when initscr(3x) is called. This handler emits KEY_RESIZE (decimal 410) to stdin.
|
||||
* REF: manpages -> resizeterm(3x) initscr(3x) wgetch(3x)
|
||||
*/
|
||||
switch (key) {
|
||||
case -1:
|
||||
return;
|
||||
case KEY_RESIZE:
|
||||
termsize(term_width, term_height);
|
||||
term_dims = __alloc_dims(0, 0, term_width, term_height);
|
||||
resize_tree(tree, term_dims);
|
||||
// flush ncurses virtual screen -> physical screen
|
||||
doupdate();
|
||||
/* TODO: why the fuck does this line make everything work?? */
|
||||
wrefresh(tree->root->child[0]->win);
|
||||
// printf("hola\n");
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue