wmii

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

commit 2313fd952dff5957f807af711e88df0c47a3c393
parent 74503fd53bb6f2a6afc80caefb4e115ee209f827
Author: Anselm R. Garbe <garbeam@wmii.de>
Date:   Thu, 26 Jan 2006 19:29:49 +0200

proceeded with cleanups


Diffstat:
cmd/wm/client.c | 54+++++++++++++++++++++++++++++++++++++++++++++++++-----
cmd/wm/column.c | 258++++++++++++++++++++-----------------------------------------------------------
cmd/wm/page.c | 95+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
cmd/wm/wm.c | 1+
cmd/wm/wm.h | 8+++++++-
rc/wmiirc | 44+++++++++++++++++++++-----------------------
6 files changed, 238 insertions(+), 222 deletions(-)

diff --git a/cmd/wm/client.c b/cmd/wm/client.c @@ -13,6 +13,14 @@ static void handle_before_read_client(IXPServer * s, File * file); static void handle_after_write_client(IXPServer * s, File * file); +static void max_client(void *obj, char *arg); + +/* action table for /?/ namespace */ +Action client_acttbl[] = { + {"max", max_client}, + {0, 0} +}; + void attach_client_to_array(Client *c, Client **array, size_t *size) { @@ -93,6 +101,9 @@ alloc_client(Window w, XWindowAttributes *wa) c->file[C_GEOMETRY] = ixp_create(ixps, buf); c->file[C_GEOMETRY]->before_read = handle_before_read_client; c->file[C_GEOMETRY]->after_write = handle_after_write_client; + snprintf(buf, MAX_BUF, "/detached/%d/ctl", id); + c->file[C_CTL] = ixp_create(ixps, buf); + c->file[C_CTL]->after_write = handle_after_write_client; id++; /* client.frame */ @@ -422,10 +433,14 @@ attach_client(Client *c) reparent_client(c, c->frame.win, c->rect.x, c->rect.y); c->page = p; - if(p->is_column) + if(p->is_column) { + wmii_move_ixpfile(c->file[C_PREFIX], p->file[P_COLUMN_PREFIX]); attach_column(c); - else + } + else { + wmii_move_ixpfile(c->file[C_PREFIX], p->file[P_FLOATING_PREFIX]); attach_client_to_array(c, p->floating, &p->floatingsz); + } map_client(c); focus_client(c); @@ -435,6 +450,7 @@ attach_client(Client *c) void detach_client(Client *c, Bool unmap) { + wmii_move_ixpfile(c->file[C_PREFIX], def[WM_DETACHED_PREFIX]); if(c->column) detach_column(c); else { @@ -456,9 +472,8 @@ detach_client(Client *c, Bool unmap) } Client * -sel_client() +sel_client_of_page(Page *p) { - Page *p = page ? page[sel_page] : nil; if(p) { if(p->is_column) { Column *col = p->column[p->sel_column]; @@ -471,6 +486,12 @@ sel_client() } Client * +sel_client() +{ + return page ? sel_client_of_page(page[sel_page]) : nil; +} + +Client * win_to_frame(Window w) { size_t i; @@ -598,7 +619,11 @@ handle_after_write_client(IXPServer *s, File *file) for(i = 0; (i < clientsz) && client[i]; i++) { Client *c = client[i]; - if(file == c->file[C_TAB] || file == c->file[C_BORDER] + if(file == c->file[C_CTL]) { + run_action(file, c, client_acttbl); + return; + } + else if(file == c->file[C_TAB] || file == c->file[C_BORDER] || file == c->file[C_HANDLE_INC]) { resize_client(c, &c->frame.rect, nil); @@ -615,3 +640,22 @@ handle_after_write_client(IXPServer *s, File *file) } } } + +static void +max_client(void *obj, char *arg) +{ + Client *c = obj; + + if(c->maximized) { + /* XXX: do we really need this ? */ c->frame.rect = c->frame.revert; + resize_client(c, &c->frame.revert, nil); + } + else { + c->frame.revert = c->frame.rect; + c->frame.rect = c->column ? c->column->rect : rect; + XRaiseWindow(dpy, c->frame.win); + resize_client(c, &c->frame.rect, nil); + } + c->maximized = !c->maximized; +} + diff --git a/cmd/wm/column.c b/cmd/wm/column.c @@ -38,8 +38,8 @@ detach_column_from_array(Column *col, Column **array) array[i] = nil; } -static void -xarrange_column(Page *p, Column *col) +void +arrange_column(Page *p, Column *col) { size_t i, nc; unsigned int h; @@ -62,11 +62,11 @@ xarrange_column(Page *p, Column *col) } void -arrange_column(Page *p) +arrange_page(Page *p) { size_t i; for(i = 0; (i < p->columnsz) && p->column[i]; i++) - xarrange_column(p, p->column[i]); + arrange_column(p, p->column[i]); } void @@ -84,7 +84,7 @@ attach_column(Client *c) c->column = col; attach_client_to_array(c, col->client, &col->clientsz); - xarrange_column(p, col); + arrange_column(p, col); } static void @@ -103,7 +103,7 @@ update_column_width(Page *p) p->column[i]->rect.x = i * width; p->column[i]->rect.width = width; } - arrange_column(p); + arrange_page(p); } void @@ -119,7 +119,7 @@ detach_column(Client *c) update_column_width(p); } else - xarrange_column(p, col); + arrange_column(p, col); } static void @@ -205,8 +205,8 @@ drop_moving(Client *c, XRectangle *new, XPoint * pt) return; detach_client_from_array(c, src->client); attach_client_to_array(c, tgt->client, &tgt->clientsz); - xarrange_column(p, src); - xarrange_column(p, tgt); + arrange_column(p, src); + arrange_column(p, tgt); } else { for(i = 0; (i < src->clientsz) && src->client[i] && !blitz_ispointinrect(pt->x, pt->y, &src->client[i]->frame.rect); i++); @@ -215,7 +215,7 @@ drop_moving(Client *c, XRectangle *new, XPoint * pt) for(j = 0; (j < src->clientsz) && src->client[j] && (src->client[j] != c); j++); src->client[j] = src->client[i]; src->client[i] = c; - xarrange_column(p, src); + arrange_column(p, src); } } focus_client(c); @@ -232,198 +232,70 @@ resize_column(Client *c, XRectangle *r, XPoint *pt) drop_resize(c, r); } -/* -static void select_frame(void *obj, char *arg); -static void max_frame(void *obj, char *arg); -static void swap_frame(void *obj, char *arg); -static void new_column(void *obj, char *arg); - -static Action lcol_acttbl[] = { - {"select", select_frame}, - {"swap", swap_frame}, - {"new", new_column}, - {"max", max_frame}, - {0, 0} -}; - - -static void -max_frame(void *obj, char *arg) +void +select_column(Client *c, char *arg) { - Layout *l = obj; - Acme *acme = l->aux; - Column *c = acme->sel; - Cell *cell; - Frame *f; - - if(!c) - return; - - cell = c->sel; - if(!cell) - return; + Page *p = c->page; + Column *col = c->column; + size_t i; - f = cell->frame; - if(f->maximized) { - f->rect = f->old; - resize_frame(f, &f->old, nil); - f->maximized = False; + for(i = 0; (i < col->clientsz) && col->client[i] && (col->client[i] != c); i++); + if(!strncmp(arg, "prev", 5)) { + if(!i) + for(i = 0; (i < col->clientsz) && col->client[i]; i++); + focus_client(col->client[i - 1]); + return; + } else if(!strncmp(arg, "next", 5)) { + if(col->client[i + 1]) + focus_client(col->client[i + 1]); + else + focus_client(col->client[0]); + return; } - else { - f->old = f->rect; - f->rect = c->rect; - XRaiseWindow(dpy, f->win); - resize_frame(f, &c->rect, nil); - f->maximized = True; + + for(i = 0; (i < p->columnsz) && p->column[i] && (p->column[i] != col); i++); + if(!strncmp(arg, "west", 5)) { + if(!i) + for(i = 0; (i < p->columnsz) && p->column[i]; i++); + col = p->column[i - 1]; + } else if(!strncmp(arg, "east", 5)) { + if(p->column[i + 1]) + col = p->column[i + 1]; + else + col = p->column[0]; + } else { + const char *errstr; + for(i = 0; (i < p->columnsz) && p->column[i]; i++); + i = cext_strtonum(arg, 0, i - 1, &errstr); + if(errstr) + return; + col = p->column[i]; } + focus_client(col->client[col->sel]); } -static void -select_frame(void *obj, char *arg) -{ - Layout *l = obj; - Acme *acme = l->aux; - Column *c, *column = acme->sel; - Cell *cell; - - if(!column) - return; - - cell = column->sel; - if(!cell || !arg) - return; - if(!strncmp(arg, "prev", 5)) { - if(cell->prev) - cell = cell->prev; - else - for(cell = column->cells; cell && cell->next; cell = cell->next); - } else if(!strncmp(arg, "next", 5)) { - if(cell->next) - cell = cell->next; - else - cell = column->cells; - } else if(!strncmp(arg, "west", 5)) { - if(column->prev) - cell = column->prev->sel; - else { - for(c = acme->columns; c && c->next; c = c->next); - cell = c->sel; - } - } else if(!strncmp(arg, "east", 5)) { - if(column->next) - cell = column->next->sel; - else - cell = acme->columns->sel; - } else { - unsigned int i = 0, idx = blitz_strtonum(arg, 0, column->ncells - 1); - for(cell = column->cells; cell && i != idx; cell = cell->next) - i++; - } - if(cell && cell != column->sel) - focus_column(l, cell->frame->sel, True); -} - -static void -swap_frame(void *obj, char *arg) -{ - Layout *l = obj; - Acme *acme = l->aux; - Column *west = nil, *east = nil, *column = acme->sel; - Cell *north = nil, *south = nil, *cell = column->sel; - Frame *f; - XRectangle r; - - if(!column || !cell || !arg) - return; - - west = column->prev; - east = column->next; - north = cell->prev; - south = cell->next; - - if(!west) - west = east; - if(!east) - east = west; - - if(!strncmp(arg, "north", 6) && north) { - r = north->frame->rect; - north->frame->rect = cell->frame->rect; - cell->frame->rect = r; - f = north->frame; - north->frame = cell->frame; - cell->frame = f; - cell->frame->aux = cell; - north->frame->aux = north; - resize_frame(cell->frame, &cell->frame->rect, nil); - resize_frame(north->frame, &north->frame->rect, nil); - focus_column(l, cell->frame->sel, True); - } else if(!strncmp(arg, "south", 6) && south) { - r = south->frame->rect; - south->frame->rect = cell->frame->rect; - cell->frame->rect = r; - f = south->frame; - south->frame = cell->frame; - cell->frame = f; - cell->frame->aux = cell; - south->frame->aux = south; - resize_frame(cell->frame, &cell->frame->rect, nil); - resize_frame(south->frame, &south->frame->rect, nil); - focus_column(l, cell->frame->sel, True); - } else if(!strncmp(arg, "west", 5) && west && column->ncells && west->ncells) { - Cell *other = west->sel; - r = other->frame->rect; - other->frame->rect = cell->frame->rect; - cell->frame->rect = r; - f = other->frame; - other->frame = cell->frame; - cell->frame = f; - other->frame->aux = other; - cell->frame->aux = cell; - resize_frame(cell->frame, &cell->frame->rect, nil); - resize_frame(other->frame, &other->frame->rect, nil); - focus_column(l, other->frame->sel, True); - } else if(!strncmp(arg, "east", 5) && east && column->ncells && east->ncells) { - Cell *other = east->sel; - r = other->frame->rect; - other->frame->rect = cell->frame->rect; - cell->frame->rect = r; - f = other->frame; - other->frame = cell->frame; - cell->frame = f; - other->frame->aux = other; - cell->frame->aux = cell; - resize_frame(cell->frame, &cell->frame->rect, nil); - resize_frame(other->frame, &other->frame->rect, nil); - focus_column(l, other->frame->sel, True); - } -} - -static void -new_column(void *obj, char *arg) +void +new_column(Page *p) { - Layout *l = obj; - Acme *acme = l->aux; - Column *c, *new, *column = acme->sel; - Frame *f; - - if(!column || column->ncells < 2) - return; + Client *c = sel_client_of_page(p); + Column *col, *old = c ? c->column : nil; + size_t i; - f = column->sel->frame; - for(c = acme->columns; c && c->next; c = c->next); + if(!old) + return; - new = cext_emallocz(sizeof(Column)); - new->rect = layout_rect; - new->prev = c; - c->next = new; - acme->ncolumns++; - acme->sel = new; + for(i = 0; (i < old->clientsz) && old->client[i]; i++); - detach_frame(l, f); - attach_frame(l, new, f); + if(i < 2) + return; - update_column_width(l); - focus_column(l, f->sel, True); + col = cext_emallocz(sizeof(Column)); + col->rect = p->rect_column; + attach_column_to_array(col, p->column, &p->columnsz); + p->sel_column = i; + detach_client_from_array(c, old->client); + attach_client_to_array(c, col->client, &col->clientsz); + c->column = col; + update_column_width(p); + focus_client(c); } -*/ diff --git a/cmd/wm/page.c b/cmd/wm/page.c @@ -12,13 +12,19 @@ static void handle_after_write_page(IXPServer * s, File * file); +static void select_client(void *obj, char *arg); static void toggle_layout(void *obj, char *arg); static void xexec(void *obj, char *arg); +static void swap_client(void *obj, char *arg); +static void xnew_column(void *obj, char *arg); /* action table for /?/ namespace */ Action page_acttbl[] = { {"toggle", toggle_layout}, {"exec", xexec}, + {"swap", swap_client}, + {"newcol", xnew_column}, + {"select", select_client}, {0, 0} }; @@ -229,3 +235,92 @@ toggle_layout(void *obj, char *arg) else if(p->floating && p->floatingsz && p->floating[p->sel_float]) focus_client(p->floating[p->sel_float]); } + +static void +swap_client(void *obj, char *arg) +{ + Page *p = obj; + Client *c = sel_client_of_page(p); + Column *west = nil, *east = nil, *col = c->column; + Client *north = nil, *south = nil; + size_t i; + + if(!col || !arg) + return; + + for(i = 0; (i < p->columnsz) && p->column[i] && (p->column[i] != col); i++); + west = i ? p->column[i - 1] : nil; + east = (i < p->columnsz) && p->column[i + 1] ? p->column[i + 1] : nil; + + for(i = 0; (i < col->clientsz) && col->client[i] && (col->client[i] != c); i++); + north = i ? col->client[i - 1] : nil; + south = (i < col->clientsz) && col->client[i + 1] ? col->client[i + 1] : nil; + + if(!strncmp(arg, "north", 6) && north) { + col->client[i] = col->client[i - 1]; + col->client[i - 1] = c; + arrange_column(p, col); + } else if(!strncmp(arg, "south", 6) && south) { + col->client[i] = col->client[i + 1]; + col->client[i + 1] = c; + arrange_column(p, col); + } + else if(!strncmp(arg, "west", 5) && west) { + col->client[i] = west->client[west->sel]; + col->client[i]->column = col; + west->client[west->sel] = c; + west->client[west->sel]->column = west; + arrange_column(p, col); + arrange_column(p, west); + } else if(!strncmp(arg, "east", 5) && east) { + col->client[i] = west->client[west->sel]; + col->client[i]->column = col; + east->client[east->sel] = c; + east->client[east->sel]->column = east; + arrange_column(p, col); + arrange_column(p, east); + } + focus_client(c); +} + +static void +xnew_column(void *obj, char *arg) +{ + new_column(obj); +} + +static void +select_client(void *obj, char *arg) +{ + Page *p = obj; + Client *c = sel_client_of_page(p); + size_t i; + + if(!c || !arg) + return; + + if(c->column) + select_column(c, arg); + else { + for(i = 0; (i < p->floatingsz) && p->floating[i] && (p->floating[i] != c); i++); + if(!strncmp(arg, "prev", 5)) { + if(!i) + for(i = 0; (i < p->floatingsz) && p->floating[i]; i++); + focus_client(p->floating[i - 1]); + } else if(!strncmp(arg, "next", 5)) { + if(p->floating[i + 1]) + focus_client(p->floating[i + 1]); + else + focus_client(p->floating[0]); + } + else { + const char *errstr; + for(i = 0; (i < p->floatingsz) && p->floating[i]; i++); + i = cext_strtonum(arg, 0, i - 1, &errstr); + if(errstr) + return; + focus_client(p->floating[i]); + } + } +} + diff --git a/cmd/wm/wm.c b/cmd/wm/wm.c @@ -639,6 +639,7 @@ init_default() def[WM_EVENT_B3PRESS] = ixp_create(ixps, "/default/event/b3press"); def[WM_EVENT_B4PRESS] = ixp_create(ixps, "/default/event/b4press"); def[WM_EVENT_B5PRESS] = ixp_create(ixps, "/default/event/b5press"); + def[WM_DETACHED_PREFIX] = ixp_create(ixps, "/detached"); } static void diff --git a/cmd/wm/wm.h b/cmd/wm/wm.h @@ -30,6 +30,7 @@ enum { C_BORDER, C_TAB, C_HANDLE_INC, + C_CTL, C_LAST }; @@ -49,6 +50,7 @@ enum { WM_TAB, WM_HANDLE_INC, WM_SNAP_VALUE, + WM_DETACHED_PREFIX, WM_SEL_PAGE, WM_EVENT_PAGE_UPDATE, WM_EVENT_CLIENT_UPDATE, @@ -190,6 +192,7 @@ void reparent_client(Client * c, Window w, int x, int y); void attach_client(Client * c); void detach_client(Client * c, Bool unmap); Client *sel_client(); +Client *sel_client_of_page(Page *p); void focus_client(Client *c); Client *win_to_frame(Window w); void resize_client(Client *c, XRectangle * r, XPoint * pt); @@ -217,10 +220,13 @@ void focus_page(Page *p); XRectangle *rectangles(unsigned int *num); /* column.c */ -void arrange_column(Page *p); +void arrange_page(Page *p); +void arrange_column(Page *p, Column *col); void attach_column(Client *c); void detach_column(Client *c); void resize_column(Client *c, XRectangle *r, XPoint *pt); +void select_column(Client *c, char *arg); +void new_column(Page *p); /* wm.c */ void invoke_wm_event(File * f); diff --git a/rc/wmiirc b/rc/wmiirc @@ -139,21 +139,21 @@ kbind bare $MODKEY-Escape 'kmode normal' kbind move Escape 'kmode normal' kbind move $MODKEY-C-r 'kmode resize' -kbind move $NORTHKEY 'wmiir write /wm/sel/layout/sel/frame/sel/geometry ''-0 -30 -0 -0''' -kbind move $SOUTHKEY 'wmiir write /wm/sel/layout/sel/frame/sel/geometry ''+0 +30 +0 +0''' -kbind move $WESTKEY 'wmiir write /wm/sel/layout/sel/frame/sel/geometry ''-40 -0 -0 -0''' -kbind move $EASTKEY 'wmiir write /wm/sel/layout/sel/frame/sel/geometry ''+40 +0 +0 +0''' -kbind move S-$NORTHKEY 'wmiir write /wm/sel/layout/sel/frame/sel/geometry ''-0 north -0 -0''' -kbind move S-$SOUTHKEY 'wmiir write /wm/sel/layout/sel/frame/sel/geometry ''+0 south +0 +0''' -kbind move S-$WESTKEY 'wmiir write /wm/sel/layout/sel/frame/sel/geometry ''west -0 -0 -0''' -kbind move S-$EASTKEY 'wmiir write /wm/sel/layout/sel/frame/sel/geometry ''east +0 +0 +0''' +kbind move $NORTHKEY 'wmiir write /wm/sel/sel/sel/geometry ''-0 -30 -0 -0''' +kbind move $SOUTHKEY 'wmiir write /wm/sel/sel/sel/geometry ''+0 +30 +0 +0''' +kbind move $WESTKEY 'wmiir write /wm/sel/sel/sel/geometry ''-40 -0 -0 -0''' +kbind move $EASTKEY 'wmiir write /wm/sel/sel/sel/geometry ''+40 +0 +0 +0''' +kbind move S-$NORTHKEY 'wmiir write /wm/sel/sel/sel/geometry ''-0 north -0 -0''' +kbind move S-$SOUTHKEY 'wmiir write /wm/sel/sel/sel/geometry ''+0 south +0 +0''' +kbind move S-$WESTKEY 'wmiir write /wm/sel/sel/sel/geometry ''west -0 -0 -0''' +kbind move S-$EASTKEY 'wmiir write /wm/sel/sel/sel/geometry ''east +0 +0 +0''' kbind resize Escape 'kmode normal' kbind resize $MODKEY-C-m 'kmode move' -kbind resize $NORTHKEY 'wmiir write /wm/sel/layout/sel/frame/sel/geometry ''+0 +0 +0 -30''' -kbind resize $SOUTHKEY 'wmiir write /wm/sel/layout/sel/frame/sel/geometry ''+0 +0 +0 +30''' -kbind resize $WESTKEY 'wmiir write /wm/sel/layout/sel/frame/sel/geometry ''+0 +0 -40 +0''' -kbind resize $EASTKEY 'wmiir write /wm/sel/layout/sel/frame/sel/geometry ''+0 +0 +40 +0''' +kbind resize $NORTHKEY 'wmiir write /wm/sel/sel/sel/geometry ''+0 +0 +0 -30''' +kbind resize $SOUTHKEY 'wmiir write /wm/sel/sel/sel/geometry ''+0 +0 +0 +30''' +kbind resize $WESTKEY 'wmiir write /wm/sel/sel/sel/geometry ''+0 +0 -40 +0''' +kbind resize $EASTKEY 'wmiir write /wm/sel/sel/sel/geometry ''+0 +0 +40 +0''' kbind normal $MODKEY-C-b 'kmode bare' kbind normal $MODKEY-C-m 'kmode move' @@ -167,18 +167,16 @@ 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 detclients' -kbind normal $MODKEY-S-c 'wmiir write /wm/sel/layoutname column' -kbind normal $MODKEY-n 'wmiir write /wm/sel/layout/sel/ctl new' -kbind normal $MODKEY-m 'wmiir write /wm/sel/layout/sel/ctl max' -kbind normal $MODKEY-S-f 'wmiir write /wm/sel/layoutname float' -kbind normal $MODKEY-Return 'wmiir write /wm/sel/layout/sel/ctl ''swap west''' -kbind normal $MODKEY-S-Return 'wmiir write /wm/sel/layout/sel/ctl ''swap east''' +kbind normal $MODKEY-n 'wmiir write /wm/sel/ctl new' +kbind normal $MODKEY-m 'wmiir write /wm/sel/sel/sel/ctl max' +kbind normal $MODKEY-Return 'wmiir write /wm/sel/ctl ''swap west''' +kbind normal $MODKEY-S-Return 'wmiir write /wm/sel/ctl ''swap east''' kbind normal $MODKEY-C-y 'wmiir write /wm/ctl new' -kbind normal $MODKEY-$WESTKEY 'wmiir write /wm/sel/layout/sel/ctl ''select west''' -kbind normal $MODKEY-$EASTKEY 'wmiir write /wm/sel/layout/sel/ctl ''select east''' -kbind normal $MODKEY-Tab 'wmiir write /wm/sel/layout/sel/ctl ''select next''' -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-$WESTKEY 'wmiir write /wm/sel/ctl ''select west''' +kbind normal $MODKEY-$EASTKEY 'wmiir write /wm/sel/ctl ''select east''' +kbind normal $MODKEY-Tab 'wmiir write /wm/sel/ctl ''select next''' +kbind normal $MODKEY-$SOUTHKEY 'wmiir write /wm/sel/ctl ''select next''' +kbind normal $MODKEY-$NORTHKEY 'wmiir write /wm/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 toggle'