X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=dwm.c;h=56ca615bbcc53594c7992c79b660132ddd83c3fa;hb=5602f44b29b5c9a9b66b012b34f5749929c5cd31;hp=a77f4c8ec8b4f73eda9084745de291f5d3db1b61;hpb=7f70d90219c4a33c79ff93b49fb24ee7a6f62b4d;p=dwm.git diff --git a/dwm.c b/dwm.c index a77f4c8..56ca615 100644 --- a/dwm.c +++ b/dwm.c @@ -112,7 +112,7 @@ typedef struct { const char *symbol; void (*arrange)(void); Bool isfloating; -} Layout; +} Layout; typedef struct { const char *class; @@ -160,7 +160,7 @@ void initfont(const char *fontstr); Bool isoccupied(unsigned int t); Bool isprotodel(Client *c); Bool isurgent(unsigned int t); -Bool isvisible(Client *c); +Bool isvisible(Client *c, Bool *cmp); void keypress(XEvent *e); void killclient(const char *arg); void manage(Window w, XWindowAttributes *wa); @@ -214,7 +214,7 @@ char stext[256]; int screen, sx, sy, sw, sh; int (*xerrorxlib)(Display *, XErrorEvent *); int bx, by, bw, bh, blw, bgw, mx, my, mw, mh, mox, moy, mow, moh, tx, ty, tw, th, wx, wy, ww, wh; -int viewtags_set = 0; +int seltags = 0; double mfact; unsigned int numlockmask = 0; void (*handler[LASTEvent]) (XEvent *) = { @@ -234,21 +234,22 @@ void (*handler[LASTEvent]) (XEvent *) = { Atom wmatom[WMLast], netatom[NetLast]; Bool otherwm, readin; Bool running = True; -Bool *seltags; -Bool *viewtags[2]; +Bool *tagset[2]; Client *clients = NULL; Client *sel = NULL; Client *stack = NULL; Cursor cursor[CurLast]; Display *dpy; DC dc = {0}; +Geom geoms[]; +Geom *geom = geoms; +Layout layouts[]; +Layout *lt = layouts; Window root, barwin; /* configuration, allows nested code to access above variables */ #include "config.h" #define TAGSZ (LENGTH(tags) * sizeof(Bool)) -Layout *lt = layouts; -Geom *geom = geoms; /* function implementations */ @@ -278,7 +279,7 @@ applyrules(Client *c) { if(ch.res_name) XFree(ch.res_name); if(!matched) - memcpy(c->tags, seltags, TAGSZ); + memcpy(c->tags, tagset[seltags], TAGSZ); } void @@ -286,7 +287,7 @@ arrange(void) { Client *c; for(c = clients; c; c = c->next) - if(isvisible(c)) { + if(isvisible(c, NULL)) { unban(c); if(lt->isfloating || c->isfloating) resize(c, c->fx, c->fy, c->fw, c->fh, True); @@ -468,7 +469,7 @@ configurerequest(XEvent *e) { if((ev->value_mask & (CWX|CWY)) && !(ev->value_mask & (CWWidth|CWHeight))) configure(c); - if(isvisible(c)) + if(isvisible(c, NULL)) XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); } else @@ -535,10 +536,10 @@ drawbar(void) { drawtext(geom->symbol, dc.norm, False); dc.x += bgw; } - for(c = stack; c && !isvisible(c); c = c->snext); + for(c = stack; c && !isvisible(c, NULL); c = c->snext); for(i = 0; i < LENGTH(tags); i++) { dc.w = textw(tags[i]); - if(seltags[i]) { + if(tagset[seltags][i]) { drawtext(tags[i], dc.sel, isurgent(i)); drawsquare(c && c->tags[i], isoccupied(i), isurgent(i), dc.sel); } @@ -675,8 +676,8 @@ expose(XEvent *e) { void focus(Client *c) { - if(!c || (c && !isvisible(c))) - for(c = stack; c && !isvisible(c); c = c->snext); + if(!c || (c && !isvisible(c, NULL))) + for(c = stack; c && !isvisible(c, NULL); c = c->snext); if(sel && sel != c) { grabbuttons(sel, False); XSetWindowBorder(dpy, sel->win, dc.norm[ColBorder]); @@ -710,9 +711,9 @@ focusnext(const char *arg) { if(!sel) return; - for(c = sel->next; c && !isvisible(c); c = c->next); + for(c = sel->next; c && !isvisible(c, arg ? sel->tags : NULL); c = c->next); if(!c) - for(c = clients; c && !isvisible(c); c = c->next); + for(c = clients; c && !isvisible(c, arg ? sel->tags : NULL); c = c->next); if(c) { focus(c); restack(); @@ -725,10 +726,10 @@ focusprev(const char *arg) { if(!sel) return; - for(c = sel->prev; c && !isvisible(c); c = c->prev); + for(c = sel->prev; c && !isvisible(c, arg ? sel->tags : NULL); c = c->prev); if(!c) { for(c = clients; c && c->next; c = c->next); - for(; c && !isvisible(c); c = c->prev); + for(; c && !isvisible(c, arg ? sel->tags : NULL); c = c->prev); } if(c) { focus(c); @@ -929,11 +930,13 @@ isurgent(unsigned int t) { } Bool -isvisible(Client *c) { +isvisible(Client *c, Bool *cmp) { unsigned int i; + if(!cmp) + cmp = tagset[seltags]; for(i = 0; i < LENGTH(tags); i++) - if(c->tags[i] && seltags[i]) + if(c->tags[i] && cmp[i]) return True; return False; } @@ -1060,7 +1063,7 @@ monocle(void) { Client *c; for(c = clients; c; c = c->next) - if((lt->isfloating || !c->isfloating) && isvisible(c)) + if((lt->isfloating || !c->isfloating) && isvisible(c, NULL)) resize(c, mox, moy, mow - 2 * c->bw, moh - 2 * c->bw, RESIZEHINTS); } @@ -1114,7 +1117,7 @@ movemouse(Client *c) { Client * nexttiled(Client *c) { - for(; c && (c->isfloating || !isvisible(c)); c = c->next); + for(; c && (c->isfloating || !isvisible(c, NULL)); c = c->next); return c; } @@ -1291,7 +1294,7 @@ restack(void) { wc.stack_mode = Below; wc.sibling = barwin; for(c = stack; c; c = c->snext) - if(!c->isfloating && isvisible(c)) { + if(!c->isfloating && isvisible(c, NULL)) { XConfigureWindow(dpy, c->win, CWSibling|CWStackMode, &wc); wc.sibling = c->win; } @@ -1505,10 +1508,9 @@ setup(void) { XSetFont(dpy, dc.gc, dc.font.xfont->fid); /* init tags */ - viewtags[0] = emallocz(TAGSZ); - viewtags[1] = emallocz(TAGSZ); - viewtags[0][0] = viewtags[1][0] = True; - seltags = viewtags[0]; + tagset[0] = emallocz(TAGSZ); + tagset[1] = emallocz(TAGSZ); + tagset[0][0] = tagset[1][0] = True; /* init bar */ for(blw = i = 0; LENGTH(layouts) > 1 && i < LENGTH(layouts); i++) { @@ -1701,10 +1703,10 @@ toggleview(const char *arg) { unsigned int i, j; i = idxoftag(arg); - seltags[i] = !seltags[i]; - for(j = 0; j < LENGTH(tags) && !seltags[j]; j++); + tagset[seltags][i] = !tagset[seltags][i]; + for(j = 0; j < LENGTH(tags) && !tagset[seltags][j]; j++); if(j == LENGTH(tags)) - seltags[i] = True; /* at least one tag must be viewed */ + tagset[seltags][i] = True; /* at least one tag must be viewed */ arrange(); } @@ -1830,25 +1832,15 @@ updatewmhints(Client *c) { void view(const char *arg) { - Bool tmp[LENGTH(tags)]; - unsigned int i; - - for(i = 0; i < LENGTH(tags); i++) - tmp[i] = (NULL == arg); - tmp[idxoftag(arg)] = True; - - if(memcmp(seltags, tmp, TAGSZ) != 0) { - seltags = viewtags[viewtags_set ^= 1]; /* toggle tagset */ - memcpy(seltags, tmp, TAGSZ); - arrange(); - } - else - viewprevtag(NULL); + seltags ^= 1; + memset(tagset[seltags], (NULL == arg), TAGSZ); + tagset[seltags][idxoftag(arg)] = True; + arrange(); } void viewprevtag(const char *arg) { - seltags = viewtags[viewtags_set ^= 1]; /* toggle tagset */ + seltags ^= 1; /* toggle sel tagset */ arrange(); } @@ -1863,6 +1855,7 @@ xerror(Display *dpy, XErrorEvent *ee) { || (ee->request_code == X_PolyFillRectangle && ee->error_code == BadDrawable) || (ee->request_code == X_PolySegment && ee->error_code == BadDrawable) || (ee->request_code == X_ConfigureWindow && ee->error_code == BadMatch) + || (ee->request_code == X_GrabButton && ee->error_code == BadAccess) || (ee->request_code == X_GrabKey && ee->error_code == BadAccess) || (ee->request_code == X_CopyArea && ee->error_code == BadDrawable)) return 0;