[dwm] [patch] 'per tag' patch for dwm-4.4.1+stackcol

From: Chris Webb <chris_AT_arachsys.com>
Date: Wed, 12 Sep 2007 13:32:19 +0100

The attached patch applies on top of my stackcol patch. (It won't apply
without it, because they both heavily touch tile.c.)

It changes the selected layout and values of mwfact, nrows, ncols and
nmaster from being global to being indexed by current tag. The definition
of 'current tag' is the same as that used by the taglayouts patch: view()
resets the current tag, whereas toggleview() leaves it unchanged. This
results in fairly natural, predictable behaviour.

As with the previous patch, I'd be interested in feedback from anyone
who finds this useful.

Cheers,

Chris.

diff -uNrdp dwm-4.4.1/dwm.h dwm-4.4.1-tl/dwm.h
--- dwm-4.4.1/dwm.h 2007-08-26 11:53:49.000000000 +0100
+++ dwm-4.4.1-tl/dwm.h 2007-09-12 13:00:54.000000000 +0100
@@ -79,6 +79,7 @@ extern int screen, sx, sy, sw, sh; /* s
 extern int wax, way, wah, waw; /* windowarea geometry */
 extern unsigned int bh, blw, bpos; /* bar height, bar layout label width, bar position */
 extern unsigned int ntags, numlockmask; /* number of tags, numlock mask */
+extern unsigned seltag; /* current master tag for layout purposes */
 extern void (*handler[LASTEvent])(XEvent *); /* event handler */
 extern Atom wmatom[WMLast], netatom[NetLast];
 extern Bool selscreen, *seltags; /* seltags is array of Bool */
@@ -87,6 +88,8 @@ extern Cursor cursor[CurLast];
 extern DC dc; /* global draw context */
 extern Display *dpy;
 extern Window root, barwin;
+extern double *mwfact;
+extern unsigned int *nmaster, *nrows, *ncols;
 
 /* client.c */
 void attach(Client *c); /* attaches c to global client list */
@@ -125,6 +128,7 @@ void focusnext(const char *arg); /* focu
 void focusprev(const char *arg); /* focuses prev visible client */
 const char *getsymbol(void); /* returns symbol of enabled layout */
 void initlayouts(void); /* initialize layout array */
+void freelayouts(void); /* free layout array */
 Bool isarrange(void (*func)()); /* returns True if func is the layout function in use */
 Bool isfloating(void); /* returns True if floating layout is enabled */
 Bool isvisible(Client *c); /* returns True if client is visible */
diff -uNrdp dwm-4.4.1/main.c dwm-4.4.1-tl/main.c
--- dwm-4.4.1/main.c 2007-09-09 16:41:18.000000000 +0100
+++ dwm-4.4.1-tl/main.c 2007-09-12 12:49:46.000000000 +0100
@@ -20,6 +20,7 @@ int screen, sx, sy, sw, sh, wax, way, wa
 unsigned int bh, ntags;
 unsigned int bpos = BARPOS;
 unsigned int numlockmask = 0;
+unsigned int seltag = 0;
 Atom wmatom[WMLast], netatom[NetLast];
 Bool *seltags;
 Bool selscreen = True;
@@ -31,6 +32,9 @@ Display *dpy;
 DC dc = {0};
 Window root, barwin;
 
+double *mwfact;
+unsigned int *nmaster, *nrows, *ncols;
+
 /* static */
 
 static int (*xerrorxlib)(Display *, XErrorEvent *);
@@ -58,6 +62,7 @@ cleanup(void) {
         XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
         XSync(dpy, False);
         free(seltags);
+ freelayouts();
 }
 
 static unsigned long
diff -uNrdp dwm-4.4.1/screen.c dwm-4.4.1-tl/screen.c
--- dwm-4.4.1/screen.c 2007-08-26 11:53:49.000000000 +0100
+++ dwm-4.4.1-tl/screen.c 2007-09-12 12:52:28.000000000 +0100
@@ -29,7 +29,7 @@ RULES
 
 static unsigned int nrules = 0;
 static unsigned int nlayouts = 0;
-static unsigned int ltidx = 0; /* default */
+static unsigned int *ltidx;
 static Regs *regs = NULL;
 
 static unsigned int
@@ -80,8 +80,7 @@ applyrules(Client *c) {
                                 }
                         }
                 }
- if(ch.res_class)
- XFree(ch.res_class);
+
         if(ch.res_name)
                 XFree(ch.res_name);
         if(!matched)
@@ -98,7 +97,7 @@ arrange(void) {
                         unban(c);
                 else
                         ban(c);
- layouts[ltidx].arrange();
+ layouts[ltidx[seltag]].arrange();
         focus(NULL);
         restack();
 }
