wmii

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

commit 0af8de3e858ffcebf56a318b14f8a5a94708b390
parent 8856b230b8996993a6236f5ce335815fe86b6e4c
Author: garbeam <garbeam@mmv.wmii.de>
Date:   Tue, 13 Dec 2005 17:10:22 +0200

changed column layout policy as follow, new column only possible if current column contains > 1 frame,
if last frame is detached, column gets detroyed


Diffstat:
cmd/wm/area.c | 2+-
cmd/wm/client.c | 4++--
cmd/wm/event.c | 18+++++++++---------
cmd/wm/frame.c | 6+++---
cmd/wm/layout_column.c | 77+++++++++++++++++++++++++++++++++++++++++++++++++----------------------------
cmd/wm/layout_float.c | 4++--
cmd/wm/page.c | 5+++--
cmd/wm/wm.c | 14+++++++-------
cmd/wmiibar.c | 2+-
cmd/wmiibar2.c | 2+-
cmd/wmiifs.c | 2+-
cmd/wmiimenu.c | 4++--
libcext/cext.h | 2+-
libcext/container.c | 6+++---
liblitz/geometry.c | 2+-
rc/wmiirc | 5++---
16 files changed, 88 insertions(+), 67 deletions(-)

diff --git a/cmd/wm/area.c b/cmd/wm/area.c @@ -15,7 +15,7 @@ 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); + size_t id = cext_sizeof_container(&p->areas); a->page = p; snprintf(buf, MAX_BUF, "/%s/layout/%d", p->file[P_PREFIX]->name, id); diff --git a/cmd/wm/client.c b/cmd/wm/client.c @@ -196,7 +196,7 @@ void draw_client(void *item, void *aux) if (!tabh) return; - size = cext_sizeof(&f->clients); + size = cext_sizeof_container(&f->clients); tw = f->rect.width; if (size) tw /= size; @@ -295,7 +295,7 @@ void attach_client(Client * c) { Area *a = 0; Frame *old = get_sel_frame(); - if (!cext_sizeof(&pages)) + if (!cext_sizeof_container(&pages)) alloc_page(); /* transient stuff */ a = get_sel_area(); diff --git a/cmd/wm/event.c b/cmd/wm/event.c @@ -63,7 +63,7 @@ static void handle_buttonpress(XEvent * e) Client *c; XButtonPressedEvent *ev = &e->xbutton; Frame *f = win_to_frame(ev->window); - fprintf(stderr, "%s\n", "handle_buttonpress"); + /*fprintf(stderr, "%s\n", "handle_buttonpress");*/ if (f) { handle_frame_buttonpress(ev, f); @@ -106,7 +106,7 @@ static void handle_configurerequest(XEvent * e) Frame *f = 0; - fprintf(stderr, "%s\n", "handle_configurerequest"); + /*fprintf(stderr, "%s\n", "handle_configurerequest");*/ c = win_to_client(ev->window); ev->value_mask &= ~CWSibling; @@ -173,7 +173,7 @@ static void handle_destroynotify(XEvent * e) { XDestroyWindowEvent *ev = &e->xdestroywindow; Client *c = win_to_client(ev->window); - fprintf(stderr, "%s\n", "handle_destroynotify"); + /*fprintf(stderr, "%s\n", "handle_destroynotify");*/ if (c) { c->destroyed = True; detach_client(c, False); @@ -183,7 +183,7 @@ static void handle_destroynotify(XEvent * e) static void handle_expose(XEvent * e) { static Frame *f; - fprintf(stderr, "%s\n", "handle_expose"); + /*fprintf(stderr, "%s\n", "handle_expose");*/ if (e->xexpose.count == 0) { f = win_to_frame(e->xbutton.window); if (f) @@ -197,7 +197,7 @@ static void handle_maprequest(XEvent * e) static XWindowAttributes wa; static Client *c; - fprintf(stderr, "%s\n", "handle_maprequest"); + /*fprintf(stderr, "%s\n", "handle_maprequest");*/ if (!XGetWindowAttributes(dpy, ev->window, &wa)) return; if (wa.override_redirect) { @@ -219,7 +219,7 @@ static void handle_motionnotify(XEvent * e) { Frame *f = win_to_frame(e->xmotion.window); Cursor cursor; - fprintf(stderr, "%s\n", "handle_motionnotify"); + /*fprintf(stderr, "%s\n", "handle_motionnotify");*/ if (f) { cursor = cursor_for_motion(f, e->xmotion.x, e->xmotion.y); if (cursor != f->cursor) { @@ -245,7 +245,7 @@ static void handle_unmapnotify(XEvent * e) { XUnmapEvent *ev = &e->xunmap; Client *c; - fprintf(stderr, "%s\n", "handle_unmapnotify"); + /*fprintf(stderr, "%s\n", "handle_unmapnotify");*/ handle_ignore_enternotify_crap(e); if ((c = win_to_client(ev->window))) { if (!c->ignore_unmap) @@ -263,7 +263,7 @@ static void handle_enternotify(XEvent * e) if ((ev->mode != NotifyNormal) || (ev->detail == NotifyInferior) || (ev->serial == ignore_enternotify_crap)) return; - fprintf(stderr, "%s\n", "handle_enternotify"); + /*fprintf(stderr, "%s\n", "handle_enternotify");*/ c = win_to_client(ev->window); if (c && c->frame) { Frame *old = get_sel_frame(); @@ -277,7 +277,7 @@ static void handle_enternotify(XEvent * e) static void handle_ignore_enternotify_crap(XEvent *e) { - fprintf(stderr, "%s\n", "handle_ignore_enternotify_crap"); + /*fprintf(stderr, "%s\n", "handle_ignore_enternotify_crap");*/ ignore_enternotify_crap = e->xany.serial; XSync(dpy, False); } diff --git a/cmd/wm/frame.c b/cmd/wm/frame.c @@ -278,7 +278,7 @@ void draw_frame(void *frame, void *aux) void handle_frame_buttonpress(XButtonEvent *e, Frame *f) { Align align; - size_t size = cext_sizeof(&f->clients); + size_t size = cext_sizeof_container(&f->clients); int bindex, cindex = e->x / (f->rect.width / size); /*fprintf(stderr, "%d (x) / %d (w) / %d (size) = %d (#c)\n", e->x, f->rect.width, size, cindex);*/ /*sel_client(cext_list_get_item(&f->clients, cindex));*/ @@ -338,7 +338,7 @@ static void select_client(void *obj, char *arg) { Client *c; Frame *f = obj; - size_t size = cext_sizeof(&f->clients); + size_t size = cext_sizeof_container(&f->clients); if (!f || !arg || size == 1) return; c = cext_stack_get_top_item(&f->clients); @@ -347,7 +347,7 @@ static void select_client(void *obj, char *arg) else if (!strncmp(arg, "next", 5)) c = cext_list_get_next_item(&f->clients, c); else - c = cext_list_get_item(&f->clients, blitz_strtonum(arg, 0, cext_sizeof(&f->clients) - 1)); + c = cext_list_get_item(&f->clients, blitz_strtonum(arg, 0, cext_sizeof_container(&f->clients) - 1)); sel_client(c); draw_frame(f, nil); } diff --git a/cmd/wm/layout_column.c b/cmd/wm/layout_column.c @@ -63,7 +63,7 @@ static void iter_arrange_column_frame(void *frame, void *height) { Frame *f = frame; Column *col = f->aux; - size_t size = cext_sizeof(&col->frames); + size_t size = cext_sizeof_container(&col->frames); unsigned int h = *(unsigned int *)height; int idx = cext_list_get_item_index(&col->frames, f) ; @@ -79,7 +79,7 @@ static void iter_arrange_column_frame(void *frame, void *height) static void iter_arrange_column(void *column, void *area) { Column *col = column; - size_t size = cext_sizeof(&col->frames); + size_t size = cext_sizeof_container(&col->frames); unsigned int height; if (size) { @@ -103,10 +103,7 @@ static void iter_attach_col(void *client, void *area) static void init_col(Area *a) { Acme *acme = cext_emallocz(sizeof(Acme)); - Column *col = cext_emallocz(sizeof(Column)); a->aux = acme; - col->rect = area_rect; - cext_attach_item(&acme->columns, col); cext_list_iterate(&a->clients, a, iter_attach_col); } @@ -136,6 +133,12 @@ static Bool attach_col(Area *a, Client *c) Column *col = get_sel_column(acme); Frame *f = get_sel_frame_of_area(a); + if (!col) { + col = cext_emallocz(sizeof(Column)); + col->rect = area_rect; + cext_attach_item(&acme->columns, col); + } + /* check for tabbing? */ if (f && (((char *) f->file[F_LOCKED]->content)[0] == '1')) f = 0; @@ -154,6 +157,24 @@ static Bool attach_col(Area *a, Client *c) return True; } +static void update_column_width(Area *a) +{ + Acme *acme = a->aux; + size_t size = cext_sizeof_container(&acme->columns); + unsigned int i, width; + + if (!size) + return; + + width = area_rect.width / size; + for (i = 0; i < size; i++) { + Column *col = cext_list_get_item(&acme->columns, i); + col->rect.x = i * width; + col->rect.width = width; + } + arrange_col(a); +} + static void detach_col(Area *a, Client *c, Bool unmap) { Acme *acme = a->aux; @@ -161,13 +182,19 @@ static void detach_col(Area *a, Client *c, Bool unmap) Column *col = f->aux; detach_client_from_frame(c, unmap); - if (!cext_sizeof(&f->clients)) { + if (!cext_sizeof_container(&f->clients)) { detach_frame_from_area(f); cext_detach_item(&acme->frames, f); cext_detach_item(&col->frames, f); destroy_frame(f); } - iter_arrange_column(col, a); + if (cext_sizeof_container(&col->frames)) + iter_arrange_column(col, a); + else { + cext_detach_item(&acme->columns, col); + free(col); + update_column_width(a); + } } static void iter_match_frame_horiz(void *frame, void *rect) @@ -184,8 +211,8 @@ static void drop_resize(Frame *f, XRectangle *new) Column *west = 0, *east = 0, *col = f->aux; Frame *north = 0, *south = 0; Acme *acme = f->area->aux; - size_t ncol = cext_sizeof(&acme->columns); - size_t nfr = cext_sizeof(&col->frames); + size_t ncol = cext_sizeof_container(&acme->columns); + size_t nfr = cext_sizeof_container(&col->frames); int colidx = cext_list_get_item_index(&acme->columns, col); int fidx = cext_list_get_item_index(&col->frames, f); @@ -330,7 +357,7 @@ static void select_frame(void *obj, char *arg) f = cext_stack_get_top_item(&col->frames); } else - f = cext_list_get_item(&col->frames, blitz_strtonum(arg, 0, cext_sizeof(&col->frames) - 1)); + f = cext_list_get_item(&col->frames, blitz_strtonum(arg, 0, cext_sizeof_container(&col->frames) - 1)); if (f && old != f) { select_col(f, True); draw_frame(old, nil); @@ -348,25 +375,19 @@ static void swap_frame(void *obj, char *arg) return; } -static void update_column_width(Area *a) -{ - Acme *acme = a->aux; - size_t size = 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->rect.x = i * width; - col->rect.width = width; - } - arrange_col(a); -} - static void new_col(void *obj, char *arg) { Area *a = obj; Acme *acme = a->aux; - Column *col = cext_emallocz(sizeof(Column)); + Column *col = get_sel_column(acme); + Frame *f = cext_stack_get_top_item(&col->frames); + + if (cext_sizeof_container(&col->frames) < 2) + return; + + cext_detach_item(&col->frames, f); + f->aux = col = cext_emallocz(sizeof(Column)); + cext_attach_item(&col->frames, f); cext_attach_item(&acme->columns, col); update_column_width(a); } @@ -378,10 +399,10 @@ static void destroy_col(void *obj, char *arg) Column *col = get_sel_column(acme); size_t size; - if (cext_sizeof(&acme->columns) > 1) { - while (cext_sizeof(&col->frames)) { + if (cext_sizeof_container(&acme->columns) > 1) { + while (cext_sizeof_container(&col->frames)) { Frame *f = cext_stack_get_top_item(&col->frames); - while ((size = cext_sizeof(&f->clients))) { + while ((size = cext_sizeof_container(&f->clients))) { detach_col(a, cext_stack_get_top_item(&f->clients), a->page != get_sel_page()); if (size == 1) break; diff --git a/cmd/wm/layout_float.c b/cmd/wm/layout_float.c @@ -93,7 +93,7 @@ static void detach_float(Area *a, Client *c, Bool unmap) { Frame *f = c->frame; detach_client_from_frame(c, unmap); - if (!cext_sizeof(&f->clients)) { + if (!cext_sizeof_container(&f->clients)) { detach_frame_from_area(f); cext_detach_item((Container *)a->aux, f); destroy_frame(f); @@ -136,7 +136,7 @@ static void select_frame(void *obj, char *arg) else if (!strncmp(arg, "next", 5)) f = cext_list_get_next_item(c, f); else - f = cext_list_get_item(c, blitz_strtonum(arg, 0, cext_sizeof(c) - 1)); + f = cext_list_get_item(c, blitz_strtonum(arg, 0, cext_sizeof_container(c) - 1)); if (old != f) { select_float(f, True); center_pointer(f); diff --git a/cmd/wm/page.c b/cmd/wm/page.c @@ -23,7 +23,7 @@ Page *alloc_page() { Page *p = cext_emallocz(sizeof(Page)); char buf[MAX_BUF], buf2[16]; - size_t id = cext_sizeof(&pages); + size_t id = cext_sizeof_container(&pages); snprintf(buf2, sizeof(buf2), "%d", id); p->areas.list = p->areas.stack = 0; @@ -170,6 +170,7 @@ static void select_area(void *obj, char *arg) else if (!strncmp(arg, "next", 5)) a = cext_list_get_next_item(&p->areas, a); else - a = cext_list_get_item(&p->areas, blitz_strtonum(arg, 0, cext_sizeof(&p->areas) - 1)); + a = cext_list_get_item(&p->areas, blitz_strtonum(arg, 0, cext_sizeof_container(&p->areas) - 1)); sel_area(a); + invoke_wm_event(def[WM_EVENT_PAGE_UPDATE]); } diff --git a/cmd/wm/wm.c b/cmd/wm/wm.c @@ -198,7 +198,7 @@ static Page *xy_to_pager_page(int x, int y) XRectangle r; Page *p; - if (!cext_sizeof(&pages)) + if (!cext_sizeof_container(&pages)) return nil; blitz_getbasegeometry(&pages, &size, &cols, &rows); dx = (cols - 1) * GAP; /* GAPpx space */ @@ -241,7 +241,7 @@ static void pager(void *obj, char *arg) XEvent ev; int i; - if (!cext_sizeof(&pages)) + if (!cext_sizeof_container(&pages)) return; XClearWindow(dpy, transient); @@ -261,7 +261,7 @@ static void pager(void *obj, char *arg) case KeyPress: XUnmapWindow(dpy, transient); if ((i = handle_kpress(&ev.xkey)) != -1) - if (i < cext_sizeof(&pages)) + if (i < cext_sizeof_container(&pages)) sel_page(cext_list_get_item(&pages, i)); XUngrabKeyboard(dpy, CurrentTime); return; @@ -284,7 +284,7 @@ static void draw_detached_clients() unsigned int i, ic, ir, tw, th, rows, cols, size; int dx, dy; - if (!cext_sizeof(&detached)) + if (!cext_sizeof_container(&detached)) return; blitz_getbasegeometry(&detached, &size, &cols, &rows); dx = (cols - 1) * GAP; /* GAPpx space */ @@ -328,7 +328,7 @@ static void detached_clients(void *obj, char *arg) { XEvent ev; int i, n; - size_t size = cext_sizeof(&detached); + size_t size = cext_sizeof_container(&detached); Client *c; if (!size) @@ -389,7 +389,7 @@ static void _close_client(void *obj, char *arg) static void _attach_client(void *obj, char *arg) { - if (cext_sizeof(&detached)) { + if (cext_sizeof_container(&detached)) { Client *c = cext_stack_get_top_item(&detached); cext_detach_item(&detached, c); attach_client(c); @@ -413,7 +413,7 @@ static void _select_page(void *obj, char *arg) else if (!strncmp(arg, "next", 5)) p = cext_list_get_next_item(&pages, p); else - p = cext_list_get_item(&pages, blitz_strtonum(arg, 0, cext_sizeof(&pages) - 1)); + p = cext_list_get_item(&pages, blitz_strtonum(arg, 0, cext_sizeof_container(&pages) - 1)); sel_page(p); } diff --git a/cmd/wmiibar.c b/cmd/wmiibar.c @@ -198,7 +198,7 @@ static void draw() unsigned int i, w, xoff = 0; unsigned expandable = 0; char buf[32]; - size_t size = cext_sizeof(&items); + size_t size = cext_sizeof_container(&items); if (!size) return; diff --git a/cmd/wmiibar2.c b/cmd/wmiibar2.c @@ -194,7 +194,7 @@ static Bool make_qid(Qid * dir, char *wname, Qid * new) } /* check if wname is a number, otherwise file not found */ idx = (u16) cext_strtonum(wname, 1, 0xffff, &errstr); - if (errstr || cext_sizeof(&items) < idx) + if (errstr || cext_sizeof_container(&items) < idx) return False; /* found */ new->path = make_qpath(Ditem, idx, NONE); diff --git a/cmd/wmiifs.c b/cmd/wmiifs.c @@ -161,7 +161,7 @@ static Bind *fd_to_bind(int fd, int *client_fd) File *f = fd_to_file(ixps, fd); unsigned int i, j; Bind *b; - size_t size = cext_sizeof(&bindings); + size_t size = cext_sizeof_container(&bindings); if (!f) return nil; diff --git a/cmd/wmiimenu.c b/cmd/wmiimenu.c @@ -236,7 +236,7 @@ static int update_items(char *pattern) p->parent = f; /* restore HACK */ } - size = cext_sizeof(&items); + size = cext_sizeof_container(&items); update_offsets(); return size; } @@ -316,7 +316,7 @@ static void handle_kpress(XKeyEvent * e) char buf[32]; int num; static char text[4096]; - size_t len = 0, size = cext_sizeof(&items); + size_t len = 0, size = cext_sizeof_container(&items); File *selitem = cext_list_get_item(&items, sel); File *hist = cext_stack_get_top_item(&history); diff --git a/libcext/cext.h b/libcext/cext.h @@ -35,7 +35,7 @@ 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_swap_items(Container *c, void *item1, void *item2); -size_t cext_sizeof(Container *c); +size_t cext_sizeof_container(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); diff --git a/libcext/container.c b/libcext/container.c @@ -92,7 +92,7 @@ void *cext_find_item(Container *c, void *pattern, int (*comp)(void *pattern, voi return i ? i->item : nil; } -size_t cext_sizeof(Container *c) +size_t cext_sizeof_container(Container *c) { size_t idx = 0; CItem *i; @@ -202,7 +202,7 @@ int cext_list_get_item_index(Container *c, void *item) void *cext_list_get_next_item(Container *c, void *item) { - size_t size = cext_sizeof(c); + size_t size = cext_sizeof_container(c); int idx = cext_list_get_item_index(c, item); if (idx == -1) return nil; @@ -215,7 +215,7 @@ void *cext_list_get_next_item(Container *c, void *item) void *cext_list_get_prev_item(Container *c, void *item) { - size_t size = cext_sizeof(c); + size_t size = cext_sizeof_container(c); int idx = cext_list_get_item_index(c, item); if (idx == -1) return nil; diff --git a/liblitz/geometry.c b/liblitz/geometry.c @@ -203,7 +203,7 @@ void blitz_getbasegeometry(Container *c, unsigned int *size, unsigned int *cols, { float sq, dummy; - *size = cext_sizeof(c); + *size = cext_sizeof_container(c); sq = sqrt(*size); if (modff(sq, &dummy) < 0.5) *rows = floor(sq); diff --git a/rc/wmiirc b/rc/wmiirc @@ -142,7 +142,7 @@ kbind normal $MODKEY-t 'extern xterm ''+sb'' -bg ''#000000'' -fg ''#ffffff'' -cr 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-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-c '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' kbind normal $MODKEY-S-f 'wmiir write /wm/sel/layout/sel/name float' @@ -157,11 +157,10 @@ kbind normal $MODKEY-$SOUTHKEY 'wmiir write /wm/sel/layout/sel/ctl ''select next kbind normal $MODKEY-$NORTHKEY 'wmiir write /wm/sel/layout/sel/ctl ''select prev''' kbind normal $MODKEY-S-$WESTKEY 'wmiir write /wm/ctl ''select prev''' kbind normal $MODKEY-S-$EASTKEY 'wmiir write /wm/ctl ''select next''' -kbind normal $MODKEY-Space 'wmiir write /wm/sel/ctl ''select next''' +kbind normal $MODKEY-space 'wmiir write /wm/sel/ctl ''select next''' kbind normal $MODKEY-S-Tab 'wmiir write /wm/sel/layout/sel/frame/sel/ctl ''select next''' kbind normal $MODKEY-S-$SOUTHKEY 'wmiir write /wm/sel/layout/sel/frame/sel/ctl ''select next''' kbind normal $MODKEY-S-$NORTHKEY 'wmiir write /wm/sel/layout/sel/frame/sel/ctl ''select prev''' -kbind normal $MODKEY-space 'wmiir write /wm/sel/ctl ''select toggled''' kbind normal $MODKEY-S-p 'wmiir write /wm/ctl pager' for(i in 0 1 2 3 4 5 6 7 8 9) { kbind normal $MODKEY-S-$i 'wmiir write /wm/ctl ''select '^$i^''''