From fa97c73522fa3b3c87cf175000f25350fee4d0f0 Mon Sep 17 00:00:00 2001 From: Emile Clark-Boman Date: Sun, 14 Sep 2025 00:13:55 +1000 Subject: [PATCH] add NFLAGS to ct_node NFLAGS will be used to avoid unnecessary CPU usage for events like resizing windows, a bitflag will be instead set to notify cursetree at the end of each ct_update --- cursetree/node.c | 16 +++++++++++++--- cursetree/node.h | 6 ++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/cursetree/node.c b/cursetree/node.c index f7d786a..4251afd 100644 --- a/cursetree/node.c +++ b/cursetree/node.c @@ -13,14 +13,21 @@ static inline struct ct_node *__alloc_node(void) { } /* Returns NULL if memory allocation failed. + * TODO: should dims be given as a parameter, or lazily computed in ct_update? */ struct ct_node *new_node(struct ct_dims *const dims, struct ct_bounds *const bounds, struct ct_node *const parent) { struct ct_node *node = __alloc_node(); - if (node == NULL) { + if (node != NULL) { *node = (struct ct_node){ - .surface = new_surface(dims, bounds), + /* copy the parent's dimensions for now and request + * cursetree resize this node appropriately afterwards + * WARNING: new_node doesn't set the NFLAG_RESIZE request flag + * WARNING: that should be done by a function calling new_node + */ + .surface = new_surface(parent->surface->dims, bounds), + .flags = NFLAG_EMPTY, .parent = parent, .child = (struct ct_node **)malloc(NODE_INIT_CHILDREN * @@ -28,7 +35,6 @@ struct ct_node *new_node(struct ct_dims *const dims, .csize = NODE_INIT_CHILDREN, .cindex = 0, .axis = AXIS_X, - .ratio = 0, }; } @@ -151,6 +157,8 @@ int insert_child_node(struct ct_node *const parent, struct ct_node *const child, // do insertion parent->child[i] = child; parent->cindex++; + // request cursetree recompute dimensions recursively from parent + parent->flags |= NFLAG_RESIZE; return EXIT_SUCCESS; } @@ -191,6 +199,8 @@ struct ct_node *remove_child_node(struct ct_node *const parent, } parent->cindex--; __set_cbounds(parent, child, false); + // request cursetree recompute dimensions recursively from parent + parent->flags |= NFLAG_RESIZE; return child; } diff --git a/cursetree/node.h b/cursetree/node.h index 9f713e7..b9917fc 100644 --- a/cursetree/node.h +++ b/cursetree/node.h @@ -13,11 +13,15 @@ typedef struct _win_st WINDOW; #define NODE_CHILDREN_GROWTH 1.5 #define CINDEX_MAX UCHAR_MAX +#define NFLAG_EMPTY (0) +#define NFLAG_RESIZE (1<<0) + /* Child Index */ typedef unsigned char cindex; struct ct_node { struct ct_surface *surface; + unsigned char flags; struct ct_node *parent; enum ct_axis axis; @@ -30,8 +34,6 @@ struct ct_node { int wmin_rel; int hmin_rel; } cbounds; - - float ratio; }; /* === External Interface === */