diff -r 78d663b698f0 dwm.c --- a/dwm.c Thu Oct 25 20:24:59 2007 +0200 +++ b/dwm.c Sat Oct 27 10:37:04 2007 +0200 @@ -193,12 +193,11 @@ void zoom(const char *arg); /* variables */ char stext[256]; -double mwfact; 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; @@ -235,6 +234,9 @@ Regs *regs = NULL; #define NTAGS (sizeof tags / sizeof tags[0]) Bool seltags[NTAGS] = {[0] = True}; Bool prevtags[NTAGS] = {[0] = True}; +unsigned int bpos[NTAGS]; +unsigned int ltidxs[NTAGS]; +double mwfacts[NTAGS]; /* function implementations */ void @@ -277,7 +279,7 @@ arrange(void) { unban(c); else ban(c); - layouts[ltidx].arrange(); + layouts[ltidxs[csel]].arrange(); focus(NULL); restack(); } @@ -549,7 +551,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; @@ -895,7 +897,7 @@ Bool Bool isarrange(void (*func)()) { - return func == layouts[ltidx].arrange; + return func == layouts[ltidxs[csel]].arrange; } Bool @@ -1378,8 +1380,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++) @@ -1387,7 +1389,7 @@ setlayout(const char *arg) { break; if(i == nlayouts) return; - ltidx = i; + ltidxs[csel] = i; } if(sel) arrange(); @@ -1403,16 +1405,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(); } @@ -1479,7 +1481,11 @@ setup(void) { dc.h = bh = dc.font.height + 2; /* init layouts */ - mwfact = MWFACT; + for(i = 0; i < NTAGS; i++) + { + ltidxs[i] = 0; + mwfacts[i] = MWFACT; + } nlayouts = sizeof layouts / sizeof layouts[0]; for(blw = i = 0; i < nlayouts; i++) { j = textw(layouts[i].symbol); @@ -1488,7 +1494,8 @@ setup(void) { } /* init bar */ - bpos = BARPOS; + for(i = 0; i < NTAGS; i++) + bpos[i] = BARPOS; wa.override_redirect = 1; wa.background_pixmap = ParentRelative; wa.event_mask = ButtonPressMask | ExposureMask; @@ -1570,7 +1577,7 @@ tile(void) { n++; /* window geoms */ - mw = (n == 1) ? waw : mwfact * waw; + mw = (n == 1) ? waw : mwfacts[csel] * waw; th = (n > 1) ? wah / (n - 1) : 0; if(n > 1 && th < bh) th = wah; @@ -1606,10 +1613,10 @@ tile(void) { 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(); } @@ -1673,8 +1680,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(); } @@ -1726,7 +1737,7 @@ updatebarpos(void) { way = sy; wah = sh; waw = sw; - switch(bpos) { + switch(bpos[csel]) { default: wah -= bh; way += bh; @@ -1836,12 +1847,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(); } @@ -1849,6 +1864,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);