AUTO RESIZING NOW WORKS WELL
This commit is contained in:
parent
6cc80f32a3
commit
2ad6e4e104
3 changed files with 29 additions and 54 deletions
32
cli/curse.c
32
cli/curse.c
|
|
@ -43,6 +43,7 @@ void init_ncurses(void) {
|
||||||
|
|
||||||
/* NCurses Init */
|
/* NCurses Init */
|
||||||
initscr();
|
initscr();
|
||||||
|
/* WARNING: no you shouldn't delwin(stdscr) it breaks everything... */
|
||||||
__conf_window(stdscr);
|
__conf_window(stdscr);
|
||||||
start_color();
|
start_color();
|
||||||
|
|
||||||
|
|
@ -81,34 +82,3 @@ int resizemv_window(const int x, const int y, const int width, const int height,
|
||||||
WINDOW *const win) {
|
WINDOW *const win) {
|
||||||
return wresize(win, height, width) || mvwin(win, y, x);
|
return wresize(win, height, width) || mvwin(win, y, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
int main(const int argc, const char *const argv[]) {
|
|
||||||
init_ncurses();
|
|
||||||
WINDOW *stdscr = new_window(0, 0, 0, 0);
|
|
||||||
|
|
||||||
// Set background
|
|
||||||
wbkgd(stdscr, COLOR_PAIR(1));
|
|
||||||
|
|
||||||
attron(COLOR_PAIR(1));
|
|
||||||
attron(A_BOLD);
|
|
||||||
int counter = 0;
|
|
||||||
while (1) {
|
|
||||||
mvprintw(0, 0, "COUNTER %d", counter++);
|
|
||||||
refresh();
|
|
||||||
|
|
||||||
switch (getch()) {
|
|
||||||
case 'q':
|
|
||||||
goto end;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
usleep(BASE_DELAY);
|
|
||||||
}
|
|
||||||
|
|
||||||
end:
|
|
||||||
endwin();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
|
||||||
18
cli/main.c
18
cli/main.c
|
|
@ -4,20 +4,8 @@
|
||||||
|
|
||||||
#include <ncursesw/ncurses.h>
|
#include <ncursesw/ncurses.h>
|
||||||
|
|
||||||
// #include "child.h"
|
|
||||||
#include "curse.h"
|
|
||||||
#include "tree.h"
|
#include "tree.h"
|
||||||
|
|
||||||
// struct d_window {
|
|
||||||
// int ptmx; // fd
|
|
||||||
// };
|
|
||||||
|
|
||||||
// struct d_window new_window() {
|
|
||||||
// struct d_window w = {
|
|
||||||
// .ptmx = posix_openpt(O_RDWR | O_NOCTTY),
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
// struct d_child child;
|
// struct d_child child;
|
||||||
// spawnchild(&child);
|
// spawnchild(&child);
|
||||||
|
|
@ -34,10 +22,12 @@ int main(int argc, char **argv) {
|
||||||
wrefresh(tree->root->child[0]->win);
|
wrefresh(tree->root->child[0]->win);
|
||||||
wrefresh(tree->root->child[1]->win);
|
wrefresh(tree->root->child[1]->win);
|
||||||
|
|
||||||
|
// wbkgd(tree->root->win, COLOR_PAIR(1));
|
||||||
|
// wrefresh(tree->root->win);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
ct_update(tree);
|
ct_update(tree);
|
||||||
// refresh();
|
usleep(100000);
|
||||||
// usleep(100000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
destroy_tree(tree);
|
destroy_tree(tree);
|
||||||
|
|
|
||||||
33
cli/tree.c
33
cli/tree.c
|
|
@ -3,6 +3,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "curse.h"
|
#include "curse.h"
|
||||||
|
#include "ncurses.h"
|
||||||
#include "tree.h"
|
#include "tree.h"
|
||||||
|
|
||||||
/* Internal allocator method for crs_node structures.
|
/* Internal allocator method for crs_node structures.
|
||||||
|
|
@ -152,14 +153,19 @@ static int bifurcate_dims(const struct crs_nodedims *const parent_dims,
|
||||||
return 0;
|
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,
|
static void resize_node(struct crs_node *const node,
|
||||||
struct crs_nodedims *const new_dims) {
|
struct crs_nodedims *const new_dims) {
|
||||||
if (node->type == NODE_WINDOW) {
|
if (node->type == NODE_WINDOW) {
|
||||||
/* Window Node */
|
/* Window Node */
|
||||||
resizemv_window(new_dims->x, new_dims->y, new_dims->width, new_dims->height,
|
resizemv_window(new_dims->x, new_dims->y, new_dims->width, new_dims->height,
|
||||||
node->win);
|
node->win);
|
||||||
wrefresh(node->win);
|
|
||||||
free(new_dims);
|
free(new_dims);
|
||||||
|
|
||||||
|
wnoutrefresh(node->win);
|
||||||
} else {
|
} else {
|
||||||
/* Abstract Node */
|
/* Abstract Node */
|
||||||
assert(node->type == NODE_ABSTRACT);
|
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) {
|
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;
|
/* ncurses binds a SIGWINCH handler if SIGWINCH has SIG_DFL disposition
|
||||||
termsize(term_width, term_height);
|
* when initscr(3x) is called. This handler emits KEY_RESIZE (decimal 410) to stdin.
|
||||||
nodesize(tree->root, &win_width, &win_height);
|
* REF: manpages -> resizeterm(3x) initscr(3x) wgetch(3x)
|
||||||
/* Check if window size has changed, I assume ncurses already binds
|
*/
|
||||||
* a SIGWINCH handler so we can do this instead (TODO: sighandler?) */
|
switch (key) {
|
||||||
if (win_width != term_width || win_height != term_height) {
|
case -1:
|
||||||
|
return;
|
||||||
|
case KEY_RESIZE:
|
||||||
|
termsize(term_width, term_height);
|
||||||
term_dims = __alloc_dims(0, 0, term_width, term_height);
|
term_dims = __alloc_dims(0, 0, term_width, term_height);
|
||||||
resize_tree(tree, term_dims);
|
resize_tree(tree, term_dims);
|
||||||
|
// flush ncurses virtual screen -> physical screen
|
||||||
|
doupdate();
|
||||||
/* TODO: why the fuck does this line make everything work?? */
|
/* 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