diff -r 78d663b698f0 dwm.c --- a/dwm.c Thu Oct 25 20:24:59 2007 +0200 +++ b/dwm.c Sat Oct 27 11:46:16 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); @@ -193,12 +194,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; @@ -229,6 +229,10 @@ Window barwin, root; Window barwin, root; Regs *regs = NULL; +unsigned int *bpos; +unsigned int *ltidxs; +double *mwfacts; + /* configuration, allows nested code to access above variables */ #include "config.h" @@ -277,7 +281,7 @@ arrange(void) { unban(c); else ban(c); - layouts[ltidx].arrange(); + layouts[ltidxs[csel]].arrange(); focus(NULL); restack(); } @@ -396,6 +400,7 @@ cleanup(void) { XFreeCursor(dpy, cursor[CurMove]); XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); XSync(dpy, False); + deinitpertag(); } void @@ -504,6 +509,14 @@ configurerequest(XEvent *e) { } void +deinitpertag(void) +{ + free(bpos); + free(ltidxs); + free(mwfacts); +} + +void destroynotify(XEvent *e) { Client *c; XDestroyWindowEvent *ev = &e->xdestroywindow; @@ -549,7 +562,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 +908,7 @@ Bool Bool isarrange(void (*func)()) { - return func == layouts[ltidx].arrange; + return func == layouts[ltidxs[csel]].arrange; } Bool @@ -1378,8 +1391,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 +1400,7 @@ setlayout(const char *arg) { break; if(i == nlayouts) return; - ltidx = i; + ltidxs[csel] = i; } if(sel) arrange(); @@ -1403,16 +1416,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 +1492,13 @@ setup(void) { dc.h = bh = dc.font.height + 2; /* init layouts */ - mwfact = MWFACT; + ltidxs = (unsigned int*)emallocz(sizeof(unsigned int) * NTAGS); + mwfacts = (double*)emallocz(sizeof(double) * NTAGS); + 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 +1507,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; @@ -1570,7 +1591,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 +1627,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 +1694,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 +1751,7 @@ updatebarpos(void) { way = sy; wah = sh; waw = sw; - switch(bpos) { + switch(bpos[csel]) { default: wah -= bh; way += bh; @@ -1836,12 +1861,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 +1878,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);