added some test case which offered that cext_detach_item is borken atm, fixing

This commit is contained in:
garbeam 2005-12-07 18:30:34 +02:00
parent 43ed7943be
commit 4948c0db18
6 changed files with 173 additions and 17 deletions

View File

@ -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); 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->file[A_LAYOUT] = wmii_create_ixpfile(ixps, buf, layout);
a->layout = get_layout(layout); a->layout = get_layout(layout);
a->layout->init(a);
cext_attach_item(&p->areas, a); cext_attach_item(&p->areas, a);
p->file[P_SEL_AREA]->content = a->file[A_PREFIX]->content; p->file[P_SEL_AREA]->content = a->file[A_PREFIX]->content;
return a; return a;

View File

@ -234,8 +234,7 @@ void resize_frame(Frame * f, XRectangle * r, XPoint * pt)
/* resize if client requests special size */ /* resize if client requests special size */
check_dimensions(f, tabh, bw); check_dimensions(f, tabh, bw);
if (f->file[F_HANDLE_INC]->content if (f->file[F_HANDLE_INC]->content && ((char *) f->file[F_HANDLE_INC]->content)[0] == '1')
&& ((char *) f->file[F_HANDLE_INC]->content)[0] == '1')
resize_incremental(f, tabh, bw); resize_incremental(f, tabh, bw);
XMoveResizeWindow(dpy, f->win, f->rect.x, f->rect.y, f->rect.width, f->rect.height); XMoveResizeWindow(dpy, f->win, f->rect.x, f->rect.y, f->rect.width, f->rect.height);

View File

@ -16,30 +16,47 @@ static void arrange_float(Area *a);
static Bool attach_float(Area *a, Client *c); static Bool attach_float(Area *a, Client *c);
static void detach_float(Area *a, Client *c); static void detach_float(Area *a, Client *c);
static void resize_float(Frame *f, XRectangle *new, XPoint *pt); 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() void init_layout_float()
{ {
cext_attach_item(&layouts, &lfloat); cext_attach_item(&layouts, &lfloat);
} }
static void arrange_float(Area *a) 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) 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) 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) static Bool attach_float(Area *a, Client *c)
{ {
Frame *f = get_sel_frame_of_area(a); Frame *f = get_sel_frame_of_area(a);
fprintf(stderr, "attach_float() frame=0x%x\n", f);
cext_attach_item(&a->clients, c); cext_attach_item(&a->clients, c);
/* check for tabbing? */ /* check for tabbing? */
if (f && (((char *) f->file[F_LOCKED]->content)[0] == '1')) if (f && (((char *) f->file[F_LOCKED]->content)[0] == '1'))
@ -47,6 +64,7 @@ static Bool attach_float(Area *a, Client *c)
if (!f) { if (!f) {
f = alloc_frame(&c->rect); f = alloc_frame(&c->rect);
attach_frame_to_area(a, f); attach_frame_to_area(a, f);
cext_attach_item((Container *)a->aux, f);
} }
attach_client_to_frame(f, c); attach_client_to_frame(f, c);
if (a->page == get_sel_page()) if (a->page == get_sel_page())
@ -62,6 +80,7 @@ static void detach_float(Area *a, Client *c)
cext_detach_item(&a->clients, c); cext_detach_item(&a->clients, c);
if (!cext_sizeof(&f->clients)) { if (!cext_sizeof(&f->clients)) {
detach_frame_from_area(f); detach_frame_from_area(f);
cext_detach_item((Container *)a->aux, f);
destroy_frame(f); destroy_frame(f);
} }
} }
@ -70,3 +89,7 @@ static void resize_float(Frame *f, XRectangle *new, XPoint *pt)
{ {
f->rect = *new; f->rect = *new;
} }
static Container *get_frames_float(Area *a) {
return a->aux;
}

View File

@ -3,6 +3,7 @@
* See LICENSE file for license details. * See LICENSE file for license details.
*/ */
#include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include "cext.h" #include "cext.h"
@ -18,17 +19,23 @@ static void detach_from_stack(Container *c, CItem *i)
{ {
/* remove from stack */ /* remove from stack */
if (i == c->stack) { if (i == c->stack) {
c->stack = i->down; c->stack = i->down;
return; c->stack->up = 0;
} }
if (i->up) else {
i->up->down = i->down; if (i->up)
if (i->down) i->up->down = i->down;
i->down->up = i->up; if (i->down)
i->down->up = i->up;
}
i->up = 0;
i->down = 0;
} }
static void attach_to_stack(Container *c, CItem *i) static void attach_to_stack(Container *c, CItem *i)
{ {
i->up = 0;
i->down = 0;
if (!c->stack) if (!c->stack)
c->stack = i; c->stack = i;
else { else {
@ -43,32 +50,29 @@ void cext_attach_item(Container *c, void *item)
CItem *i, *new = cext_emalloc(sizeof(CItem)); CItem *i, *new = cext_emalloc(sizeof(CItem));
*new = zero_item; *new = zero_item;
new->item = item; new->item = item;
for (i = c->list; i && i->next; i = i->next);
if (!c->list) if (!c->list)
c->list = new; c->list = new;
else else {
for (i = c->list; i->next; i = i->next);
i->next = new; i->next = new;
}
attach_to_stack(c, new); attach_to_stack(c, new);
} }
void cext_detach_item(Container *c, void *item) void cext_detach_item(Container *c, void *item)
{ {
CItem *i = c->list; CItem *i = c->list;
if (!i) if (!i)
return; return;
/* remove from list */ /* remove from list */
if (i->item == item) if (i->item == item)
c->list = c->list->next; c->list = c->list->next;
else { else {
for (; i->next && i->next->item != item; i = i->next); for (; i->next && (i->next->item != item); i = i->next);
if (!i->next) if (!i->next)
return; return;
i->next = i->next->next; i->next = i->next->next;
} }
detach_from_stack(c, i); detach_from_stack(c, i);
free(i); free(i);
} }
@ -90,7 +94,11 @@ void cext_iterate(Container *c, void *aux, void (*iter)(void *, void *aux))
{ {
CItem *i; CItem *i;
for (i = c->list; i; i = i->next) for (i = c->list; i; i = i->next)
{
assert(c);
assert(i->item);
iter(i->item, aux); iter(i->item, aux);
}
} }
void cext_top_item(Container *c, void *item) void cext_top_item(Container *c, void *item)

25
test/Makefile Normal file
View File

@ -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

100
test/test_container.c Normal file
View File

@ -0,0 +1,100 @@
/*
* (C)opyright MMIV-MMV Anselm R. Garbe <garbeam at gmail dot com>
* See LICENSE file for license details.
*/
#include <assert.h>
#include <stdio.h>
#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;
}