@@ -165,13 +164,24 @@ focusprev(const char *arg) {
 const char *
 getsymbol(void)
 {
- return layouts[ltidx].symbol;
+ return layouts[ltidx[seltag]].symbol;
 }
 
 void
 initlayouts(void) {
         unsigned int i, w;
-
+ ltidx = (unsigned int *) emallocz(ntags * sizeof(unsigned int));
+ nmaster = (unsigned int *) emallocz(ntags * sizeof(unsigned int));
+ nrows = (unsigned int *) emallocz(ntags * sizeof(unsigned int));
+ ncols = (unsigned int *) emallocz(ntags * sizeof(unsigned int));
+ mwfact = (double *) emallocz(ntags * sizeof(double));
+ for(i = 0; i < ntags; i++) {
+ ltidx[i] = 0; /* default */
+ nmaster[i] = NMASTER;
+ nrows[i] = NROWS;
+ ncols[i] = NCOLS;
+ mwfact[i] = MWFACT;
+ }
         nlayouts = sizeof layouts / sizeof layouts[0];
         for(blw = i = 0; i < nlayouts; i++) {
                 w = textw(layouts[i].symbol);
@@ -179,16 +189,24 @@ initlayouts(void) {
                         blw = w;
         }
 }
+void
+freelayouts(void) {
+ free(ltidx);
+ free(nmaster);
+ free(nrows);
+ free(ncols);
+ free(mwfact);
+}
 
 Bool
 isfloating(void) {
- return layouts[ltidx].arrange == floating;
+ return layouts[ltidx[seltag]].arrange == floating;
 }
 
 Bool
 isarrange(void (*func)())
 {
- return func == layouts[ltidx].arrange;
+ return func == layouts[ltidx[seltag]].arrange;
 }
 
 Bool
@@ -241,8 +259,8 @@ setlayout(const char *arg) {
         unsigned int i;
 
         if(!arg) {
- if(++ltidx == nlayouts)
- ltidx = 0;;
+ if(++ltidx[seltag] == nlayouts)
+ ltidx[seltag] = 0;;
         }
         else {
                 for(i = 0; i < nlayouts; i++)
@@ -250,7 +268,7 @@ setlayout(const char *arg) {
                                 break;
                 if(i == nlayouts)
                         return;
- ltidx = i;
+ ltidx[seltag] = i;
         }
         if(sel)
                 arrange();
@@ -320,8 +338,12 @@ toggletag(const char *arg) {
         i = idxoftag(arg);
         sel->tags[i] = !sel->tags[i];
         for(j = 0; j < ntags && !sel->tags[j]; j++);
- if(j == ntags)
+ if(j == ntags) {
                 sel->tags[i] = True;
+ j = i;
+ }
+ if (seltag == i)
+ seltag = j;
         arrange();
 }
 
@@ -370,7 +392,9 @@ view(const char *arg) {
         for(i = 0; i < ntags; i++)
                 seltags[i] = arg == NULL;
         i = idxoftag(arg);
- if(i >= 0 && i < ntags)
+ if(i >= 0 && i < ntags) {
+ seltag = i;
                 seltags[i] = True;
+ }
         arrange();
 }
diff -uNrdp dwm-4.4.1/tile.c dwm-4.4.1-tl/tile.c
--- dwm-4.4.1/tile.c 2007-09-09 16:38:27.000000000 +0100
+++ dwm-4.4.1-tl/tile.c 2007-09-12 12:53:31.000000000 +0100
@@ -3,13 +3,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-/* static */
-
-static double mwfact = MWFACT;
-static unsigned int nmaster = NMASTER;
-static unsigned int nrows = NROWS;
-static unsigned int ncols = NCOLS;
-
 /* extern */
 
 void
@@ -23,12 +16,12 @@ setnmaster(const char *arg) {
         else if(arg[0] != '+' && arg[0] != '-')
                 i = atoi(arg);
         else
- i = nmaster + atoi(arg);
+ i = nmaster[seltag] + atoi(arg);
 
         if(i < 0 || wah <= 2 * BORDERPX * i)
                 return;
         
- nmaster = i;
+ nmaster[seltag] = i;
         if(sel)
                 arrange();
         else
@@ -46,11 +39,11 @@ setnrows(const char *arg) {
         else if(arg[0] != '+' && arg[0] != '-')
                 i = atoi(arg);
         else
- i = nrows + atoi(arg);
+ i = nrows[seltag] + atoi(arg);
 
         if(i < 0 || wah <= 2 * BORDERPX * i)
                 return;
- nrows = i;
+ nrows[seltag] = i;
 
         if(sel)
                 arrange();
@@ -69,11 +62,11 @@ setncols(const char *arg) {
         else if(arg[0] != '+' && arg[0] != '-')
                 i = atoi(arg);
         else
- i = ncols + atoi(arg);
+ i = ncols[seltag] + atoi(arg);
 
         if((i < 0) || (i >= 1 && waw / i <= 2 * BORDERPX))
                 return;
- ncols = i;
+ ncols[seltag] = i;
 
         if(sel)
                 arrange();
@@ -89,16 +82,16 @@ setmwfact(const char *arg) {
                 return;
         /* arg handling, manipulate mwfact */
         if(arg == NULL)
- mwfact = MWFACT;
+ mwfact[seltag] = MWFACT;
         else if(1 == sscanf(arg, "%lf", &delta)) {
                 if(arg[0] != '+' && arg[0] != '-')
- mwfact = delta;
+ mwfact[seltag] = delta;
                 else
- mwfact += delta;
- if(mwfact < 0.1)
- mwfact = 0.1;
- else if(mwfact > 0.9)
- mwfact = 0.9;
+ mwfact[seltag] += delta;
+ if(mwfact[seltag] < 0.1)
+ mwfact[seltag] = 0.1;
+ else if(mwfact[seltag] > 0.9)
+ mwfact[seltag] = 0.9;
         }
         arrange();
 }
@@ -112,32 +105,32 @@ tile(void) {
                 n++;
 
         /* calculate correct number of rows */
- if(ncols > 0 && n - nmaster > nrows * ncols)
- rows = (n - nmaster) / ncols + ((n - nmaster) % ncols ? 1 : 0);
+ if(ncols[seltag] > 0 && n - nmaster[seltag] > nrows[seltag] * ncols[seltag])
+ rows = (n - nmaster[seltag]) / ncols[seltag] + ((n - nmaster[seltag]) % ncols[seltag] ? 1 : 0);
         else
- rows = nrows;
+ rows = nrows[seltag];
         
         /* window geoms */
- if (nmaster == 0) {
+ if (nmaster[seltag] == 0) {
                 mh = mw = 0;
         }
- else if (n <= nmaster) {
+ else if (n <= nmaster[seltag]) {
                 mh = wah / (n > 0 ? n : 1);
                 mw = waw;
         }
         else {
- mh = wah / nmaster;
- mw = mwfact * waw;
+ mh = wah / nmaster[seltag];
+ mw = mwfact[seltag] * waw;
         }
 
- if(rows == 0 || n <= nmaster + rows) {
- rows1 = n > nmaster ? n - nmaster : 1;
+ if(rows == 0 || n <= nmaster[seltag] + rows) {
+ rows1 = n > nmaster[seltag] ? n - nmaster[seltag] : 1;
                 tw = tw1 = waw - mw;
                 th = wah / rows1;
         }
         else {
- rows1 = 1 + (n - nmaster - 1) % rows;
- cols = (n - nmaster) / rows + ((n - nmaster) % rows ? 1 : 0);
+ rows1 = 1 + (n - nmaster[seltag] - 1) % rows;
+ cols = (n - nmaster[seltag]) / rows + ((n - nmaster[seltag]) % rows ? 1 : 0);
                 tw = (waw - mw) / cols;
                 tw1 = waw - mw - (cols - 1) * tw;
                 th = wah / rows;
@@ -148,14 +141,14 @@ tile(void) {
 
         for(i = 0, c = nexttiled(clients); c; c = nexttiled(c->next), i++) {
                 c->ismax = False;
- if(i < nmaster) { /* master column */
+ if(i < nmaster[seltag]) { /* master column */
                         nw = mw - 2 * c->border;
                         nh = mh - 2 * c->border;
                         if(i == 0)
- nh += wah - mh * (n < nmaster ? n : nmaster);
+ nh += wah - mh * (n < nmaster[seltag] ? n : nmaster[seltag]);
                 }
- else if(i < nmaster + rows1) { /* first stack column */
- if(i == nmaster) { /* initialise */
+ else if(i < nmaster[seltag] + rows1) { /* first stack column */
+ if(i == nmaster[seltag]) { /* initialise */
                                 ny = way;
                                 nx += mw;
                                 nh = wah - 2*c->border - (rows1 - 1) * th;
@@ -166,7 +159,7 @@ tile(void) {
                         nw = tw1 - 2 * c->border;
                 }
                 else { /* successive stack columns - rows > 0 if we reach here */
- if((i - nmaster - rows1) % rows == 0) { /* reinitialise */
+ if((i - nmaster[seltag] - rows1) % rows == 0) { /* reinitialise */
                                 ny = way;
                                 nx += nw + 2 * c-> border;
                                 nh = wah - 2*c->border - (rows - 1) * th;
Received on Wed Sep 12 2007 - 14:32:24 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 14:52:44 UTC