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
This commit is contained in:
Emile Clark-Boman 2025-09-14 00:13:55 +10:00
parent 759920a9cc
commit fa97c73522
2 changed files with 17 additions and 5 deletions

View file

@ -13,14 +13,21 @@ static inline struct ct_node *__alloc_node(void) {
} }
/* Returns NULL if memory allocation failed. /* 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_node *new_node(struct ct_dims *const dims,
struct ct_bounds *const bounds, struct ct_bounds *const bounds,
struct ct_node *const parent) { struct ct_node *const parent) {
struct ct_node *node = __alloc_node(); struct ct_node *node = __alloc_node();
if (node == NULL) { if (node != NULL) {
*node = (struct ct_node){ *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, .parent = parent,
.child = (struct ct_node **)malloc(NODE_INIT_CHILDREN * .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, .csize = NODE_INIT_CHILDREN,
.cindex = 0, .cindex = 0,
.axis = AXIS_X, .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 // do insertion
parent->child[i] = child; parent->child[i] = child;
parent->cindex++; parent->cindex++;
// request cursetree recompute dimensions recursively from parent
parent->flags |= NFLAG_RESIZE;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
@ -191,6 +199,8 @@ struct ct_node *remove_child_node(struct ct_node *const parent,
} }
parent->cindex--; parent->cindex--;
__set_cbounds(parent, child, false); __set_cbounds(parent, child, false);
// request cursetree recompute dimensions recursively from parent
parent->flags |= NFLAG_RESIZE;
return child; return child;
} }

View file

@ -13,11 +13,15 @@ typedef struct _win_st WINDOW;
#define NODE_CHILDREN_GROWTH 1.5 #define NODE_CHILDREN_GROWTH 1.5
#define CINDEX_MAX UCHAR_MAX #define CINDEX_MAX UCHAR_MAX
#define NFLAG_EMPTY (0)
#define NFLAG_RESIZE (1<<0)
/* Child Index */ /* Child Index */
typedef unsigned char cindex; typedef unsigned char cindex;
struct ct_node { struct ct_node {
struct ct_surface *surface; struct ct_surface *surface;
unsigned char flags;
struct ct_node *parent; struct ct_node *parent;
enum ct_axis axis; enum ct_axis axis;
@ -30,8 +34,6 @@ struct ct_node {
int wmin_rel; int wmin_rel;
int hmin_rel; int hmin_rel;
} cbounds; } cbounds;
float ratio;
}; };
/* === External Interface === */ /* === External Interface === */