bug fixes + general X axis splitting!

This commit is contained in:
Emile Clark-Boman 2025-09-16 21:30:14 +10:00
parent 5e99b09f8a
commit dce97e6b3e
6 changed files with 69 additions and 33 deletions

View file

@ -1,9 +1,9 @@
#include <stdlib.h>
#include "_ncurses.h"
#include "ncrswrap.h"
#include "node.h"
#include "tree.h"
#include "_ncurses.h"
int ct_init(struct ct_tree **const tree) {
/* Initialise NCurses Library & Root Node */
@ -13,44 +13,63 @@ int ct_init(struct ct_tree **const tree) {
return EXIT_SUCCESS;
}
void ct_redraw(void) {
/* TODO: hide doupdate() behind some other method */
/* flush ncurses virtual screen -> physical screen */
doupdate();
}
/* Recursively search the tree for update requests.
* Returns:
* 0 - success (no action required)
* 1 - success (request: redraw the screen)
*/
static void __update_rec(struct ct_node *const node) {
static int __update_rec(struct ct_node *const node) {
int result = 0;
struct ct_dims *dims;
if (node->flags & NFLAG_RESIZE) {
/* TODO: the child has requested a resizing, but resize_node()
* TODO: wastes CPU time resizing itself!
*/
resize_node(node, dup_dims(node->surface->dims));
dims = IS_ROOT_NODE(node) ? termdims() : dup_dims(node->surface->dims);
resize_node(node, dims);
result = 1;
}
for (int i=0; i < node->cindex; i++) {
__update_rec(node->child[i]);
if (node->surface->updatereq) {
sfflush(node->surface);
}
for (int i = 0; i < node->cindex; i++) {
result |= __update_rec(node->child[i]);
}
return result;
}
void ct_update(struct ct_tree *const tree) {
const int key = wgetch(curscr);
/* 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)
* 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:
wclear(tree->root->surface->win);
mvwprintw(tree->root->surface->win, 0, 0, " \r-1\n");
wrefresh(tree->root->surface->win);
// wclear(tree->root->surface->win);
// mvwprintw(tree->root->surface->win, 0, 0, " \r-1\n");
// wrefresh(tree->root->surface->win);
return;
case KEY_RESIZE:
resize_tree(tree, termdims());
// flush ncurses virtual screen -> physical screen
doupdate();
tree->root->flags |= NFLAG_RESIZE;
break;
default:
// wclear(tree->root->surface->win);
mvwprintw(tree->root->surface->win, 0, 0, " \r%d\n", key);
wrefresh(tree->root->surface->win);
// mvwprintw(tree->root->surface->win, 0, 0, " \r%d\n", key);
// wrefresh(tree->root->surface->win);
break;
}
__update_rec(tree->root);
if (__update_rec(tree->root)) {
ct_redraw();
}
}