diff --git a/cmd/wm/mouse.c b/cmd/wm/mouse.c index 486049d3..5f9f99fd 100644 --- a/cmd/wm/mouse.c +++ b/cmd/wm/mouse.c @@ -608,7 +608,6 @@ void drop_move(Frame *f, XRectangle *new, XPoint *pt) for (i = 0; i < size; i++) { f2 = cext_get_item(&a->frames, i); if ((i != idx) && blitz_ispointinrect(cx, cy, &f1->rect)) { - /* XXXX: implement swap replacement */ cext_swap_items(&a->frames, f1, f2); cext_top_item(&a->frames, f2); a->layout->arrange(a); diff --git a/libcext/container.c b/libcext/container.c index 31ade29f..87c0d6c4 100644 --- a/libcext/container.c +++ b/libcext/container.c @@ -14,9 +14,13 @@ static int comp_ptr(void *p1, void *p2) return p1 == p2; } -static void detach_from_stack(CItem *i) +static void detach_from_stack(Container *c, CItem *i) { /* remove from stack */ + if (i == c->stack) { + c->stack = i->down; + return; + } if (i->up) i->up->down = i->down; if (i->down) @@ -65,14 +69,20 @@ void cext_detach_item(Container *c, void *item) i->next = i->next->next; } - detach_from_stack(i); + detach_from_stack(c, i); free(i); } +static CItem *cext_find_citem(Container *c, void *pattern, int (*comp)(void *pattern, void *item)) +{ + CItem *i; + for (i = c->list; i && !comp(pattern, i->item); i = i->next); + return i; +} + void *cext_find_item(Container *c, void *pattern, int (*comp)(void *pattern, void *item)) { - CItem *i; - for (i = c->list; i && comp(pattern, i->item); i = i->next); + CItem *i = cext_find_citem(c, pattern, comp); return i ? i->item : nil; } @@ -85,10 +95,10 @@ void cext_iterate(Container *c, void *aux, void (*iter)(void *, void *aux)) void cext_top_item(Container *c, void *item) { - CItem *i = cext_find_item(c, item, comp_ptr); + CItem *i = cext_find_citem(c, item, comp_ptr); if (!i) return; - detach_from_stack(i); + detach_from_stack(c, i); attach_to_stack(c, i); } @@ -99,7 +109,7 @@ void *cext_get_top_item(Container *c) void *cext_get_down_item(Container *c, void *item) { - CItem *i = cext_find_item(c, item, comp_ptr); + CItem *i = cext_find_citem(c, item, comp_ptr); if (!i) return nil; return i->down ? i->down->item : c->stack->item; @@ -107,7 +117,7 @@ void *cext_get_down_item(Container *c, void *item) void *cext_get_up_item(Container *c, void *item) { - CItem *i = cext_find_item(c, item, comp_ptr); + CItem *i = cext_find_citem(c, item, comp_ptr); CItem *bottom; if (!i) return nil; @@ -150,8 +160,8 @@ size_t cext_sizeof(Container *c) void cext_swap_items(Container *c, void *item1, void *item2) { - CItem *i1 = cext_find_item(c, item1, comp_ptr); - CItem *i2 = cext_find_item(c, item2, comp_ptr); + CItem *i1 = cext_find_citem(c, item1, comp_ptr); + CItem *i2 = cext_find_citem(c, item2, comp_ptr); i1->item = item2; i2->item = item1;