wmii

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

commit c3578257f838abcde216853334fe803849ab9dfc
parent 0ed70ce9532bbb9b270ee5556704a80dc66a661e
Author: garbeam <garbeam@mmv.wmii.de>
Date:   Tue, 13 Dec 2005 02:10:28 +0200

dynamic bar area reservation implemented, yippie


Diffstat:
cmd/wm/area.c | 14+-------------
cmd/wm/layout_column.c | 33+++++++++++++--------------------
cmd/wm/page.c | 4++--
cmd/wm/wm.c | 93++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------
cmd/wm/wm.h | 6+++---
cmd/wmiibar.c | 12+++++++-----
cmd/wmiimenu.c | 3+--
liblitz/geometry.c | 3+--
rc/wmiirc | 16+++++++++++++++-
9 files changed, 112 insertions(+), 72 deletions(-)

diff --git a/cmd/wm/area.c b/cmd/wm/area.c @@ -11,13 +11,12 @@ static void handle_after_write_area(IXPServer * s, File * f); -Area *alloc_area(Page *p, XRectangle * r, char *layout) +Area *alloc_area(Page *p, char *layout) { char buf[MAX_BUF]; Area *a = (Area *) cext_emallocz(sizeof(Area)); size_t id = cext_sizeof(&p->areas); - a->rect = *r; a->page = p; snprintf(buf, MAX_BUF, "/%s/layout/%d", p->file[P_PREFIX]->name, id); a->file[A_PREFIX] = ixp_create(ixps, buf); @@ -29,9 +28,6 @@ Area *alloc_area(Page *p, XRectangle * r, char *layout) snprintf(buf, MAX_BUF, "/%s/layout/%d/ctl", p->file[P_PREFIX]->name, id); a->file[A_CTL] = ixp_create(ixps, buf); a->file[A_CTL]->after_write = handle_after_write_area; - snprintf(buf, MAX_BUF, "/%s/layout/%d/geometry", p->file[P_PREFIX]->name, id); - a->file[A_GEOMETRY] = ixp_create(ixps, buf); - a->file[A_GEOMETRY]->after_write = handle_after_write_area; snprintf(buf, MAX_BUF, "/%s/layout/%d/name", p->file[P_PREFIX]->name, id); a->file[A_LAYOUT] = wmii_create_ixpfile(ixps, buf, layout); a->file[A_LAYOUT]->after_write = handle_after_write_area; @@ -127,14 +123,6 @@ static void iter_after_write_area(void *item, void *aux) } draw_page(a->page); return; - } else if (file == a->file[A_GEOMETRY]) { - char *geom = a->file[A_GEOMETRY]->content; - if (geom && strrchr(geom, ',')) { - blitz_strtorect(&rect, &a->rect, geom); - a->layout->arrange(a); - draw_page(a->page); - } - return; } } diff --git a/cmd/wm/layout_column.c b/cmd/wm/layout_column.c @@ -19,7 +19,6 @@ struct Acme { }; struct Column { - Bool refresh; Container frames; XRectangle rect; }; @@ -68,14 +67,12 @@ static void iter_arrange_column_frame(void *frame, void *height) unsigned int h = *(unsigned int *)height; int idx = cext_list_get_item_index(&col->frames, f) ; - if (col->refresh) { - f->rect = col->rect; - f->rect.y = idx * h; - if (idx + 1 == size) - f->rect.height = f->area->rect.height - f->rect.y; - else - f->rect.height = h; - } + f->rect = col->rect; + f->rect.y = area_rect.y + idx * h; + if (idx + 1 == size) + f->rect.height = area_rect.height - f->rect.y + area_rect.y; + else + f->rect.height = h; resize_frame(f, &f->rect, 0); } @@ -86,9 +83,8 @@ static void iter_arrange_column(void *column, void *area) unsigned int height; if (size) { - height= ((Area *)area)->rect.height / size; + height= area_rect.height / size; cext_list_iterate(&col->frames, &height, iter_arrange_column_frame); - col->refresh = False; } } @@ -109,7 +105,7 @@ static void init_col(Area *a) Acme *acme = cext_emallocz(sizeof(Acme)); Column *col = cext_emallocz(sizeof(Column)); a->aux = acme; - col->rect = a->rect; + col->rect = area_rect; cext_attach_item(&acme->columns, col); cext_list_iterate(&a->clients, a, iter_attach_col); } @@ -153,8 +149,7 @@ static Bool attach_col(Area *a, Client *c) attach_client_to_frame(f, c); if (a->page == get_sel_page()) XMapWindow(dpy, f->win); - col->refresh = True; - arrange_col(a); + iter_arrange_column(col, a); select_col(f, True); return True; } @@ -172,8 +167,7 @@ static void detach_col(Area *a, Client *c, Bool unmap) cext_detach_item(&col->frames, f); destroy_frame(f); } - col->refresh = True; - arrange_col(a); + iter_arrange_column(col, a); } static void iter_match_frame_horiz(void *frame, void *rect) @@ -270,9 +264,9 @@ static void drop_moving(Frame *f, XRectangle *new, XPoint *pt) cext_detach_item(&src->frames, f); cext_attach_item(&tgt->frames, f); f->aux = tgt; - tgt->refresh = src->refresh = True; cext_stack_top_item(&acme->columns, tgt); - arrange_col(f->area); + iter_arrange_column(tgt, f->area); + iter_arrange_column(src, f->area); } } @@ -358,11 +352,10 @@ static void update_column_width(Area *a) { Acme *acme = a->aux; size_t size = cext_sizeof(&acme->columns); - unsigned int i, width = a->rect.width / cext_sizeof(&acme->columns); + unsigned int i, width = area_rect.width / cext_sizeof(&acme->columns); for (i = 0; i < size; i++) { Column *col = cext_list_get_item(&acme->columns, i); - col->refresh = True; col->rect.x = i * width; col->rect.width = width; } diff --git a/cmd/wm/page.c b/cmd/wm/page.c @@ -39,8 +39,8 @@ Page *alloc_page() snprintf(buf, sizeof(buf), "/%d/ctl", id); p->file[P_CTL] = ixp_create(ixps, buf); p->file[P_CTL]->after_write = handle_after_write_page; - alloc_area(p, &rect, "float"); - alloc_area(p, &rect, def[WM_LAYOUT]->content); + alloc_area(p, "float"); + alloc_area(p, def[WM_LAYOUT]->content); cext_attach_item(&pages, p); def[WM_SEL_PAGE]->content = p->file[P_PREFIX]->content; invoke_wm_event(def[WM_EVENT_PAGE_UPDATE]); diff --git a/cmd/wm/wm.c b/cmd/wm/wm.c @@ -20,15 +20,16 @@ static XRectangle initial_rect; static int other_wm_running; static int (*x_error_handler) (Display *, XErrorEvent *); -static void new_page(void *obj, char *cmd); -static void _select_page(void *obj, char *cmd); -static void _destroy_page(void *obj, char *cmd); -static void quit(void *obj, char *cmd); -static void _attach_client(void *obj, char *cmd); -static void _detach_client(void *obj, char *cmd); -static void _close_client(void *obj, char *cmd); -static void pager(void *obj, char *cmd); -static void detached_clients(void *obj, char *cmd); +static void new_page(void *obj, char *arg); +static void _select_page(void *obj, char *arg); +static void _destroy_page(void *obj, char *arg); +static void quit(void *obj, char *arg); +static void _attach_client(void *obj, char *arg); +static void _detach_client(void *obj, char *arg); +static void _close_client(void *obj, char *arg); +static void pager(void *obj, char *arg); +static void detached_clients(void *obj, char *arg); +static void reserve_area(void *obj, char *arg); /* action table for /ctl namespace */ Action wm_acttbl[] = { @@ -40,7 +41,8 @@ Action wm_acttbl[] = { {"close", _close_client}, {"quit", quit}, {"pager", pager}, - {"detached clients", detached_clients}, + {"detached_clients", detached_clients}, + {"reserve_area", reserve_area}, {0, 0} }; @@ -81,7 +83,7 @@ void run_action(File * f, void *obj, Action * acttbl) " or invalid ctl device\n", (char *) f->content); } -static void quit(void *obj, char *cmd) +static void quit(void *obj, char *arg) { ixps->runlevel = SHUTDOWN; } @@ -234,7 +236,7 @@ static int handle_kpress(XKeyEvent * e) return -1; } -static void pager(void *obj, char *cmd) +static void pager(void *obj, char *arg) { XEvent ev; int i; @@ -314,7 +316,15 @@ static void draw_detached_clients() } } -static void detached_clients(void *obj, char *cmd) +static void reserve_area(void *obj, char *arg) +{ + if (arg && strrchr(arg, ',')) { + XRectangle r; + blitz_strtorect(&rect, &r, arg); + } +} + +static void detached_clients(void *obj, char *arg) { XEvent ev; int i, n; @@ -370,14 +380,14 @@ static void detached_clients(void *obj, char *cmd) } } -static void _close_client(void *obj, char *cmd) +static void _close_client(void *obj, char *arg) { Frame *f = get_sel_frame(); if (f) close_client(cext_stack_get_top_item(&f->clients)); } -static void _attach_client(void *obj, char *cmd) +static void _attach_client(void *obj, char *arg) { if (cext_sizeof(&detached)) { Client *c = cext_stack_get_top_item(&detached); @@ -386,35 +396,35 @@ static void _attach_client(void *obj, char *cmd) } } -static void _detach_client(void *obj, char *cmd) +static void _detach_client(void *obj, char *arg) { Client *c = get_sel_client(); if (c) detach_client(c, False); } -static void _select_page(void *obj, char *cmd) +static void _select_page(void *obj, char *arg) { Page *p = get_sel_page(); - if (!p || !cmd) + if (!p || !arg) return; - if (!strncmp(cmd, "prev", 5)) + if (!strncmp(arg, "prev", 5)) p = cext_list_get_prev_item(&pages, p); - else if (!strncmp(cmd, "next", 5)) + else if (!strncmp(arg, "next", 5)) p = cext_list_get_next_item(&pages, p); else - p = cext_list_get_item(&pages, blitz_strtonum(cmd, 0, cext_sizeof(&pages) - 1)); + p = cext_list_get_item(&pages, blitz_strtonum(arg, 0, cext_sizeof(&pages) - 1)); sel_page(p); } -static void _destroy_page(void *obj, char *cmd) +static void _destroy_page(void *obj, char *arg) { Page *p = get_sel_page(); if (p) destroy_page(p); } -static void new_page(void *obj, char *cmd) +static void new_page(void *obj, char *arg) { Page *p = get_sel_page(); if (p) @@ -527,6 +537,30 @@ int win_state(Window w) return res; } +static void iter_update_area(void *area, void *aux) +{ + Area *a = area; + a->layout->arrange(a); +} + +static void iter_update_page(void *page, void *aux) +{ + Page *p = page; + cext_list_iterate(&p->areas, nil, iter_update_area); +} + +void handle_before_read(IXPServer *s, File *f) +{ + char buf[64]; + if (f == def[WM_AREA_GEOMETRY]) { + snprintf(buf, 64, "%d,%d,%d,%d", area_rect.x, area_rect.y, area_rect.width, area_rect.height); + if (f->content) + free(f->content); + f->content = cext_estrdup(buf); + f->size = strlen(buf); + } +} + void handle_after_write(IXPServer * s, File * f) { if (f == def[WM_CTL]) @@ -544,7 +578,14 @@ void handle_after_write(IXPServer * s, File * f) XFreeFont(dpy, font); font = blitz_getfont(dpy, def[WM_FONT]->content); } - + else if (f == def[WM_AREA_GEOMETRY]) { + char *geom = def[WM_AREA_GEOMETRY]->content; + if (geom && strrchr(geom, ',')) { + area_rect = rect; + blitz_strtorect(&rect, &area_rect, geom); + cext_list_iterate(&pages, nil, iter_update_page); + } + } check_event(0); } @@ -580,6 +621,9 @@ static void init_default() def[WM_DETACHED_CLIENT] = ixp_create(ixps, "/detached/client"); def[WM_TRANS_COLOR] = wmii_create_ixpfile(ixps, "/default/transcolor", BLITZ_SEL_FG_COLOR); def[WM_TRANS_COLOR]->after_write = handle_after_write; + def[WM_AREA_GEOMETRY] = wmii_create_ixpfile(ixps, "/default/area/geometry", BLITZ_SEL_FG_COLOR); + def[WM_AREA_GEOMETRY]->after_write = handle_after_write; + def[WM_AREA_GEOMETRY]->before_read = handle_before_read; def[WM_SEL_BG_COLOR] = wmii_create_ixpfile(ixps, "/default/sstyle/bgcolor", BLITZ_SEL_BG_COLOR); def[WM_SEL_FG_COLOR] = wmii_create_ixpfile(ixps, "/default/sstyle/fgcolor", BLITZ_SEL_FG_COLOR); def[WM_SEL_BORDER_COLOR] = wmii_create_ixpfile(ixps, "/default/sstyle/fgcolor", BLITZ_SEL_BORDER_COLOR); @@ -624,6 +668,7 @@ static void init_screen() rect.x = rect.y = 0; rect.width = DisplayWidth(dpy, screen_num); rect.height = DisplayHeight(dpy, screen_num); + area_rect = rect; wa.override_redirect = 1; wa.background_pixmap = ParentRelative; diff --git a/cmd/wm/wm.h b/cmd/wm/wm.h @@ -24,7 +24,6 @@ enum { A_FRAME_PREFIX, A_SEL_FRAME, A_CTL, - A_GEOMETRY, A_LAYOUT, A_LAST }; @@ -66,6 +65,7 @@ enum { WM_DETACHED_FRAME, WM_DETACHED_CLIENT, WM_TRANS_COLOR, + WM_AREA_GEOMETRY, WM_SEL_BG_COLOR, WM_SEL_BORDER_COLOR, WM_SEL_FG_COLOR, @@ -126,7 +126,6 @@ struct Area { Page *page; Layout *layout; Container clients; - XRectangle rect; void *aux; /* free pointer */ File *file[A_LAST]; }; @@ -164,6 +163,7 @@ int screen_num; Window root; Window transient; XRectangle rect; +XRectangle area_rect; Container detached; Container pages; Container areas; @@ -201,7 +201,7 @@ File *def[WM_LAST]; unsigned int valid_mask, num_lock_mask; /* area.c */ -Area *alloc_area(Page *p, XRectangle * r, char *layout); +Area *alloc_area(Page *p, char *layout); void destroy_area(Area * a); void sel_area(Area * a); void draw_area(Area * a); diff --git a/cmd/wmiibar.c b/cmd/wmiibar.c @@ -26,6 +26,7 @@ typedef enum { B_FG_COLOR, B_BORDER_COLOR, B_BG_COLOR, + B_EVENT_RESIZE, B_LAST } BarIndexes; @@ -371,6 +372,8 @@ static void update_geometry() XFreePixmap(dpy, pmap); pmap = XCreatePixmap(dpy, win, brect.width, brect.height, DefaultDepth(dpy, screen_num)); XSync(dpy, False); + if (file[B_EVENT_RESIZE]->content) + wmii_spawn(dpy, file[B_EVENT_RESIZE]->content); } static void handle_after_write(IXPServer * s, File * f) @@ -421,13 +424,11 @@ static void handle_before_read(IXPServer * s, File * f) { char buf[64]; if (f == file[B_GEOMETRY]) { + snprintf(buf, 64, "%d,%d,%d,%d", brect.x, brect.y, brect.width, brect.height); if (f->content) free(f->content); - if (align == SOUTH) - f->content = strdup("south"); - else - f->content = strdup("north"); - f->size = strlen(f->content); + f->content = cext_estrdup(buf); + f->size = strlen(buf); } else if (f == file[B_NEW]) { snprintf(buf, sizeof(buf), "%d", id++); if (f->content) @@ -498,6 +499,7 @@ int main(int argc, char *argv[]) file[B_GEOMETRY]->before_read = handle_before_read; file[B_GEOMETRY]->after_write = handle_after_write; file[B_EXPANDABLE] = ixp_create(ixps, "/expandable"); + file[B_EVENT_RESIZE] = ixp_create(ixps, "/event/resize"); wa.override_redirect = 1; wa.background_pixmap = ParentRelative; diff --git a/cmd/wmiimenu.c b/cmd/wmiimenu.c @@ -517,8 +517,7 @@ static void handle_before_read(IXPServer * s, File * f) char buf[64]; if (f != files[M_GEOMETRY]) return; - snprintf(buf, sizeof(buf), "%d,%d,%d,%d", mrect.x, mrect.y, - mrect.width, mrect.height); + snprintf(buf, sizeof(buf), "%d,%d,%d,%d", mrect.x, mrect.y, mrect.width, mrect.height); if (f->content) free(f->content); f->content = strdup(buf); diff --git a/liblitz/geometry.c b/liblitz/geometry.c @@ -196,8 +196,7 @@ int blitz_distance(XRectangle * origin, XRectangle * target) int tx = target->x + target->width / 2; int ty = target->y + target->height / 2; - return (int) sqrt((double) (((ox - tx) * (ox - tx)) + - ((oy - ty) * (oy - ty)))); + return (int) sqrt((double) (((ox - tx) * (ox - tx)) + ((oy - ty) * (oy - ty)))); } void blitz_getbasegeometry(Container *c, unsigned int *size, unsigned int *cols, unsigned int *rows) diff --git a/rc/wmiirc b/rc/wmiirc @@ -2,6 +2,9 @@ # configure wmii TAB=0 +BAR_ALIGN=south +#BAR_ALIGN=north + SEL_BG_COLOR='#002200' SEL_FG_COLOR='#66ff00' @@ -74,6 +77,16 @@ fn barsucks { wmiir write /bar/$1/b5press 'wmiir write /wm/ctl ''select next''' } +wmiir write /bar/geometry $BAR_ALIGN +if (~ $BAR_ALIGN south) { + wmiir write /bar/event/resize \ + 'val=`{wmiir read /bar/geometry|sed ''s/,/ /g''|awk ''{print $4}''} wmiir write /wm/default/area/geometry ''+0,+0,+0,-''^$val' +} +if not { + wmiir write /bar/event/resize \ + 'val=`{wmiir read /bar/geometry|sed ''s/,/ /g''|awk ''{print $4}''} wmiir write /wm/default/area/geometry ''+0,+''^$val^'',+0,-''^$val' +} + wmiir write /bar/ctl reset wmiir write /bar/font $FONT wmiir write /bar/fgcolor $NORM_FG_COLOR @@ -128,7 +141,7 @@ kbind normal $MODKEY-C-w,y wmiirc kbind normal $MODKEY-t 'extern xterm ''+sb'' -bg ''#000000'' -fg ''#ffffff'' -cr ''#ffffff'' -sl 4000 -fn -artwiz-smoothansi-*-*-*-*-*-*-*-*-*-*-*-*' kbind normal $MODKEY-d 'wmiir write /wm/ctl detach' kbind normal $MODKEY-a 'wmiir write /wm/ctl attach' -kbind normal $MODKEY-S-a 'wmiir write /wm/ctl ''detached clients''' +kbind normal $MODKEY-S-a 'wmiir write /wm/ctl detached_clients' kbind normal $MODKEY-S-c 'wmiir write /wm/sel/layout/1/geometry 0,0,east,south-20; wmiir write /wm/sel/layout/1/name column' kbind normal $MODKEY-S-n 'wmiir write /wm/sel/layout/sel/ctl new' kbind normal $MODKEY-S-d 'wmiir write /wm/sel/layout/sel/ctl destroy' @@ -159,6 +172,7 @@ selstyle /keys/box kmode normal # WMIMENU CONFIGURATION +wmiir write /menu/geometry $BAR_ALIGN items actions $WMII_CONFDIR:$HOME/.wmii-3 wmiir create /menu/items/actions/rmpage 'wmiir write /wm/ctl destroy' items programs $OLD_PATH