diff --git a/cmd/wm/area.c b/cmd/wm/area.c index 1f6ae4bf..87110b82 100644 --- a/cmd/wm/area.c +++ b/cmd/wm/area.c @@ -34,6 +34,7 @@ Area *alloc_area(Page *p, XRectangle * r, char *layout) snprintf(buf, MAX_BUF, "/%s/a/%d/layout", p->file[P_PREFIX]->name, id); a->file[A_LAYOUT] = wmii_create_ixpfile(ixps, buf, layout); a->layout = get_layout(layout); + a->layout->init(a); cext_attach_item(&p->areas, a); p->file[P_SEL_AREA]->content = a->file[A_PREFIX]->content; return a; diff --git a/cmd/wm/frame.c b/cmd/wm/frame.c index f520689b..0fcbdc6e 100644 --- a/cmd/wm/frame.c +++ b/cmd/wm/frame.c @@ -234,8 +234,7 @@ void resize_frame(Frame * f, XRectangle * r, XPoint * pt) /* resize if client requests special size */ check_dimensions(f, tabh, bw); - if (f->file[F_HANDLE_INC]->content - && ((char *) f->file[F_HANDLE_INC]->content)[0] == '1') + if (f->file[F_HANDLE_INC]->content && ((char *) f->file[F_HANDLE_INC]->content)[0] == '1') resize_incremental(f, tabh, bw); XMoveResizeWindow(dpy, f->win, f->rect.x, f->rect.y, f->rect.width, f->rect.height); diff --git a/cmd/wm/layout_float.c b/cmd/wm/layout_float.c index afd865fe..1a138101 100644 --- a/cmd/wm/layout_float.c +++ b/cmd/wm/layout_float.c @@ -16,30 +16,47 @@ static void arrange_float(Area *a); static Bool attach_float(Area *a, Client *c); static void detach_float(Area *a, Client *c); static void resize_float(Frame *f, XRectangle *new, XPoint *pt); +static Container *get_frames_float(Area *a); -static Layout lfloat = { "float", init_float, deinit_float, arrange_float, attach_float, detach_float, resize_float }; +static Layout lfloat = { "float", init_float, deinit_float, arrange_float, attach_float, + detach_float, resize_float, get_frames_float }; void init_layout_float() { cext_attach_item(&layouts, &lfloat); } - static void arrange_float(Area *a) { } +static void iter_attach_float(void *client, void *area) +{ + attach_float(area, client); +} + static void init_float(Area *a) { + a->aux = cext_emalloc(sizeof(Container)); + cext_iterate(&a->clients, a, iter_attach_float); +} + +static void iter_detach_float(void *client, void *area) +{ + detach_float(area, client); } static void deinit_float(Area *a) { + cext_iterate(&a->clients, a, iter_detach_float); + free(a->aux); + a->aux = nil; } static Bool attach_float(Area *a, Client *c) { Frame *f = get_sel_frame_of_area(a); + fprintf(stderr, "attach_float() frame=0x%x\n", f); cext_attach_item(&a->clients, c); /* check for tabbing? */ if (f && (((char *) f->file[F_LOCKED]->content)[0] == '1')) @@ -47,6 +64,7 @@ static Bool attach_float(Area *a, Client *c) if (!f) { f = alloc_frame(&c->rect); attach_frame_to_area(a, f); + cext_attach_item((Container *)a->aux, f); } attach_client_to_frame(f, c); if (a->page == get_sel_page()) @@ -62,6 +80,7 @@ static void detach_float(Area *a, Client *c) cext_detach_item(&a->clients, c); if (!cext_sizeof(&f->clients)) { detach_frame_from_area(f); + cext_detach_item((Container *)a->aux, f); destroy_frame(f); } } @@ -70,3 +89,7 @@ static void resize_float(Frame *f, XRectangle *new, XPoint *pt) { f->rect = *new; } + +static Container *get_frames_float(Area *a) { + return a->aux; +} diff --git a/libcext/container.c b/libcext/container.c index 87c0d6c4..d4caa217 100644 --- a/libcext/container.c +++ b/libcext/container.c @@ -3,6 +3,7 @@ * See LICENSE file for license details. */ +#include #include #include "cext.h" @@ -18,17 +19,23 @@ static void detach_from_stack(Container *c, CItem *i) { /* remove from stack */ if (i == c->stack) { - c->stack = i->down; - return; + c->stack = i->down; + c->stack->up = 0; } - if (i->up) - i->up->down = i->down; - if (i->down) - i->down->up = i->up; + else { + if (i->up) + i->up->down = i->down; + if (i->down) + i->down->up = i->up; + } + i->up = 0; + i->down = 0; } static void attach_to_stack(Container *c, CItem *i) { + i->up = 0; + i->down = 0; if (!c->stack) c->stack = i; else { @@ -43,32 +50,29 @@ void cext_attach_item(Container *c, void *item) CItem *i, *new = cext_emalloc(sizeof(CItem)); *new = zero_item; new->item = item; - for (i = c->list; i && i->next; i = i->next); if (!c->list) c->list = new; - else + else { + for (i = c->list; i->next; i = i->next); i->next = new; - + } attach_to_stack(c, new); } void cext_detach_item(Container *c, void *item) { CItem *i = c->list; - if (!i) return; - /* remove from list */ if (i->item == item) c->list = c->list->next; else { - for (; i->next && i->next->item != item; i = i->next); + for (; i->next && (i->next->item != item); i = i->next); if (!i->next) return; i->next = i->next->next; } - detach_from_stack(c, i); free(i); } @@ -90,7 +94,11 @@ void cext_iterate(Container *c, void *aux, void (*iter)(void *, void *aux)) { CItem *i; for (i = c->list; i; i = i->next) + { + assert(c); + assert(i->item); iter(i->item, aux); + } } void cext_top_item(Container *c, void *item) diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 00000000..1369ea49 --- /dev/null +++ b/test/Makefile @@ -0,0 +1,25 @@ +# window manager improved 2 testcases +# (C)opyright MMIV-MMV Anselm R. Garbe + +include ../config.mk + +CFLAGS += -I../liblitz -I../libixp -I../libwmii -I../libcext +LDFLAGS += -L../liblitz -llitz -L../libixp -lixp \ + -L../libwmii -lwmii -L../libcext -lcext + +SRC_container = test_container.c +OBJ_container = ${SRC_container:.c=.o} + +all: test_container + @echo built test cases + +.c.o: + @echo CC $< + @${CC} -c ${CFLAGS} $< + +test_container: ${OBJ_container} + @echo LD $@ + @${CC} -o $@ ${OBJ_container} ${LDFLAGS} + +clean: + rm -f test_container *.o diff --git a/test/test_container.c b/test/test_container.c new file mode 100644 index 00000000..7e6d1ea7 --- /dev/null +++ b/test/test_container.c @@ -0,0 +1,100 @@ +/* + * (C)opyright MMIV-MMV Anselm R. Garbe + * See LICENSE file for license details. + */ + +#include +#include + +#include "cext.h" + +static void iter_print_container(void *item, void *aux) +{ + printf("%d\n", *(int *)item); +} + +int main(int argc, char *argv[]) +{ + + Container c = {0}; + int i; + + for (i = 0; i < 10; i++) { + int *e = cext_emalloc(sizeof(int)); + *e = i; + cext_attach_item(&c, e); + } + + printf("--------------------------------\n"); + cext_iterate(&c, nil, iter_print_container); + printf("--------------------------------\n"); + + printf("--------------------------------\n"); + for (i = 0; i < 10; i++) { + int *e = cext_get_item(&c, i); + printf("%d\n", *e); + } + printf("--------------------------------\n"); + + printf("--------------------------------\n"); + { + CItem *itm = c.stack; + for (; itm; itm = itm->down) + printf("%d\n", *(int *)itm->item); + } + printf("--------------------------------\n"); + + printf("--------------------------------\n"); + { + int *e = cext_get_item(&c, 5); + cext_top_item(&c, e); + e = cext_get_top_item(&c); + printf("%d (5)\n", *e); + e = cext_get_up_item(&c, cext_get_top_item(&c)); + printf("%d (0)\n", *e); + e = cext_get_down_item(&c, cext_get_top_item(&c)); + printf("%d (9)\n", *e); + } + printf("--------------------------------\n"); + + printf("--------------------------------\n"); + { + CItem *itm = c.stack; + for (; itm; itm = itm->down) + printf("%d\n", *(int *)itm->item); + } + printf("--------------------------------\n"); + + printf("--------------------------------\n"); + { + int *e = cext_get_item(&c, 5); + cext_detach_item(&c, e); + cext_iterate(&c, nil, iter_print_container); + } + printf("--------------------------------\n"); + + printf("--------------------------------\n"); + { + CItem *itm = c.stack; + for (; itm; itm = itm->down) + printf("%d\n", *(int *)itm->item); + } + printf("--------------------------------\n"); + + printf("--------------------------------\n"); + { + int *e = cext_get_item(&c, 4); + cext_detach_item(&c, e); + cext_iterate(&c, nil, iter_print_container); + } + printf("--------------------------------\n"); + + printf("--------------------------------\n"); + { + CItem *itm = c.stack; + for (; itm; itm = itm->down) + printf("%d\n", *(int *)itm->item); + } + printf("--------------------------------\n"); + return TRUE; +}