diff -r 0eea3c24456e dwm.c --- a/dwm.c Sat Oct 27 11:46:31 2007 +0200 +++ b/dwm.c Sat Oct 27 11:48:49 2007 +0200 @@ -124,6 +124,7 @@ void configure(Client *c); void configure(Client *c); void configurenotify(XEvent *e); void configurerequest(XEvent *e); +void deinitpertag(void); void destroynotify(XEvent *e); void detach(Client *c); void detachstack(Client *c); @@ -194,13 +195,11 @@ void zoom(const char *arg); /* variables */ char stext[256]; -double mwfact; -unsigned int nmaster; int screen, sx, sy, sw, sh, wax, way, waw, wah; int (*xerrorxlib)(Display *, XErrorEvent *); -unsigned int bh, bpos; +unsigned int bh; unsigned int blw = 0; -unsigned int ltidx = 0; /* default */ +unsigned int csel = 0; unsigned int nlayouts = 0; unsigned int nrules = 0; unsigned int numlockmask = 0; @@ -231,6 +230,11 @@ Window barwin, root; Window barwin, root; Regs *regs = NULL; +unsigned int *bpos; +unsigned int *ltidxs; +unsigned int *nmasters; +double *mwfacts; + /* configuration, allows nested code to access above variables */ #include "config.h" @@ -279,7 +283,7 @@ arrange(void) { unban(c); else ban(c); - layouts[ltidx].arrange(); + layouts[ltidxs[csel]].arrange(); focus(NULL); restack(); } @@ -398,6 +402,7 @@ cleanup(void) { XFreeCursor(dpy, cursor[CurMove]); XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); XSync(dpy, False); + deinitpertag(); } void @@ -506,6 +511,15 @@ configurerequest(XEvent *e) { } void +deinitpertag(void) +{ + free(bpos); + free(ltidxs); + free(mwfacts); + free(nmasters); +} + +void destroynotify(XEvent *e) { Client *c; XDestroyWindowEvent *ev = &e->xdestroywindow; @@ -551,7 +565,7 @@ drawbar(void) { dc.x += dc.w; } dc.w = blw; - drawtext(layouts[ltidx].symbol, dc.norm); + drawtext(layouts[ltidxs[csel]].symbol, dc.norm); x = dc.x + dc.w; dc.w = textw(stext); dc.x = sw - dc.w; @@ -897,7 +911,7 @@ Bool Bool isarrange(void (*func)()) { - return func == layouts[ltidx].arrange; + return func == layouts[ltidxs[csel]].arrange; } Bool @@ -1380,8 +1394,8 @@ setlayout(const char *arg) { unsigned int i; if(!arg) { - if(++ltidx == nlayouts) - ltidx = 0;; + if(++ltidxs[csel] == nlayouts) + ltidxs[csel] = 0;; } else { for(i = 0; i < nlayouts; i++) @@ -1389,7 +1403,7 @@ setlayout(const char *arg) { break; if(i == nlayouts) return; - ltidx = i; + ltidxs[csel] = i; } if(sel) arrange(); @@ -1405,16 +1419,16 @@ setmwfact(const char *arg) { return; /* arg handling, manipulate mwfact */ if(arg == NULL) - mwfact = MWFACT; + mwfacts[csel] = MWFACT; else if(1 == sscanf(arg, "%lf", &delta)) { if(arg[0] == '+' || arg[0] == '-') - mwfact += delta; + mwfacts[csel] += delta; else - mwfact = delta; - if(mwfact < 0.1) - mwfact = 0.1; - else if(mwfact > 0.9) - mwfact = 0.9; + mwfacts[csel] = delta; + if(mwfacts[csel] < 0.1) + mwfacts[csel] = 0.1; + else if(mwfacts[csel] > 0.9) + mwfacts[csel] = 0.9; } arrange(); } @@ -1426,12 +1440,12 @@ setnmaster(const char *arg) { if(!isarrange(tile)) return; if(!arg) - nmaster = NMASTER; + nmasters[csel] = NMASTER; else { i = atoi(arg); - if((nmaster + i) < 1 || wah / (nmaster + i) <= 2 * BORDERPX) + if((nmasters[csel] + i) < 1 || wah / (nmasters[csel] + i) <= 2 * BORDERPX) return; - nmaster += i; + nmasters[csel] += i; } if(sel) arrange(); @@ -1501,8 +1515,15 @@ setup(void) { dc.h = bh = dc.font.height + 2; /* init layouts */ - mwfact = MWFACT; - nmaster = NMASTER; + ltidxs = (unsigned int*)emallocz(sizeof(unsigned int) * NTAGS); + mwfacts = (double*)emallocz(sizeof(double) * NTAGS); + nmasters = (unsigned int*)emallocz(sizeof(unsigned int) * NTAGS); + for(i = 0; i < NTAGS; i++) + { + ltidxs[i] = 0; + mwfacts[i] = MWFACT; + nmasters[i] = NMASTER; + } nlayouts = sizeof layouts / sizeof layouts[0]; for(blw = i = 0; i < nlayouts; i++) { j = textw(layouts[i].symbol); @@ -1511,7 +1532,9 @@ setup(void) { } /* init bar */ - bpos = BARPOS; + bpos = (unsigned int*)emallocz(sizeof(unsigned int) * NTAGS); + for(i = 0; i < NTAGS; i++) + bpos[i] = BARPOS; wa.override_redirect = 1; wa.background_pixmap = ParentRelative; wa.event_mask = ButtonPressMask | ExposureMask; @@ -1593,10 +1616,10 @@ tile(void) { n++; /* window geoms */ - mh = (n <= nmaster) ? wah / (n > 0 ? n : 1) : wah / nmaster; - mw = (n <= nmaster) ? waw : mwfact * waw; - th = (n > nmaster) ? wah / (n - nmaster) : 0; - if(n > nmaster && th < bh) + mh = (n <= nmasters[csel]) ? wah / (n > 0 ? n : 1) : wah / nmasters[csel]; + mw = (n == 1) ? waw : mwfacts[csel] * waw; + th = (n > nmasters[csel]) ? wah / (n - nmasters[csel]) : 0; + if(n > nmasters[csel] && th < bh) th = wah; nx = wax; @@ -1604,17 +1627,17 @@ tile(void) { nw = 0; /* gcc stupidity requires this */ for(i = 0, c = mc = nexttiled(clients); c; c = nexttiled(c->next), i++) { c->ismax = False; - if(i < nmaster) { /* master */ + if(i < nmasters[csel]) { /* master */ ny = way + i * mh; nw = mw - 2 * c->border; nh = wah - 2 * c->border; nh = mh; - if(i + 1 == (n < nmaster ? n : nmaster)) /* remainder */ + if(i + 1 == (n < nmasters[csel] ? n : nmasters[csel])) /* remainder */ nh = wah - mh * i; nh -= 2 * c->border; } else { /* tile window */ - if(i == nmaster) { + if(i == nmasters[csel]) { ny = way; nx += mc->w + 2 * mc->border; nw = waw - nx - 2 * c->border; @@ -1628,17 +1651,17 @@ tile(void) { if((c->h < bh) || (c->h > nh) || (c->w < bh) || (c->w > nw)) /* client doesn't accept size constraints */ resize(c, nx, ny, nw, nh, False); - if(n > nmaster && th != wah) + if(n > nmasters[csel] && th != wah) ny = c->y + c->h + 2 * c->border; } } void togglebar(const char *arg) { - if(bpos == BarOff) - bpos = (BARPOS == BarOff) ? BarTop : BARPOS; + if(bpos[csel] == BarOff) + bpos[csel] = (BARPOS == BarOff) ? BarTop : BARPOS; else - bpos = BarOff; + bpos[csel] = BarOff; updatebarpos(); arrange(); } @@ -1702,8 +1725,12 @@ toggleview(const char *arg) { i = idxoftag(arg); seltags[i] = !seltags[i]; for(j = 0; j < NTAGS && !seltags[j]; j++); - if(j == NTAGS) + if(j == NTAGS) { seltags[i] = True; /* at least one tag must be viewed */ + j = i; + } + if(csel == i) + csel = j; arrange(); } @@ -1755,7 +1782,7 @@ updatebarpos(void) { way = sy; wah = sh; waw = sw; - switch(bpos) { + switch(bpos[csel]) { default: wah -= bh; way += bh; @@ -1865,12 +1892,16 @@ xerrorstart(Display *dsply, XErrorEvent void view(const char *arg) { - unsigned int i; + unsigned int i, prevcsel; memcpy(prevtags, seltags, sizeof seltags); for(i = 0; i < NTAGS; i++) seltags[i] = arg == NULL; seltags[idxoftag(arg)] = True; + prevcsel = csel; + csel = idxoftag(arg); + if (bpos[prevcsel] != bpos[csel]) + updatebarpos(); arrange(); } @@ -1878,6 +1909,9 @@ viewprevtag(const char *arg) { viewprevtag(const char *arg) { static Bool tmptags[sizeof tags / sizeof tags[0]]; + int i = 0; + while(i < NTAGS && !prevtags[i]) i++; + csel = i; memcpy(tmptags, seltags, sizeof seltags); memcpy(seltags, prevtags, sizeof seltags); memcpy(prevtags, tmptags, sizeof seltags);