wmii

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

commit 43ed7943bed0d1bfe041a30441678d3578df52df
parent c552c5851942774c15b14316ef1aa9623dbdd801
Author: garbeam <garbeam@localhost.localdomain>
Date:   Wed,  7 Dec 2005 16:06:16 +0200

removed frames container from area, areas contain clients only in their container,
instead the layout is responsible to provide a frame container of its frames


Diffstat:
cmd/wm/Makefile | 6+++---
cmd/wm/Makefile.wm | 4++--
cmd/wm/area.c | 37+++++++++++++++++--------------------
cmd/wm/client.c | 5+----
cmd/wm/frame.c | 4++--
cmd/wm/layout.c | 21+++++++++++++++++++++
cmd/wm/layout_column.c | 9+++++----
cmd/wm/layout_float.c | 11+++++++----
cmd/wm/mklayout.sh | 16++++++++--------
cmd/wm/mouse.c | 13+++++++------
cmd/wm/page.c | 6+++---
cmd/wm/wm.c | 18+++---------------
cmd/wm/wm.h | 18++++++++++--------
13 files changed, 89 insertions(+), 79 deletions(-)

diff --git a/cmd/wm/Makefile b/cmd/wm/Makefile @@ -3,13 +3,13 @@ include ../../config.mk -all: layout.c +all: layoutdef.c @${MAKE} -f Makefile.wm @echo built core wm -layout.c: +layoutdef.c: @echo SH mklayout.sh @sh mklayout.sh clean: - rm -f wmiiwm *.o layout.* + rm -f wmiiwm *.o layoutdef.* diff --git a/cmd/wm/Makefile.wm b/cmd/wm/Makefile.wm @@ -8,9 +8,9 @@ CFLAGS += -I../../liblitz -I../../libixp -I../../libwmii \ LDFLAGS += -L../../liblitz -llitz -L../../libixp -lixp \ -L../../libwmii -lwmii -L../../libcext -lcext -SRC = wm.c client.c event.c mouse.c frame.c area.c page.c layout.c +SRC = wm.c client.c event.c mouse.c frame.c area.c page.c layoutdef.c layout.c -include layout.mk +include layoutdef.mk OBJ = ${SRC:.c=.o} diff --git a/cmd/wm/area.c b/cmd/wm/area.c @@ -48,7 +48,7 @@ static void iter_destroy_area(void *item, void *aux) void destroy_area(Area *a) { a->layout->deinit(a); - cext_iterate(&a->frames, nil, iter_destroy_area); + cext_iterate(a->layout->get_frames(a), nil, iter_destroy_area); ixp_remove_file(ixps, a->file[A_PREFIX]); free(a); } @@ -64,31 +64,16 @@ void sel_area(Area *a) Frame *f; Bool raise = cext_get_item_index(&p->areas, a) == 0; if (raise) - cext_iterate(&a->frames, nil, iter_raise_frame); + cext_iterate(a->layout->get_frames(a), nil, iter_raise_frame); cext_top_item(&p->areas, a); p->file[P_SEL_AREA]->content = a->file[A_PREFIX]->content; if ((f = get_sel_frame_of_area(a))) sel_frame(f, raise); } -void attach_frame_to_area(Area * a, Frame * f) -{ - wmii_move_ixpfile(f->file[F_PREFIX], a->file[A_FRAME_PREFIX]); - a->file[A_SEL_FRAME]->content = f->file[F_PREFIX]->content; - cext_attach_item(&a->frames, f); - f->area = a; -} - -void detach_frame_from_area(Frame * f, int ignore_sel_and_destroy) -{ - Area *a = f->area; - cext_detach_item(&a->frames, f); - f->area = 0; -} - void draw_area(Area *a) { - cext_iterate(&a->frames, nil, draw_frame); + cext_iterate(a->layout->get_frames(a), nil, draw_frame); } static void iter_hide_area(void *item, void *aux) @@ -98,7 +83,7 @@ static void iter_hide_area(void *item, void *aux) void hide_area(Area * a) { - cext_iterate(&a->frames, nil, iter_hide_area); + cext_iterate(a->layout->get_frames(a), nil, iter_hide_area); } static void iter_show_area(void *item, void *aux) @@ -108,7 +93,7 @@ static void iter_show_area(void *item, void *aux) void show_area(Area * a) { - cext_iterate(&a->frames, nil, iter_show_area); + cext_iterate(a->layout->get_frames(a), nil, iter_show_area); } Area *get_sel_area() @@ -117,3 +102,15 @@ Area *get_sel_area() return p ? cext_get_top_item(&p->areas) : nil; } + +void attach_frame_to_area(Area *a, Frame *f) +{ + wmii_move_ixpfile(f->file[F_PREFIX], a->file[A_FRAME_PREFIX]); + a->file[A_SEL_FRAME]->content = f->file[F_PREFIX]->content; + f->area = a; +} + +void detach_frame_from_area(Frame *f) { + f->area->file[A_SEL_FRAME]->content = 0; + f->area = 0; +} diff --git a/cmd/wm/client.c b/cmd/wm/client.c @@ -311,7 +311,6 @@ 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); @@ -319,10 +318,8 @@ void attach_client(Client * c) } void detach_client(Client *c) { - if (c->frame) { - cext_detach_item(&c->frame->area->clients, c); + if (c->frame) c->frame->area->layout->detach(c->frame->area, c); - } if (c->destroyed) destroy_client(c); sel_page(get_sel_page()); diff --git a/cmd/wm/frame.c b/cmd/wm/frame.c @@ -106,7 +106,7 @@ void sel_frame(Frame * f, Bool raise) { Area *a = f->area; sel_client(cext_get_top_item(&f->clients)); - cext_top_item(&a->frames, f); + cext_top_item(a->layout->get_frames(a), f); a->file[A_SEL_FRAME]->content = f->file[F_PREFIX]->content; if (raise) XRaiseWindow(dpy, f->win); @@ -440,7 +440,7 @@ static void handle_after_write_frame(IXPServer * s, File * f) Frame *get_sel_frame_of_area(Area *a) { - return cext_get_top_item(&a->frames); + return cext_get_top_item(a->layout->get_frames(a)); } Frame *get_sel_frame() diff --git a/cmd/wm/layout.c b/cmd/wm/layout.c @@ -0,0 +1,21 @@ +/* + * (C)opyright MMIV-MMV Anselm R. Garbe <garbeam at gmail dot com> + * See LICENSE file for license details. + */ + +#include <string.h> + +#include "wm.h" + +static int comp_layout_name(void *name, void *layout) +{ + Layout *l = layout; + size_t len = strlen(l->name); + + return !strncmp(name, l->name, len); +} + +Layout *get_layout(char *name) +{ + return cext_find_item(&layouts, name, comp_layout_name); +} diff --git a/cmd/wm/layout_column.c b/cmd/wm/layout_column.c @@ -8,7 +8,7 @@ #include <math.h> #include "wm.h" -#include "layout.h" +#include "layoutdef.h" typedef struct Acme Acme; typedef struct Column Column; @@ -28,7 +28,7 @@ struct Column { static void init_col(Area * a); static void deinit_col(Area * a); static void arrange_col(Area * a); -static void attach_col(Area * a, Client * c); +static Bool attach_col(Area * a, Client * c); static void detach_col(Area * a, Client * c); static void resize_col(Frame * f, XRectangle * new, XPoint * pt); @@ -179,7 +179,7 @@ static void deinit_col(Area *a) a->aux = 0; } -static void attach_col(Area *a, Client *c) +static Bool attach_col(Area *a, Client *c) { Acme *acme = a->aux; Column *col; @@ -193,6 +193,7 @@ static void attach_col(Area *a, Client *c) attach_frame_to_area(a, f); attach_client_to_frame(f, c); arrange_col(a); + return True; } static void detach_col(Area *a, Client *c) @@ -203,7 +204,7 @@ static void detach_col(Area *a, Client *c) cext_detach_item(&col->frames, f); col->refresh = 1; detach_client_from_frame(c); - detach_frame_from_area(f, 1); + detach_frame_from_area(f); destroy_frame(f); arrange_col(a); diff --git a/cmd/wm/layout_float.c b/cmd/wm/layout_float.c @@ -8,12 +8,12 @@ #include <math.h> #include "wm.h" -#include "layout.h" +#include "layoutdef.h" static void init_float(Area *a); static void deinit_float(Area *a); static void arrange_float(Area *a); -static void attach_float(Area *a, Client *c); +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); @@ -37,9 +37,10 @@ static void deinit_float(Area *a) { } -static void attach_float(Area *a, Client *c) +static Bool attach_float(Area *a, Client *c) { Frame *f = get_sel_frame_of_area(a); + cext_attach_item(&a->clients, c); /* check for tabbing? */ if (f && (((char *) f->file[F_LOCKED]->content)[0] == '1')) f = 0; @@ -51,14 +52,16 @@ static void attach_float(Area *a, Client *c) if (a->page == get_sel_page()) XMapRaised(dpy, f->win); draw_frame(f, nil); + return True; } static void detach_float(Area *a, Client *c) { Frame *f = c->frame; detach_client_from_frame(c); + cext_detach_item(&a->clients, c); if (!cext_sizeof(&f->clients)) { - detach_frame_from_area(f, 0); + detach_frame_from_area(f); destroy_frame(f); } } diff --git a/cmd/wm/mklayout.sh b/cmd/wm/mklayout.sh @@ -1,12 +1,12 @@ #!/bin/sh -rm -f layout.h layout.c layout.mk -echo "#include \"layout.h\"" > layout.c -echo "#include \"wm.h\"" >> layout.c -echo "void init_layouts() {" >> layout.c +rm -f layoutdef.h layoutdef.c layout.mk +echo "#include \"layoutdef.h\"" > layoutdef.c +echo "#include \"wm.h\"" >> layoutdef.c +echo "void init_layouts() {" >> layoutdef.c for i in `ls layout_*.c`; do FUNC="`echo \`basename $i\` | sed 's/\.c//g'`" - echo "void init_$FUNC();" >> layout.h - echo " init_$FUNC();" >> layout.c; - echo "SRC += $i" >>layout.mk + echo "void init_$FUNC();" >> layoutdef.h + echo " init_$FUNC();" >> layoutdef.c; + echo "SRC += $i" >>layoutdef.mk done -echo "}" >> layout.c +echo "}" >> layoutdef.c diff --git a/cmd/wm/mouse.c b/cmd/wm/mouse.c @@ -596,20 +596,21 @@ void drop_move(Frame *f, XRectangle *new, XPoint *pt) { Frame *f1, *f2; Area *a = f->area; + Container *frames = a->layout->get_frames(a); int cx, cy; - unsigned int i, idx = cext_get_item_index(&a->frames, f); - size_t size = cext_sizeof(&a->frames); + unsigned int i, idx = cext_get_item_index(frames, f); + size_t size = cext_sizeof(frames); if ((f->rect.x == new->x) && (f->rect.y == new->y)) return; cx = (pt ? pt->x : new->x + new->width / 2); cy = (pt ? pt->y : new->y + new->height / 2); - f1 = cext_get_item(&a->frames, idx); + f1 = cext_get_item(frames, idx); for (i = 0; i < size; i++) { - f2 = cext_get_item(&a->frames, i); + f2 = cext_get_item(frames, i); if ((i != idx) && blitz_ispointinrect(cx, cy, &f1->rect)) { - cext_swap_items(&a->frames, f1, f2); - cext_top_item(&a->frames, f2); + cext_swap_items(frames, f1, f2); + cext_top_item(frames, f2); a->layout->arrange(a); return; } diff --git a/cmd/wm/page.c b/cmd/wm/page.c @@ -30,7 +30,7 @@ Page *alloc_page() p->file[P_PREFIX] = ixp_create(ixps, buf); snprintf(buf, sizeof(buf), "/%d/name", id); p->file[P_NAME] = wmii_create_ixpfile(ixps, buf, buf2); - snprintf(buf, sizeof(buf), "/%d/a", id); + snprintf(buf, sizeof(buf), "/%d/a/", id); p->file[P_AREA_PREFIX] = ixp_create(ixps, buf); snprintf(buf, sizeof(buf), "/%d/a/sel", id); p->file[P_SEL_AREA] = ixp_create(ixps, buf); @@ -148,9 +148,9 @@ static void select_frame(void *obj, char *cmd) return; a = f->area; if (!strncmp(cmd, "prev", 5)) - cext_top_item(&a->frames, cext_get_up_item(&a->frames, f)); + cext_top_item(a->layout->get_frames(a), cext_get_up_item(a->layout->get_frames(a), f)); else if (!strncmp(cmd, "next", 5)) - cext_top_item(&a->frames, cext_get_down_item(&a->frames, f)); + cext_top_item(a->layout->get_frames(a), cext_get_down_item(a->layout->get_frames(a), f)); if (old != f) { sel_frame(f, cext_get_item_index(&a->page->areas, a) == 0); center_pointer(f); diff --git a/cmd/wm/wm.c b/cmd/wm/wm.c @@ -115,7 +115,7 @@ static void iter_draw_pager_frame(void *item, void *aux) { Draw *d = aux; Frame *f = (Frame *)item; - if (f == cext_get_top_item(&f->area->frames)) { + if (f == cext_get_top_item(f->area->layout->get_frames(f->area))) { d->bg = blitz_loadcolor(dpy, screen_num, def[WM_SEL_BG_COLOR]->content); d->fg = blitz_loadcolor(dpy, screen_num, def[WM_SEL_FG_COLOR]->content); d->border = blitz_loadcolor(dpy, screen_num, def[WM_SEL_BORDER_COLOR]->content); @@ -132,7 +132,8 @@ static void iter_draw_pager_frame(void *item, void *aux) static void draw_pager_area(void *item, void *aux) { - cext_iterate(&((Area *)item)->frames, aux, iter_draw_pager_frame); + Area *a = (Area *)item; + cext_iterate(a->layout->get_frames(a), aux, iter_draw_pager_frame); } static void draw_pager_page(Page *p, Draw *d) @@ -543,19 +544,6 @@ void handle_after_write(IXPServer * s, File * f) check_event(0); } -static int comp_layout_name(void *name, void *layout) -{ - Layout *l = layout; - size_t len = strlen(l->name); - - return !strncmp(name, l->name, len); -} - -Layout *get_layout(char *name) -{ - return cext_find_item(&layouts, name, comp_layout_name); -} - static void init_atoms() { wm_state = XInternAtom(dpy, "WM_STATE", False); diff --git a/cmd/wm/wm.h b/cmd/wm/wm.h @@ -120,16 +120,15 @@ struct Layout { void (*init) (Area *); /* called when layout is initialized */ void (*deinit) (Area *); /* called when layout is uninitialized */ void (*arrange) (Area *); /* called when area is resized */ - void (*attach) (Area *, Client *); /* called on attach */ + Bool (*attach) (Area *, Client *); /* called on attach */ void (*detach) (Area *, Client *); /* called on detach */ void (*resize) (Frame *, XRectangle *, XPoint * pt); /* called after resize */ + Container *(*get_frames) (Area *); /* called after resize */ }; struct Area { - Layout *layout; Page *page; - Container frames; - /* XXX: remove frames container, areas shall only contain clients */ + Layout *layout; Container clients; XRectangle rect; void *aux; /* free pointer */ @@ -138,8 +137,8 @@ struct Area { struct Frame { Area *area; - Container clients; Window win; + Container clients; GC gc; XRectangle rect; Cursor cursor; @@ -148,6 +147,7 @@ struct Frame { }; struct Client { + Area *area; int proto; unsigned int border; Bool destroyed; @@ -206,12 +206,12 @@ unsigned int valid_mask, num_lock_mask; Area *alloc_area(Page *p, XRectangle * r, char *layout); void destroy_area(Area * a); void sel_area(Area * a); -void attach_frame_to_area(Area * a, Frame * f); -void detach_frame_from_area(Frame * f, int ignore_sel_and_destroy); void draw_area(Area * a); void hide_area(Area * a); void show_area(Area * a); Area *get_sel_area(); +void attach_frame_to_area(Area *a, Frame *f); +void detach_frame_from_area(Frame *f); /* client.c */ Client *alloc_client(Window w); @@ -273,6 +273,9 @@ void show_page(Page * p); void draw_page(Page * p); /* layout.c */ +Layout *get_layout(char *name); + +/* layoutdef.c */ void init_layouts(); /* wm.c */ @@ -285,4 +288,3 @@ int win_state(Window w); void handle_after_write(IXPServer * s, File * f); void detach(Frame * f, int client_destroyed); void set_client_state(Client * c, int state); -Layout *get_layout(char *name);