On Fri 26-10-2007 17:09 +0100, Chris Webb wrote: > Incidentally, something else needed for consistency when implementing > taglayouts-type behaviour is to index all the layout parameters like > mwfact, nmaster (if you have it) and nstack/ncols/nrows (if you have > any of them). I don't think this patch currently does this?
Hi, I've decided to abandon the taglayouts patch in favour of a more general pertag patch. Currently, the patch keeps layout, mwfact, barpos and nmaster (if installed) per tag. To make the pertag behaviour more consistent I think about synchronizing the values if multiple tags are selected. -- Jan Christoph Ebersbach Fear God and keep his commandments, for this is the whole duty of man. Eccl 12,13
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);
diff -r 167c70bcf7b0 dwm.c --- a/dwm.c Sat Oct 27 10:37:19 2007 +0200 +++ b/dwm.c Sat Oct 27 10:37:33 2007 +0200 @@ -194,13 +194,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; @@ -237,6 +235,10 @@ 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]; +unsigned int nmasters[NTAGS]; +double mwfacts[NTAGS]; /* function implementations */ void @@ -279,7 +281,7 @@ arrange(void) { unban(c); else ban(c); - layouts[ltidx].arrange(); + layouts[ltidxs[csel]].arrange(); focus(NULL); restack(); } @@ -551,7 +553,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 +899,7 @@ Bool Bool isarrange(void (*func)()) { - return func == layouts[ltidx].arrange; + return func == layouts[ltidxs[csel]].arrange; } Bool @@ -1380,8 +1382,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 +1391,7 @@ setlayout(const char *arg) { break; if(i == nlayouts) return; - ltidx = i; + ltidxs[csel] = i; } if(sel) arrange(); @@ -1405,16 +1407,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 +1428,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 +1503,12 @@ setup(void) { dc.h = bh = dc.font.height + 2; /* init layouts */ - mwfact = MWFACT; - nmaster = NMASTER; + 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 +1517,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; @@ -1593,10 +1600,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 +1611,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 +1635,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 +1709,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 +1766,7 @@ updatebarpos(void) { way = sy; wah = sh; waw = sw; - switch(bpos) { + switch(bpos[csel]) { default: wah -= bh; way += bh; @@ -1865,12 +1876,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 +1893,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);
signature.asc
Description: Digital signature