X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=dwm.c;h=3717b90238020a9d2adbc7cc4dca63c674c66f79;hb=bfd6079a155c9429b7b963b678b4a83acab07cd2;hp=7f2a638ddd23525531e95336fa0e25f77a97b312;hpb=874837f653433315bd2733823a0a1efe6f76b373;p=dwm.git diff --git a/dwm.c b/dwm.c index 7f2a638..3717b90 100644 --- a/dwm.c +++ b/dwm.c @@ -68,6 +68,7 @@ typedef struct Client Client; struct Client { char name[256]; int x, y, w, h; + int fx, fy, fw, fh; int basew, baseh, incw, inch, maxw, maxh, minw, minh; int minax, maxax, minay, maxay; long flags; @@ -144,7 +145,6 @@ void *emallocz(unsigned int size); void enternotify(XEvent *e); void eprint(const char *errstr, ...); void expose(XEvent *e); -void floating(void); /* default floating layout */ void focus(Client *c); void focusin(XEvent *e); void focusnext(const char *arg); @@ -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 seltags = 0; double mfact; unsigned int numlockmask = 0; void (*handler[LASTEvent]) (XEvent *) = { @@ -233,8 +234,7 @@ void (*handler[LASTEvent]) (XEvent *) = { Atom wmatom[WMLast], netatom[NetLast]; Bool otherwm, readin; Bool running = True; -Bool *prevtags; -Bool *seltags; +Bool *tagset[2]; Client *clients = NULL; Client *sel = NULL; Client *stack = NULL; @@ -246,7 +246,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; @@ -278,7 +277,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,13 +285,17 @@ arrange(void) { Client *c; for(c = clients; c; c = c->next) - if(isvisible(c)) + if(isvisible(c)) { unban(c); + if(lt->isfloating || c->isfloating) + resize(c, c->fx, c->fy, c->fw, c->fh, True); + } else ban(c); focus(NULL); - lt->arrange(); + if(lt->arrange) + lt->arrange(); restack(); } @@ -360,7 +363,7 @@ buttonpress(XEvent *e) { movemouse(c); } else if(ev->button == Button2) { - if((floating != lt->arrange) && c->isfloating) + if(!lt->isfloating && c->isfloating) togglefloating(NULL); else zoom(NULL); @@ -534,7 +537,7 @@ drawbar(void) { for(c = stack; c && !isvisible(c); 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); } @@ -597,22 +600,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 +625,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); @@ -671,15 +673,6 @@ expose(XEvent *e) { } void -floating(void) { /* default floating layout */ - Client *c; - - for(c = clients; c; c = c->next) - if(isvisible(c)) - resize(c, c->x, c->y, c->w, c->h, True); -} - -void focus(Client *c) { if(!c || (c && !isvisible(c))) for(c = stack; c && !isvisible(c); c = c->snext); @@ -939,7 +932,7 @@ isvisible(Client *c) { unsigned int i; for(i = 0; i < LENGTH(tags); i++) - if(c->tags[i] && seltags[i]) + if(c->tags[i] && tagset[seltags][i]) return True; return False; } @@ -994,8 +987,8 @@ manage(Window w, XWindowAttributes *wa) { /* geometry */ c->x = wa->x; c->y = wa->y; - c->w = wa->width; - c->h = wa->height; + c->w = c->fw = wa->width; + c->h = c->fh = wa->height; c->oldbw = wa->border_width; if(c->w == sw && c->h == sh) { c->x = sx; @@ -1011,6 +1004,8 @@ manage(Window w, XWindowAttributes *wa) { c->y = MAX(c->y, wy); c->bw = BORDERPX; } + c->fx = c->x; + c->fy = c->y; wc.border_width = c->bw; XConfigureWindow(dpy, w, CWBorderWidth, &wc); @@ -1106,8 +1101,11 @@ movemouse(Client *c) { ny = wy + wh - c->h - 2 * c->bw; if(!c->isfloating && !lt->isfloating && (abs(nx - c->x) > SNAP || abs(ny - c->y) > SNAP)) togglefloating(NULL); - if((lt->isfloating) || c->isfloating) + if(lt->isfloating || c->isfloating) { + c->fx = nx; + c->fy = ny; resize(c, nx, ny, c->w, c->h, False); + } break; } } @@ -1158,11 +1156,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(); @@ -1263,10 +1260,16 @@ resizemouse(Client *c) { XSync(dpy, False); nw = MAX(ev.xmotion.x - ocx - 2 * c->bw + 1, 1); nh = MAX(ev.xmotion.y - ocy - 2 * c->bw + 1, 1); - if(!c->isfloating && !lt->isfloating && (abs(nw - c->w) > SNAP || abs(nh - c->h) > SNAP)) + if(!c->isfloating && !lt->isfloating && (abs(nw - c->w) > SNAP || abs(nh - c->h) > SNAP)) { + c->fx = c->x; + c->fy = c->y; togglefloating(NULL); - if((lt->isfloating) || c->isfloating) + } + if((lt->isfloating) || c->isfloating) { resize(c, c->x, c->y, nw, nh, True); + c->fw = nw; + c->fh = nh; + } break; } } @@ -1286,16 +1289,11 @@ restack(void) { if(!lt->isfloating) { wc.stack_mode = Below; wc.sibling = barwin; - if(!sel->isfloating) { - XConfigureWindow(dpy, sel->win, CWSibling|CWStackMode, &wc); - wc.sibling = sel->win; - } - for(c = nexttiled(clients); c; c = nexttiled(c->next)) { - if(c == sel) - continue; - XConfigureWindow(dpy, c->win, CWSibling|CWStackMode, &wc); - wc.sibling = c->win; - } + for(c = stack; c; c = c->snext) + if(!c->isfloating && isvisible(c)) { + XConfigureWindow(dpy, c->win, CWSibling|CWStackMode, &wc); + wc.sibling = c->win; + } } XSync(dpy, False); while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); @@ -1506,9 +1504,9 @@ setup(void) { XSetFont(dpy, dc.gc, dc.font.xfont->fid); /* init tags */ - seltags = emallocz(TAGSZ); - prevtags = emallocz(TAGSZ); - seltags[0] = prevtags[0] = True; + 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 +1699,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(); } @@ -1828,28 +1826,24 @@ 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) { - memcpy(prevtags, seltags, TAGSZ); - memcpy(seltags, tmp, TAGSZ); - arrange(); - } + seltags ^= 1; /* toggle sel tagset */ + if(memcmp(tagset[seltags ^ 1], tmp, TAGSZ) != 0) + memcpy(tagset[seltags], tmp, TAGSZ); + arrange(); } void viewprevtag(const char *arg) { - - memcpy(tmp, seltags, TAGSZ); - memcpy(seltags, prevtags, TAGSZ); - memcpy(prevtags, tmp, TAGSZ); + seltags ^= 1; /* toggle sel tagset */ arrange(); } @@ -1889,14 +1883,14 @@ void zoom(const char *arg) { Client *c = sel; - if(!sel || lt->isfloating || sel->isfloating) - return; if(c == nexttiled(clients)) - if(!(c = nexttiled(c->next))) + if(!c || !(c = nexttiled(c->next))) return; - detach(c); - attach(c); - focus(c); + if(!lt->isfloating && !sel->isfloating) { + detach(c); + attach(c); + focus(c); + } arrange(); }