X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=dwm.c;h=7643764e42c556f2953955c25fe8abf16db36a7c;hb=858251de46c50498b261b312f2df03531dd9923c;hp=7f2a638ddd23525531e95336fa0e25f77a97b312;hpb=874837f653433315bd2733823a0a1efe6f76b373;p=dwm.git diff --git a/dwm.c b/dwm.c index 7f2a638..7643764 100644 --- a/dwm.c +++ b/dwm.c @@ -210,10 +210,11 @@ int xerrorstart(Display *dpy, XErrorEvent *ee); void zoom(const char *arg); /* variables */ -char stext[256], buf[256]; +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; double mfact; unsigned int numlockmask = 0; void (*handler[LASTEvent]) (XEvent *) = { @@ -233,8 +234,8 @@ void (*handler[LASTEvent]) (XEvent *) = { Atom wmatom[WMLast], netatom[NetLast]; Bool otherwm, readin; Bool running = True; -Bool *prevtags; Bool *seltags; +Bool *viewtags[2]; Client *clients = NULL; Client *sel = NULL; Client *stack = NULL; @@ -246,7 +247,6 @@ Window root, barwin; /* configuration, allows nested code to access above variables */ #include "config.h" #define TAGSZ (LENGTH(tags) * sizeof(Bool)) -Bool tmp[LENGTH(tags)]; Layout *lt = layouts; Geom *geom = geoms; @@ -597,22 +597,23 @@ drawtext(const char *text, unsigned long col[ColLast], Bool invert) { int x, y, w, h; unsigned int len, olen; XRectangle r = { dc.x, dc.y, dc.w, dc.h }; + char buf[256]; XSetForeground(dpy, dc.gc, col[invert ? ColFG : ColBG]); XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); if(!text) return; - w = 0; olen = strlen(text); - len = MIN(olen, sizeof buf - 1); + len = MIN(olen, sizeof buf); memcpy(buf, text, len); - buf[len] = 0; + w = 0; h = dc.font.ascent + dc.font.descent; y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent; x = dc.x + (h / 2); /* shorten text if necessary */ - while(len && (w = textnw(buf, len)) > dc.w - h) - buf[--len] = 0; + for(; len && (w = textnw(buf, len)) > dc.w - h; len--); + if (!len) + return; if(len < olen) { if(len > 1) buf[len - 1] = '.'; @@ -621,8 +622,6 @@ drawtext(const char *text, unsigned long col[ColLast], Bool invert) { if(len > 3) buf[len - 3] = '.'; } - if(w > dc.w) - return; /* too long */ XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]); if(dc.font.set) XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len); @@ -1158,11 +1157,10 @@ quit(const char *arg) { void reapply(const char *arg) { - static Bool zerotags[LENGTH(tags)] = { 0 }; Client *c; for(c = clients; c; c = c->next) { - memcpy(c->tags, zerotags, sizeof zerotags); + memset(c->tags, 0, TAGSZ); applyrules(c); } arrange(); @@ -1506,9 +1504,10 @@ setup(void) { XSetFont(dpy, dc.gc, dc.font.xfont->fid); /* init tags */ - seltags = emallocz(TAGSZ); - prevtags = emallocz(TAGSZ); - seltags[0] = prevtags[0] = True; + viewtags[0] = emallocz(TAGSZ); + viewtags[1] = emallocz(TAGSZ); + viewtags[0][0] = viewtags[1][0] = True; + seltags = viewtags[0]; /* init bar */ for(blw = i = 0; LENGTH(layouts) > 1 && i < LENGTH(layouts); i++) { @@ -1828,9 +1827,9 @@ updatewmhints(Client *c) { } } - void view(const char *arg) { + Bool tmp[LENGTH(tags)]; unsigned int i; for(i = 0; i < LENGTH(tags); i++) @@ -1838,7 +1837,7 @@ view(const char *arg) { tmp[idxoftag(arg)] = True; if(memcmp(seltags, tmp, TAGSZ) != 0) { - memcpy(prevtags, seltags, TAGSZ); + seltags = viewtags[viewtags_set ^= 1]; /* toggle tagset */ memcpy(seltags, tmp, TAGSZ); arrange(); } @@ -1846,10 +1845,7 @@ view(const char *arg) { void viewprevtag(const char *arg) { - - memcpy(tmp, seltags, TAGSZ); - memcpy(seltags, prevtags, TAGSZ); - memcpy(prevtags, tmp, TAGSZ); + seltags = viewtags[viewtags_set ^= 1]; /* toggle tagset */ arrange(); }