wmii

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

commit 40772c24ab474a075622d7c99323b52c4a1a9f1c
parent 1ec81ff9c0ee3c7df325fce050f9bac0a3d0d704
Author: Kris Maglione <jg@suckless.org>
Date:   Fri, 30 Mar 2007 01:15:36 -0400

Tread nil a bit more specially.

Diffstat:
cmd/wmii/area.c | 39++++++++++++++++++++++-----------------
cmd/wmii/client.c | 4++--
cmd/wmii/event.c | 4++--
cmd/wmii/fns.h | 8++++----
cmd/wmii/fs.c | 2+-
cmd/wmii/view.c | 41++++++++++++++++++++++-------------------
6 files changed, 53 insertions(+), 45 deletions(-)

diff --git a/cmd/wmii/area.c b/cmd/wmii/area.c @@ -14,7 +14,7 @@ static void place_frame(Frame *f); Client * -sel_client_of_area(Area *a) { +area_selclient(Area *a) { if(a && a->sel) return a->sel->client; return nil; @@ -23,31 +23,36 @@ sel_client_of_area(Area *a) { Area * create_area(View *v, Area *pos, uint w) { static ushort id = 1; - uint area_num, col_num, i; - uint min_width; + uint areanum, colnum, i; + uint minwidth; Area *a, **p; - min_width = screen->rect.width/NCOL; - p = pos ? &pos->next : &v->area; + minwidth = screen->rect.width/NCOL; - area_num = 0; - i = 0; - for(a = v->area; a != *p; a = a->next) - area_num++, i++; - for(; a; a = a->next) area_num++; + p = &v->area; + if(pos) + p = &pos->next; + + i = areanum = 0; + a = v->area; + for(; a != *p; a = a->next) + areanum++, i++; + for(; a; a = a->next) + areanum++; - col_num = max((area_num - 1), 0); + colnum = max((areanum - 1), 0); if(w == 0) { - if(col_num) { - w = newcolw_of_view(v); + if(colnum) { + w = newcolw_of_view(v, max(i-1, 0)); if (w == 0) - w = screen->rect.width / (col_num + 1); + w = screen->rect.width / (colnum + 1); } else w = screen->rect.width; } - if(w < min_width) - w = min_width; - if(col_num && (col_num * min_width + w) > screen->rect.width) + + if(w < minwidth) + w = minwidth; + if(colnum && (colnum * minwidth + w) > screen->rect.width) return nil; if(pos) scale_view(v, screen->rect.width - w); diff --git a/cmd/wmii/client.c b/cmd/wmii/client.c @@ -163,7 +163,7 @@ manage_client(Client *c) { } Client * -sel_client() { +selclient() { if(screen->sel && screen->sel->sel->sel) return screen->sel->sel->sel->client; return nil; @@ -229,7 +229,7 @@ void update_client_grab(Client *c) { Frame *f; f = c->sel; - if((f->client != sel_client()) + if((f->client != selclient()) || (f->area->floating && f != f->area->stack)) { if(verbose) fprintf(stderr, "update_client_grab(%p) AnyButton => %s\n", c, str_nil(c->name)); diff --git a/cmd/wmii/event.c b/cmd/wmii/event.c @@ -85,7 +85,7 @@ buttonpress(XEvent *e) { else if(!ev->subwindow && !ptinrect(ev->x, ev->y, &f->titlebar)) do_mouse_resize(f->client, False, quadrant(&f->rect, ev->x_root, ev->y_root)); - if(f->client != sel_client()) + if(f->client != selclient()) focus(f->client, True); } if(ev->subwindow) @@ -403,7 +403,7 @@ mapnotify(XEvent *e) { ev = &e->xmap; if((c = client_of_win(ev->window))) - if(c == sel_client()) + if(c == selclient()) focus_client(c); } diff --git a/cmd/wmii/fns.h b/cmd/wmii/fns.h @@ -14,7 +14,7 @@ char *select_area(Area *a, char *arg); void send_to_area(Area *to, Frame *f); void attach_to_area(Area *a, Frame *f, Bool send); void detach_from_area(Frame *f); -Client *sel_client_of_area(Area *a); +Client *area_selclient(Area *a); /* bar.c */ Bar *create_bar(Bar **b_link, char *name); @@ -47,7 +47,7 @@ char *send_client(Frame *f, char *arg, Bool swap); char * message_client(Client *c, char *message); void move_client(Client *c, char *arg); void size_client(Client *c, char *arg); -Client *sel_client(); +Client *selclient(); Frame *frame_of_win(Window w); Client *client_of_win(Window w); void update_client_grab(Client *c); @@ -150,13 +150,13 @@ XRectangle *rects_of_view(View *v, uint *num, Frame *ignore); View *view_of_id(ushort id); void select_view(const char *arg); void attach_to_view(View *v, Frame *f); -Client *sel_client_of_view(View *v); +Client *view_selclient(View *v); char *message_view(View *v, char *message); void restack_view(View *v); uchar *view_index(View *v); void destroy_view(View *v); void update_views(); -uint newcolw_of_view(View *v); +uint newcolw_of_view(View *v, int i); /* wm.c */ int wmii_error_handler(Display *dpy, XErrorEvent *error); diff --git a/cmd/wmii/fs.c b/cmd/wmii/fs.c @@ -386,7 +386,7 @@ lookup_file(FileId *parent, char *name) switch(parent->tab.type) { case FsDClients: if(!name || !strcmp(name, "sel")) { - if((c = sel_client())) { + if((c = selclient())) { file = get_file(); *last = file; last = &file->next; diff --git a/cmd/wmii/view.c b/cmd/wmii/view.c @@ -38,7 +38,7 @@ assign_sel_view(View *v) { } Client * -sel_client_of_view(View *v) { +view_selclient(View *v) { return v->sel && v->sel->sel ? v->sel->sel->client : nil; } @@ -331,7 +331,7 @@ client_of_message(View *v, char *message, uint *next) { if(!strncmp(message, "sel ", 4)) { *next = 4; - return sel_client_of_view(v); + return view_selclient(v); } sscanf(message, "0x%lx %n", &id, next); if(!id) @@ -412,41 +412,44 @@ send: void update_views() { View *n, *v, *old; + Bool found; old = screen->sel; for(v=view; v; v=v->next) update_frame_selectors(v); + found = False; for(v=view; v; v=n) { n=v->next; - if((v != old) && is_empty(v)) - destroy_view(v); + if(v != old) { + found = True; + if(is_empty(v)) + destroy_view(v); + } } - focus_view(screen, old); + if(found && !strcmp(old->name, "nil")) + destroy_view(old); + focus_view(screen, screen->sel); } uint -newcolw_of_view(View *v) { +newcolw_of_view(View *v, int num) { + regmatch_t regm; Rule *r; - Area *a; - uint i, n; - regmatch_t tmpregm; + uint n; - for(r=def.colrules.rule; r; r=r->next) { - if(!regexec(&r->regex, v->name, 1, &tmpregm, 0)) { - char buf[256]; + for(r=def.colrules.rule; r; r=r->next) + if(!regexec(&r->regex, v->name, 1, &regm, 0)) { + char buf[sizeof r->value]; char *toks[16]; + strncpy(buf, r->value, sizeof(buf)); n = tokenize(toks, 16, buf, '+'); - for(a=v->area, i=0; a; a=a->next) - i++; - if(n && n >= i) { - if(sscanf(toks[i - 1], "%u", &n) == 1) - return (screen->rect.width * n) / 100; - } + if(n > num) + if(sscanf(toks[num], "%u", &n) == 1) + return screen->rect.width * ((double)n / 100); break; } - } return 0; }