wmii

git clone git://oldgit.suckless.org/wmii/
Log | Files | Refs | README | LICENSE

commit 3bbcf9f569d7d99a81fed8b7bc4ff49bf2e3d43c
parent fb8176db37c20276ab9b81ef5102c4a11d423a7c
Author: garbeam <garbeam@mmv.wmii.de>
Date:   Fri,  9 Dec 2005 16:49:55 +0200

added also top-down and bottom-up iterators to container (for stack iteration)


Diffstat:
cmd/wm/area.c | 11+++++++----
cmd/wm/client.c | 14++++++++------
cmd/wm/frame.c | 22+++++++++-------------
cmd/wm/layout_column.c | 15++++++++-------
cmd/wm/layout_float.c | 8+++-----
cmd/wm/page.c | 23+++++++++++------------
cmd/wm/wm.c | 14+++++---------
cmd/wm/wm.h | 6+++---
cmd/wmibar.c | 2+-
cmd/wmifs.c | 2+-
libcext/cext.h | 4+++-
libcext/container.c | 45++++++++++++++++++++++++++++++++++-----------
rc/wmirc | 4++--
13 files changed, 95 insertions(+), 75 deletions(-)

diff --git a/cmd/wm/area.c b/cmd/wm/area.c @@ -39,7 +39,10 @@ Area *alloc_area(Page *p, XRectangle * r, char *layout) void destroy_area(Area *a) { + Client *c; a->layout->deinit(a); + while ((c = cext_stack_get_top_item(&a->clients))) + cext_detach_item(&a->clients, c); ixp_remove_file(ixps, a->file[A_PREFIX]); free(a); } @@ -55,7 +58,7 @@ void sel_area(Area *a) Frame *f; Bool raise = cext_list_get_item_index(&p->areas, a) == 0; if (raise) - cext_iterate(a->layout->get_frames(a), nil, iter_raise_frame); + cext_stack_iterate_up(a->layout->get_frames(a), nil, iter_raise_frame); cext_stack_top_item(&p->areas, a); p->file[P_SEL_AREA]->content = a->file[A_PREFIX]->content; if ((f = get_sel_frame_of_area(a))) @@ -64,7 +67,7 @@ void sel_area(Area *a) void draw_area(Area *a) { - cext_iterate(a->layout->get_frames(a), nil, draw_frame); + cext_list_iterate(a->layout->get_frames(a), nil, draw_frame); } static void iter_hide_area(void *item, void *aux) @@ -74,7 +77,7 @@ static void iter_hide_area(void *item, void *aux) void hide_area(Area * a) { - cext_iterate(a->layout->get_frames(a), nil, iter_hide_area); + cext_list_iterate(a->layout->get_frames(a), nil, iter_hide_area); } static void iter_show_area(void *item, void *aux) @@ -84,7 +87,7 @@ static void iter_show_area(void *item, void *aux) void show_area(Area * a) { - cext_iterate(a->layout->get_frames(a), nil, iter_show_area); + cext_list_iterate(a->layout->get_frames(a), nil, iter_show_area); } Area *get_sel_area() diff --git a/cmd/wm/client.c b/cmd/wm/client.c @@ -200,8 +200,6 @@ void destroy_client(Client * c) { cext_detach_item(&clients, c); ixp_remove_file(ixps, c->file[C_PREFIX]); - if (ixps->errstr) - fprintf(stderr, "wmiiwm: destroy_client(): %s\n", ixps->errstr); free(c); } @@ -250,7 +248,7 @@ void draw_client(void *item, void *aux) void draw_clients(Frame * f) { - cext_iterate(&f->clients, 0, draw_client); + cext_list_iterate(&f->clients, 0, draw_client); } void gravitate(Client * c, unsigned int tabh, unsigned int bw, int invert) @@ -326,6 +324,7 @@ void attach_client(Client * c) if (t && t->frame) a = t->frame->area; } + cext_attach_item(&a->clients, c); a->layout->attach(a, c); if (old) draw_frame(old, nil); @@ -333,11 +332,14 @@ void attach_client(Client * c) } void detach_client(Client *c) { - if (c->frame) - c->frame->area->layout->detach(c->frame->area, c); + Page *p; + Area *a = c->frame->area; + a->layout->detach(a, c); + cext_detach_item(&a->clients, c); if (c->destroyed) destroy_client(c); - draw_page(get_sel_page()); + if ((p = get_sel_page())) + draw_page(p); } Client *get_sel_client() diff --git a/cmd/wm/frame.c b/cmd/wm/frame.c @@ -128,8 +128,6 @@ void destroy_frame(Frame * f) XFreeGC(dpy, f->gc); XDestroyWindow(dpy, f->win); ixp_remove_file(ixps, f->file[F_PREFIX]); - if (ixps->errstr) - fprintf(stderr, "wmiiwm: destroy_frame(): %s\n", ixps->errstr); free(f); } @@ -167,7 +165,7 @@ static void iter_resize_client(void *item, void *aux) static void resize_clients(Frame * f, int tabh, int bw) { Twouint aux = { tabh, bw }; - cext_iterate(&f->clients, &aux, iter_resize_client); + cext_list_iterate(&f->clients, &aux, iter_resize_client); } static void check_dimensions(Frame * f, unsigned int tabh, unsigned int bw) @@ -310,7 +308,7 @@ void handle_frame_buttonpress(XButtonEvent *e, Frame *f) draw_frame(f, nil); } -void attach_client_to_frame(Frame * f, Client * c) +void attach_client_to_frame(Frame *f, Client *c) { wmii_move_ixpfile(c->file[C_PREFIX], f->file[F_CLIENT_PREFIX]); f->file[F_SEL_CLIENT]->content = c->file[C_PREFIX]->content; @@ -322,18 +320,16 @@ void attach_client_to_frame(Frame * f, Client * c) sel_client(c); } -void detach_client_from_frame(Client * c) +void detach_client_from_frame(Frame *f, Client *c) { Client *client; - Frame *f = c->frame; + c->frame = nil; + f->file[F_SEL_CLIENT]->content = nil; wmii_move_ixpfile(c->file[C_PREFIX], def[WM_DETACHED_CLIENT]); - c->frame = 0; cext_detach_item(&f->clients, c); if (!c->destroyed) { - if (f) { - hide_client(c); - cext_attach_item(&detached, c); - } + hide_client(c); + cext_attach_item(&detached, c); reparent_client(c, root, border_width(f), tab_height(f)); } if ((client = cext_stack_get_top_item(&f->clients))) { @@ -372,7 +368,7 @@ static void iter_before_read_frame(void *item, void *aux) static void handle_before_read_frame(IXPServer *s, File *f) { - cext_iterate(&frames, f, iter_before_read_frame); + cext_list_iterate(&frames, f, iter_before_read_frame); } static void iter_after_write_frame(void *item, void *aux) @@ -401,7 +397,7 @@ static void iter_after_write_frame(void *item, void *aux) static void handle_after_write_frame(IXPServer * s, File * f) { - cext_iterate(&frames, f, iter_after_write_frame); + cext_list_iterate(&frames, f, iter_after_write_frame); } Frame *get_sel_frame_of_area(Area *a) diff --git a/cmd/wm/layout_column.c b/cmd/wm/layout_column.c @@ -66,13 +66,13 @@ static void iter_arrange_column(void *column, void *area) Column *col = column; size_t size = cext_sizeof(&col->frames); unsigned int height = ((Area *)area)->rect.height / size; - cext_iterate(&col->frames, &height, iter_arrange_column_frame); + cext_list_iterate(&col->frames, &height, iter_arrange_column_frame); } static void arrange_col(Area *a) { Acme *acme = a->aux; - cext_iterate(&acme->columns, a, iter_arrange_column); + cext_list_iterate(&acme->columns, a, iter_arrange_column); } static void init_col(Area *a) @@ -155,25 +155,26 @@ static void init_col(Area *a) static void iter_detach_client(void *client, void *aux) { - detach_client_from_frame((Client *)client); + Client *c = client; + detach_client_from_frame(c->frame, c); } static void iter_detach_frame(void *frame, void *aux) { Frame *f = frame; - cext_iterate(&f->clients, nil, iter_detach_client); + cext_list_iterate(&f->clients, nil, iter_detach_client); } static void iter_deinit_col(void *column, void *aux) { Column *col = column; - cext_iterate(&col->frames, nil, iter_detach_frame); + cext_list_iterate(&col->frames, nil, iter_detach_frame); } static void deinit_col(Area *a) { Acme *acme = a->aux; - cext_iterate(&acme->columns, nil, iter_deinit_col); + cext_list_iterate(&acme->columns, nil, iter_deinit_col); free(acme); a->aux = 0; } @@ -202,7 +203,7 @@ static void detach_col(Area *a, Client *c) cext_detach_item(&col->frames, f); col->refresh = 1; - detach_client_from_frame(c); + detach_client_from_frame(f, c); detach_frame_from_area(f); destroy_frame(f); diff --git a/cmd/wm/layout_float.c b/cmd/wm/layout_float.c @@ -39,7 +39,7 @@ static void init_float(Area *a) { Container *c = cext_emallocz(sizeof(Container)); a->aux = c; - cext_iterate(&a->clients, a, iter_attach_float); + cext_list_iterate(&a->clients, a, iter_attach_float); } static void iter_detach_float(void *client, void *area) @@ -49,7 +49,7 @@ static void iter_detach_float(void *client, void *area) static void deinit_float(Area *a) { - cext_iterate(&a->clients, a, iter_detach_float); + cext_list_iterate(&a->clients, a, iter_detach_float); free(a->aux); a->aux = nil; } @@ -59,7 +59,6 @@ static Bool attach_float(Area *a, Client *c) Frame *f = get_sel_frame_of_area(a); Bool center = False; - cext_attach_item(&a->clients, c); /* check for tabbing? */ if (f && (((char *) f->file[F_LOCKED]->content)[0] == '1')) f = 0; @@ -82,8 +81,7 @@ static Bool attach_float(Area *a, Client *c) static void detach_float(Area *a, Client *c) { Frame *f = c->frame; - detach_client_from_frame(c); - cext_detach_item(&a->clients, c); + detach_client_from_frame(f, c); if (!cext_sizeof(&f->clients)) { detach_frame_from_area(f); cext_detach_item((Container *)a->aux, f); diff --git a/cmd/wm/page.c b/cmd/wm/page.c @@ -45,23 +45,22 @@ Page *alloc_page() return p; } -static void iter_destroy_page(void *item, void *aux) +static void iter_destroy_area(void *area, void *aux) { - destroy_area((Area *)item); + destroy_area((Area *)area); } void destroy_page(Page * p) { - cext_iterate(&p->areas, nil, iter_destroy_page); + cext_list_iterate(&p->areas, nil, iter_destroy_area); def[WM_SEL_PAGE]->content = 0; ixp_remove_file(ixps, p->file[P_PREFIX]); - if (ixps->errstr) - fprintf(stderr, "wmiiwm: free_page(): %s\n", ixps->errstr); + cext_detach_item(&pages, p); free(p); - if ((p = get_sel_page())) { - show_page(p); + if ((p = get_sel_page())) sel_page(p); - } + else + invoke_wm_event(def[WM_EVENT_PAGE_UPDATE]); } void sel_page(Page * p) @@ -86,7 +85,7 @@ static void iter_draw_page(void *item, void *aux) void draw_page(Page * p) { - cext_iterate(&p->areas, nil, iter_draw_page); + cext_list_iterate(&p->areas, nil, iter_draw_page); } XRectangle *rectangles(unsigned int *num) @@ -150,7 +149,7 @@ static void iter_hide_page(void *item, void *aux) void hide_page(Page * p) { - cext_iterate(&p->areas, nil, iter_hide_page); + cext_list_iterate(&p->areas, nil, iter_hide_page); } static void iter_show_page(void *item, void *aux) @@ -160,7 +159,7 @@ static void iter_show_page(void *item, void *aux) void show_page(Page * p) { - cext_iterate(&p->areas, nil, iter_show_page); + cext_list_iterate(&p->areas, nil, iter_show_page); } static void iter_after_write_page(void *item, void *aux) @@ -175,7 +174,7 @@ static void iter_after_write_page(void *item, void *aux) static void handle_after_write_page(IXPServer *s, File *f) { - cext_iterate(&pages, f, iter_after_write_page); + cext_list_iterate(&pages, f, iter_after_write_page); } Page *get_sel_page() diff --git a/cmd/wm/wm.c b/cmd/wm/wm.c @@ -133,7 +133,7 @@ static void iter_draw_pager_frame(void *item, void *aux) static void draw_pager_area(void *item, void *aux) { Area *a = (Area *)item; - cext_iterate(a->layout->get_frames(a), aux, iter_draw_pager_frame); + cext_stack_iterate_up(a->layout->get_frames(a), aux, iter_draw_pager_frame); } static void draw_pager_page(Page *p, Draw *d) @@ -153,7 +153,7 @@ static void draw_pager_page(Page *p, Draw *d) d->data = name; blitz_drawlabel(dpy, d); XSync(dpy, False); - cext_iterate(&p->areas, d, draw_pager_area); + cext_stack_iterate_up(&p->areas, d, draw_pager_area); } static void draw_pager() @@ -245,9 +245,7 @@ static void pager(void *obj, char *cmd) XClearWindow(dpy, transient); XMapRaised(dpy, transient); draw_pager(); - while (XGrabKeyboard - (dpy, transient, True, GrabModeAsync, GrabModeAsync, - CurrentTime) != GrabSuccess) + while (XGrabKeyboard (dpy, transient, True, GrabModeAsync, GrabModeAsync, CurrentTime) != GrabSuccess) usleep(1000); for (;;) { @@ -330,9 +328,7 @@ static void detached_clients(void *obj, char *cmd) XClearWindow(dpy, transient); XMapRaised(dpy, transient); draw_detached_clients(); - while (XGrabKeyboard - (dpy, transient, True, GrabModeAsync, GrabModeAsync, - CurrentTime) != GrabSuccess) + while (XGrabKeyboard(dpy, transient, True, GrabModeAsync, GrabModeAsync, CurrentTime) != GrabSuccess) usleep(1000); for (;;) { @@ -680,7 +676,7 @@ static void clean_client_up(void *item, void *aux) static void cleanup() { - cext_iterate(&clients, nil, clean_client_up); + cext_list_iterate(&clients, nil, clean_client_up); XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); } diff --git a/cmd/wm/wm.h b/cmd/wm/wm.h @@ -241,9 +241,9 @@ Frame *alloc_frame(XRectangle * r); void destroy_frame(Frame * f); void resize_frame(Frame * f, XRectangle * r, XPoint * pt); void draw_frame(void *frame, void *aux); -void handle_frame_buttonpress(XButtonEvent * e, Frame * f); -void attach_client_to_frame(Frame * f, Client * c); -void detach_client_from_frame(Client *c); +void handle_frame_buttonpress(XButtonEvent *e, Frame *f); +void attach_client_to_frame(Frame *f, Client *c); +void detach_client_from_frame(Frame *f, Client *c); unsigned int tab_height(Frame * f); unsigned int border_width(Frame * f); Frame *get_sel_frame(); diff --git a/cmd/wmibar.c b/cmd/wmibar.c @@ -335,7 +335,7 @@ static void iter_buttonpress(void *item, void *bpress) static void handle_buttonpress(XButtonPressedEvent *e) { - cext_iterate(&items, e, iter_buttonpress); + cext_list_iterate(&items, e, iter_buttonpress); } static void check_event(Connection * e) diff --git a/cmd/wmifs.c b/cmd/wmifs.c @@ -72,7 +72,7 @@ static void iter_unbind(void *bind, void *aux) static void quit(void *obj, char *arg) { - cext_iterate(&bindings, nil, iter_unbind); + cext_list_iterate(&bindings, nil, iter_unbind); ixps->runlevel = SHUTDOWN; } diff --git a/libcext/cext.h b/libcext/cext.h @@ -34,13 +34,15 @@ struct Container { void cext_attach_item(Container *c, void *item); void cext_detach_item(Container *c, void *item); void *cext_find_item(Container *c, void *pattern, int (*comp)(void *pattern, void *item)); -void cext_iterate(Container *c, void *aux, void (*iter)(void *, void *aux)); void cext_swap_items(Container *c, void *item1, void *item2); size_t cext_sizeof(Container *c); void cext_stack_top_item(Container *c, void *item); void *cext_stack_get_top_item(Container *c); void *cext_stack_get_down_item(Container *c, void *item); void *cext_stack_get_up_item(Container *c, void *item); +void cext_stack_iterate_down(Container *c, void *aux, void (*iter)(void *, void *aux)); +void cext_stack_iterate_up(Container *c, void *aux, void (*iter)(void *, void *aux)); +void cext_list_iterate(Container *c, void *aux, void (*iter)(void *, void *aux)); void *cext_list_get_item(Container *c, size_t index); int cext_list_get_item_index(Container *c, void *item); void *cext_list_get_next_item(Container *c, void *item); diff --git a/libcext/container.c b/libcext/container.c @@ -92,17 +92,6 @@ void *cext_find_item(Container *c, void *pattern, int (*comp)(void *pattern, voi return i ? i->item : nil; } -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); - } -} - size_t cext_sizeof(Container *c) { size_t idx = 0; @@ -155,6 +144,40 @@ void *cext_stack_get_up_item(Container *c, void *item) return i->up ? i->up->item : bottom->item; } +void cext_stack_iterate_down(Container *c, void *aux, void (*iter)(void *, void *aux)) +{ + CItem *i; + for (i = c->stack; i; i = i->down) + { + assert(c); + assert(i->item); + iter(i->item, aux); + } +} + +void cext_stack_iterate_up(Container *c, void *aux, void (*iter)(void *, void *aux)) +{ + CItem *i; + for (i = c->stack; i && i->down; i = i->down); + for (; i; i = i->up) + { + assert(c); + assert(i->item); + iter(i->item, aux); + } +} + +void cext_list_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_list_get_item(Container *c, size_t index) { size_t idx = 0; diff --git a/rc/wmirc b/rc/wmirc @@ -3,7 +3,7 @@ TAB=1 -SEL_BG_COLOR='#101010' +SEL_BG_COLOR='#002200' SEL_FG_COLOR='#66ff00' SEL_BORDER_COLOR='#66ff00' NORM_BG_COLOR='#000000' @@ -110,7 +110,7 @@ wmir write /wm/event/clientupdate \ wmir write /bar/'^$clab^'/data $"text' wmir write /wm/event/pageupdate \ 'wmir write /bar/'^$plab^'/data `{wmir read /wm/sel/name} &&' ^ \ -'wmir write /bar/'^$llab^'/data `{wmir read /wm/sel/layout/sel/name |awk ''{print substr($0,0,1)}''}' +'wmir write /bar/'^$llab^'/data `{wmir read /wm/sel/layout/sel/name}' for(frame in `{wmir read /wm/sel/layout/sel | grep '^[0-9]'}) framesconf /wm/sel/layout/sel/$frame refresh