(UNDER CONSTRUCTION) fixed bad free + testing AXIS_X bifurcation
This commit is contained in:
parent
b16590fd5a
commit
5e99b09f8a
7 changed files with 92 additions and 46 deletions
33
cli/main.c
33
cli/main.c
|
|
@ -10,15 +10,34 @@ int main(int argc, char **argv) {
|
||||||
struct ct_tree *tree;
|
struct ct_tree *tree;
|
||||||
ct_init(&tree);
|
ct_init(&tree);
|
||||||
|
|
||||||
init_pair(1, COLOR_CYAN, COLOR_CYAN);
|
init_pair(1, COLOR_BLACK, COLOR_CYAN);
|
||||||
init_pair(2, COLOR_RED, COLOR_RED);
|
init_pair(2, COLOR_BLACK, COLOR_RED);
|
||||||
|
|
||||||
// wbkgd(tree->root->win, COLOR_PAIR(1));
|
// wbkgd(tree->root->surface->win, COLOR_PAIR(1));
|
||||||
// wrefresh(tree->root->win);
|
// wrefresh(tree->root->surface->win);
|
||||||
|
|
||||||
int i = 1;
|
struct ct_node *const child1 = new_node(bounds_none(), tree->root);
|
||||||
while (1) {
|
struct ct_node *const child2 = new_node(bounds_none(), tree->root);
|
||||||
|
append_child_node(tree->root, child1);
|
||||||
|
append_child_node(tree->root, child2);
|
||||||
|
|
||||||
|
wbkgd(child1->surface->win, COLOR_PAIR(1));
|
||||||
|
wbkgd(child2->surface->win, COLOR_PAIR(2));
|
||||||
|
|
||||||
|
// wrefresh(child1->surface->win);
|
||||||
|
|
||||||
|
mvwprintw(child2->surface->win, 0, 0, "1@(%d,%d) %dx%d\n",
|
||||||
|
child1->surface->dims->x, child1->surface->dims->y,
|
||||||
|
child1->surface->dims->width, child1->surface->dims->height);
|
||||||
|
mvwprintw(child2->surface->win, 1, 0, "2@(%d,%d) %dx%d\n",
|
||||||
|
child2->surface->dims->x, child2->surface->dims->y,
|
||||||
|
child2->surface->dims->width, child2->surface->dims->height);
|
||||||
|
wrefresh(child2->surface->win);
|
||||||
|
|
||||||
|
|
||||||
|
while (1) {
|
||||||
ct_update(tree);
|
ct_update(tree);
|
||||||
|
napms(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
destroy_tree(tree);
|
destroy_tree(tree);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "ncrswrap.h"
|
#include "ncrswrap.h"
|
||||||
|
#include "node.h"
|
||||||
#include "tree.h"
|
#include "tree.h"
|
||||||
#include "_ncurses.h"
|
#include "_ncurses.h"
|
||||||
|
|
||||||
|
|
@ -12,6 +13,19 @@ int ct_init(struct ct_tree **const tree) {
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Recursively search the tree for update requests.
|
||||||
|
*/
|
||||||
|
static void __update_rec(struct ct_node *const node) {
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
for (int i=0; i < node->cindex; i++) {
|
||||||
|
__update_rec(node->child[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ct_update(struct ct_tree *const tree) {
|
void ct_update(struct ct_tree *const tree) {
|
||||||
const int key = wgetch(curscr);
|
const int key = wgetch(curscr);
|
||||||
|
|
@ -32,9 +46,11 @@ void ct_update(struct ct_tree *const tree) {
|
||||||
doupdate();
|
doupdate();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
wclear(tree->root->surface->win);
|
// wclear(tree->root->surface->win);
|
||||||
mvwprintw(tree->root->surface->win, 0, 0, " \r%d\n", key);
|
mvwprintw(tree->root->surface->win, 0, 0, " \r%d\n", key);
|
||||||
wrefresh(tree->root->surface->win);
|
wrefresh(tree->root->surface->win);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__update_rec(tree->root);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "dims.h"
|
#include "dims.h"
|
||||||
|
#include "node.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
struct ct_dims *new_dims(const int x, const int y, const int width, const int height) {
|
struct ct_dims *new_dims(const int x, const int y, const int width, const int height) {
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#define __BOUND_UNLIMITED (-1)
|
#define __BOUND_UNLIMITED (-1)
|
||||||
#define __BOUND_ABS_MIN (1)
|
#define __BOUND_ABS_MIN (1)
|
||||||
#define __BOUND_ABS_MAX (INT_MAX)
|
#define __BOUND_ABS_MAX (INT_MAX / CINDEX_MAX - 1)
|
||||||
#define __BOUND_REL_MIN ((float)0)
|
#define __BOUND_REL_MIN ((float)0)
|
||||||
#define __BOUND_REL_MAX ((float)1)
|
#define __BOUND_REL_MAX ((float)1)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,15 +29,6 @@ WINDOW *new_window(const int x, const int y, const int width, const int height);
|
||||||
WINDOW *new_window_fs(void);
|
WINDOW *new_window_fs(void);
|
||||||
void destroy_window(WINDOW *);
|
void destroy_window(WINDOW *);
|
||||||
|
|
||||||
// #define winpos(win, x, y) (x = winposx(win), y = winposy(win))
|
|
||||||
// #define winsize(win, width, height) \
|
|
||||||
// (width = winwidth(win), height = winheight(win))
|
|
||||||
// int winposx(WINDOW *const);
|
|
||||||
// int winposy(WINDOW *const);
|
|
||||||
// int winwidth(WINDOW *const);
|
|
||||||
// int winheight(WINDOW *const);
|
|
||||||
// struct ct_dims *windims(WINDOW *win);
|
|
||||||
|
|
||||||
int resizemv_window(WINDOW *const win, const int x, const int y,
|
int resizemv_window(WINDOW *const win, const int x, const int y,
|
||||||
const int width, const int height);
|
const int width, const int height);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ struct ct_node *new_node(struct ct_bounds *const bounds,
|
||||||
* WARNING: new_node doesn't set the NFLAG_RESIZE request flag
|
* WARNING: new_node doesn't set the NFLAG_RESIZE request flag
|
||||||
* WARNING: that should be done by a function calling new_node
|
* WARNING: that should be done by a function calling new_node
|
||||||
*/
|
*/
|
||||||
return __node(parent->surface->dims, bounds, parent);
|
return __node(dup_dims(parent->surface->dims), bounds, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* WARNING: Do NOT use __destroy_node() to destroy a node's children!
|
/* WARNING: Do NOT use __destroy_node() to destroy a node's children!
|
||||||
|
|
@ -76,8 +76,9 @@ struct ct_spdims {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*/
|
*/
|
||||||
int resize_node(struct ct_node *const node, struct ct_dims *const dims) {
|
int resize_node(struct ct_node *const node, struct ct_dims *dims) {
|
||||||
resize_surface(node->surface, dims);
|
resize_surface(node->surface, dims);
|
||||||
|
dims = node->surface->dims;
|
||||||
|
|
||||||
if (node->surface->bounds->wmin > dims->width ||
|
if (node->surface->bounds->wmin > dims->width ||
|
||||||
node->surface->bounds->hmin > dims->height) {
|
node->surface->bounds->hmin > dims->height) {
|
||||||
|
|
@ -101,36 +102,43 @@ int resize_node(struct ct_node *const node, struct ct_dims *const dims) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int axm_size, axm_free;
|
int axm_size, axm_free;
|
||||||
size_t bounds_axm_min_offset, bounds_axm_max_offset;
|
/* DEBUG: WARNING :DEBUG */
|
||||||
size_t dims_axm_pos_offset, dims_axm_size_offset;
|
// size_t bounds_axm_min_offset, bounds_axm_max_offset;
|
||||||
|
// size_t dims_axm_pos_offset, dims_axm_size_offset;
|
||||||
|
|
||||||
if (node->axis == AXIS_X) {
|
if (node->axis == AXIS_X) {
|
||||||
axm_free = dims->width;
|
axm_free = dims->width;
|
||||||
axm_size = dims->width;
|
axm_size = dims->width;
|
||||||
|
|
||||||
dims_axm_pos_offset = offsetof(struct ct_dims, x);
|
/* DEBUG: WARNING :DEBUG */
|
||||||
dims_axm_size_offset = offsetof(struct ct_dims, width);
|
// dims_axm_pos_offset = offsetof(struct ct_dims, x);
|
||||||
bounds_axm_min_offset = offsetof(struct ct_bounds, wmin);
|
// dims_axm_size_offset = offsetof(struct ct_dims, width);
|
||||||
bounds_axm_max_offset = offsetof(struct ct_bounds, wmax);
|
// bounds_axm_min_offset = offsetof(struct ct_bounds, wmin);
|
||||||
|
// bounds_axm_max_offset = offsetof(struct ct_bounds, wmax);
|
||||||
} else {
|
} else {
|
||||||
assert(node->axis == AXIS_Y);
|
assert(node->axis == AXIS_Y);
|
||||||
axm_free = dims->height;
|
axm_free = dims->height;
|
||||||
axm_size = dims->height;
|
axm_size = dims->height;
|
||||||
|
|
||||||
dims_axm_pos_offset = offsetof(struct ct_dims, y);
|
/* DEBUG: WARNING :DEBUG */
|
||||||
dims_axm_size_offset = offsetof(struct ct_dims, height);
|
// dims_axm_pos_offset = offsetof(struct ct_dims, y);
|
||||||
bounds_axm_min_offset = offsetof(struct ct_bounds, hmin);
|
// dims_axm_size_offset = offsetof(struct ct_dims, height);
|
||||||
bounds_axm_max_offset = offsetof(struct ct_bounds, hmax);
|
// bounds_axm_min_offset = offsetof(struct ct_bounds, hmin);
|
||||||
|
// bounds_axm_max_offset = offsetof(struct ct_bounds, hmax);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ct_spdims cspdims[node->cindex];
|
struct ct_spdims cspdims[node->cindex];
|
||||||
cindex parts_n = node->cindex;
|
cindex parts_n = node->cindex;
|
||||||
memset(cspdims, 0, sizeof(struct ct_spdims) * node->cindex);
|
memset(cspdims, 0, sizeof(struct ct_spdims) * node->cindex);
|
||||||
for (int i = 0; i < node->cindex; i++) {
|
for (int i = 0; i < node->cindex; i++) {
|
||||||
cspdims[i].min =
|
/* DEBUG: WARNING :DEBUG */
|
||||||
*(int *)(node->child[i]->surface->bounds + bounds_axm_min_offset);
|
// cspdims[i].min =
|
||||||
cspdims[i].max =
|
// *(int *)(node->child[i]->surface->bounds + bounds_axm_min_offset);
|
||||||
*(int *)(node->child[i]->surface->bounds + bounds_axm_max_offset);
|
// cspdims[i].max =
|
||||||
|
// *(int *)(node->child[i]->surface->bounds + bounds_axm_max_offset);
|
||||||
|
cspdims[i].min = node->child[i]->surface->bounds->wmin;
|
||||||
|
cspdims[i].max = node->child[i]->surface->bounds->wmax;
|
||||||
|
|
||||||
if (node->child[i]->surface->bounds->type == BOUND_RELATIVE) {
|
if (node->child[i]->surface->bounds->type == BOUND_RELATIVE) {
|
||||||
cspdims[i].min *= axm_size;
|
cspdims[i].min *= axm_size;
|
||||||
cspdims[i].max *= axm_size;
|
cspdims[i].max *= axm_size;
|
||||||
|
|
@ -165,9 +173,13 @@ int resize_node(struct ct_node *const node, struct ct_dims *const dims) {
|
||||||
// *(int*)(cdims + dims_axo_pos_offset) = *(int*)(dims + dims_axo_pos_offset);
|
// *(int*)(cdims + dims_axo_pos_offset) = *(int*)(dims + dims_axo_pos_offset);
|
||||||
// *(int*)(cdims + dims_axo_size_offset) = axo_size;
|
// *(int*)(cdims + dims_axo_size_offset) = axo_size;
|
||||||
for (int i = 0; i < node->cindex; i++) {
|
for (int i = 0; i < node->cindex; i++) {
|
||||||
*(int *)(cdims + dims_axm_size_offset) = cspdims[i].axm_size;
|
/* DEBUG: WARNING :DEBUG */
|
||||||
|
// *(int *)(cdims + dims_axm_size_offset) = cspdims[i].axm_size;
|
||||||
|
cdims->width = cspdims[i].axm_size;
|
||||||
resize_node(node->child[i], dup_dims(cdims));
|
resize_node(node->child[i], dup_dims(cdims));
|
||||||
*(int *)(cdims + dims_axm_pos_offset) += cspdims[i].axm_size;
|
/* DEBUG: WARNING :DEBUG */
|
||||||
|
// *(int *)(cdims + dims_axm_pos_offset) += cspdims[i].axm_size;
|
||||||
|
cdims->x += cspdims[i].axm_size;
|
||||||
}
|
}
|
||||||
free(cdims);
|
free(cdims);
|
||||||
|
|
||||||
|
|
@ -200,13 +212,13 @@ static int __set_cbounds(struct ct_node *const parent,
|
||||||
|
|
||||||
parent->cbounds.wmin_rel = p_wmin_rel;
|
parent->cbounds.wmin_rel = p_wmin_rel;
|
||||||
parent->cbounds.hmin_rel = p_hmin_rel;
|
parent->cbounds.hmin_rel = p_hmin_rel;
|
||||||
assert(parent->cbounds.wmin_rel > __BOUND_REL_MIN);
|
assert(parent->cbounds.wmin_rel >= __BOUND_REL_MIN);
|
||||||
assert(parent->cbounds.hmin_rel > __BOUND_REL_MIN);
|
assert(parent->cbounds.hmin_rel >= __BOUND_REL_MIN);
|
||||||
} else {
|
} else {
|
||||||
parent->cbounds.wmin_abs += c_wmin;
|
parent->cbounds.wmin_abs += c_wmin;
|
||||||
parent->cbounds.hmin_abs += c_hmin;
|
parent->cbounds.hmin_abs += c_hmin;
|
||||||
assert(parent->cbounds.wmin_abs > __BOUND_ABS_MIN);
|
assert(parent->cbounds.wmin_abs >= __BOUND_ABS_MIN);
|
||||||
assert(parent->cbounds.hmin_abs > __BOUND_ABS_MIN);
|
assert(parent->cbounds.hmin_abs >= __BOUND_ABS_MIN);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -317,8 +329,7 @@ static int __index_as_child(const struct ct_node *const node,
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* If preserve_bounds is set then upon collapse the new node maintains the
|
||||||
* If preserve_bounds is set then upon collapse the new node maintains the
|
|
||||||
* original node's bounds struct. Otherwise the bounds of the child collapsed
|
* original node's bounds struct. Otherwise the bounds of the child collapsed
|
||||||
* onto are used.
|
* onto are used.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ typedef struct _win_st WINDOW;
|
||||||
|
|
||||||
#define NODE_INIT_CHILDREN 4
|
#define NODE_INIT_CHILDREN 4
|
||||||
#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_EMPTY (0)
|
||||||
#define NFLAG_RESIZE (1 << 0)
|
#define NFLAG_RESIZE (1 << 0)
|
||||||
|
|
@ -47,9 +47,17 @@ struct ct_node *__node(struct ct_dims *const dims,
|
||||||
struct ct_node *const parent);
|
struct ct_node *const parent);
|
||||||
struct ct_node *new_node(struct ct_bounds *const bounds,
|
struct ct_node *new_node(struct ct_bounds *const bounds,
|
||||||
struct ct_node *const parent);
|
struct ct_node *const parent);
|
||||||
|
|
||||||
void __destroy_node(struct ct_node *const node);
|
void __destroy_node(struct ct_node *const node);
|
||||||
int resize_node(struct ct_node *const node, struct ct_dims *const new_dims);
|
|
||||||
|
int resize_node(struct ct_node *const node, struct ct_dims *dims);
|
||||||
|
|
||||||
|
int insert_child_node(struct ct_node *const parent, struct ct_node *const child,
|
||||||
|
const cindex i);
|
||||||
|
int append_child_node(struct ct_node *const parent,
|
||||||
|
struct ct_node *const child);
|
||||||
|
struct ct_node *remove_child_node(struct ct_node *const parent,
|
||||||
|
const cindex i);
|
||||||
|
int destroy_child_node(struct ct_node *const parent, const cindex i);
|
||||||
|
|
||||||
void collapse_node(struct ct_node **const node, const int i,
|
void collapse_node(struct ct_node **const node, const int i,
|
||||||
const bool preserve_bounds);
|
const bool preserve_bounds);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue