Hello. I've been a long time reader but never posted here before.
This might be of some interest. I've tackled this issue before with my own version of the pertag patch that dynamically allocates memory. This patch also adds per tag defaults. Any comments and criticisms appreciated.
--- a/config.def.h 2010-06-10 18:05:45.384971543 -0400 +++ b/config.def.h 2010-06-10 18:07:17.115816559 -0400 @@ -13,9 +13,6 @@ static const Bool showbar = True; /* False means no bar */ static const Bool topbar = True; /* False means bottom bar */ -/* tagging */ -static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; - static const Rule rules[] = { /* class instance title tags mask isfloating monitor */ { "Gimp", NULL, NULL, 0, True, -1 }, @@ -33,6 +30,20 @@ { "[M]", monocle }, }; +/* tagging */ +static const Tag tags[] = { + /* name layout mfact */ + { "1", &layouts[0], -1 }, + { "2", &layouts[0], -1 }, + { "3", &layouts[0], -1 }, + { "4", &layouts[0], -1 }, + { "5", &layouts[0], -1 }, + { "6", &layouts[0], -1 }, + { "7", &layouts[0], -1 }, + { "8", &layouts[0], -1 }, + { "9", &layouts[0], -1 }, +}; + /* key definitions */ #define MODKEY Mod1Mask #define TAGKEYS(KEY,TAG) \ --- a/dwm.c 2010-06-10 17:59:47.074990679 -0400 +++ b/dwm.c 2010-06-10 18:12:52.861580521 -0400 @@ -124,7 +124,6 @@ struct Monitor { char ltsymbol[16]; - float mfact; int num; int by; /* bar geometry */ int mx, my, mw, mh; /* screen size */ @@ -140,9 +139,19 @@ Monitor *next; Window barwin; const Layout *lt[2]; + int curtag; + int prevtag; + const Layout **lts; + double *mfacts; }; typedef struct { + const char *name; + const Layout *layout; + float mfact; +} Tag; + +typedef struct { const char *class; const char *instance; const char *title; @@ -435,7 +444,7 @@ if(ev->window == selmon->barwin) { i = x = 0; do { - x += TEXTW(tags[i]); + x += TEXTW(tags[i].name); } while(ev->x >= x && ++i < LENGTH(tags)); if(i < LENGTH(tags)) { click = ClkTagBar; @@ -510,6 +519,8 @@ } XUnmapWindow(dpy, mon->barwin); XDestroyWindow(dpy, mon->barwin); + free(mon->mfacts); + free(mon->lts); free(mon); } @@ -611,16 +622,25 @@ Monitor * createmon(void) { Monitor *m; + int i, numtags = LENGTH(tags) + 1; if(!(m = (Monitor *)calloc(1, sizeof(Monitor)))) die("fatal: could not malloc() %u bytes\n", sizeof(Monitor)); + if(!(m->mfacts = calloc(sizeof(double), numtags))) + die("fatal: could not malloc() %u bytes\n", sizeof(double) * numtags); + if(!(m->lts = calloc(sizeof(Layout *), numtags))) + die("fatal: could not malloc() %u bytes\n", sizeof(Layout *) * numtags); m->tagset[0] = m->tagset[1] = 1; - m->mfact = mfact; m->showbar = showbar; m->topbar = topbar; - m->lt[0] = &layouts[0]; + m->curtag = m->prevtag = 1; + for(i = 1; i < numtags; i++) { + m->mfacts[i] = tags[i - 1].mfact < 0 ? mfact : tags[i - 1].mfact; + m->lts[i] = tags[i - 1].layout; + } + m->lt[0] = m->lts[m->curtag]; m->lt[1] = &layouts[1 % LENGTH(layouts)]; - strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol); + strncpy(m->ltsymbol, m->lt[0]->symbol, sizeof m->ltsymbol); return m; } @@ -695,9 +715,9 @@ } dc.x = 0; for(i = 0; i < LENGTH(tags); i++) { - dc.w = TEXTW(tags[i]); + dc.w = TEXTW(tags[i].name); col = m->tagset[m->seltags] & 1 << i ? dc.sel : dc.norm; - drawtext(tags[i], col, urg & 1 << i); + drawtext(tags[i].name, col, urg & 1 << i); drawsquare(m == selmon && selmon->sel && selmon->sel->tags & 1 << i, occ & 1 << i, urg & 1 << i, col); dc.x += dc.w; @@ -1509,10 +1529,10 @@ if(!arg || !selmon->lt[selmon->sellt]->arrange) return; - f = arg->f < 1.0 ? arg->f + selmon->mfact : arg->f - 1.0; + f = arg->f < 1.0 ? arg->f + selmon->mfacts[selmon->curtag] : arg->f - 1.0; if(f < 0.1 || f > 0.9) return; - selmon->mfact = f; + selmon->mfacts[selmon->curtag] = f; arrange(selmon); } @@ -1645,7 +1665,7 @@ return; /* master */ c = nexttiled(m->clients); - mw = m->mfact * m->ww; + mw = selmon->mfacts[selmon->curtag] * m->ww; resize(c, m->wx, m->wy, (n == 1 ? m->ww : mw) - 2 * c->bw, m->wh - 2 * c->bw, False); if(--n == 0) return; @@ -1686,12 +1706,24 @@ void toggletag(const Arg *arg) { unsigned int newtags; + unsigned int i; if(!selmon->sel) return; newtags = selmon->sel->tags ^ (arg->ui & TAGMASK); if(newtags) { selmon->sel->tags = newtags; + if(newtags == ~0) { + selmon->prevtag = selmon->curtag; + selmon->curtag = 0; + } + if(!(newtags & 1 << (selmon->curtag - 1))) { + selmon->prevtag = selmon->curtag; + for(i=0; !(newtags & 1 << i); i++); + selmon->curtag = i + 1; + } + selmon->sel->tags = newtags; + selmon->lt[selmon->sellt] = selmon->lts[selmon->curtag]; arrange(selmon); } } @@ -1959,11 +1991,26 @@ void view(const Arg *arg) { + unsigned int i; + if((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags]) return; selmon->seltags ^= 1; /* toggle sel tagset */ - if(arg->ui & TAGMASK) + if(arg->ui & TAGMASK) { selmon->tagset[selmon->seltags] = arg->ui & TAGMASK; + selmon->prevtag = selmon->curtag; + if(arg->ui == ~0) + selmon->curtag = 0; + else { + for (i=0; !(arg->ui & 1 << i); i++); + selmon->curtag = i + 1; + } + } else { + selmon->prevtag= selmon->curtag ^ selmon->prevtag; + selmon->curtag^= selmon->prevtag; + selmon->prevtag= selmon->curtag ^ selmon->prevtag; + } + selmon->lt[selmon->sellt] = selmon->lts[selmon->curtag]; arrange(selmon); }