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 === */