Hi,

attached patch makes one array for both sel and prevtags. So there is
no need to swap them in memory in view() as we only change seltags
pointer to point viewtags[0] or viewtags[1].

It also with little change can support arbitrary number of saved tags
set (3 save position can be usable, with modkey-shift-tab going on
"next" state in queue).

-Ph
diff -r 595ed1a4447c dwm.c
--- a/dwm.c	Tue Apr 08 11:49:35 2008 +0100
+++ b/dwm.c	Sun Apr 20 17:44:51 2008 +0200
@@ -231,11 +231,12 @@ Atom wmatom[WMLast], netatom[NetLast];
 Atom wmatom[WMLast], netatom[NetLast];
 Bool otherwm, readin;
 Bool running = True;
-Bool *prevtags;
-Bool *seltags;
 Client *clients = NULL;
 Client *sel = NULL;
+Bool *seltags;
 Client *stack = NULL;
+Bool *viewtags[2];
+int viewtags_set = 0;
 Cursor cursor[CurLast];
 Display *dpy;
 DC dc = {0};
@@ -246,7 +247,6 @@ Window root, barwin;
 /* configuration, allows nested code to access above variables */
 #include "config.h"
 #define TAGSZ (LENGTH(tags) * sizeof(Bool))
-static Bool tmp[LENGTH(tags)];
 
 /* function implementations */
 
@@ -1162,11 +1162,10 @@ quit(const char *arg) {
 
 void
 reapply(const char *arg) {
-	static Bool zerotags[LENGTH(tags)] = { 0 };
 	Client *c;
 
 	for(c = clients; c; c = c->next) {
-		memcpy(c->tags, zerotags, sizeof zerotags);
+		memset(c->tags, 0, TAGSZ);
 		applyrules(c);
 	}
 	arrange();
@@ -1515,9 +1514,10 @@ setup(void) {
 		XSetFont(dpy, dc.gc, dc.font.xfont->fid);
 
 	/* init tags */
-	seltags = emallocz(TAGSZ);
-	prevtags = emallocz(TAGSZ);
-	seltags[0] = prevtags[0] = True;
+	viewtags[0] = emallocz(TAGSZ);
+	viewtags[1] = emallocz(TAGSZ);
+	viewtags[0][0] = viewtags[1][0] = True;
+	seltags = viewtags[0];
 
 	/* init layouts */
 	lt = &layouts[0];
@@ -1842,9 +1842,9 @@ updatewmhints(Client *c) {
 	}
 }
 
-
 void
 view(const char *arg) {
+	Bool tmp[LENGTH(tags)];
 	unsigned int i;
 
 	for(i = 0; i < LENGTH(tags); i++)
@@ -1852,7 +1852,7 @@ view(const char *arg) {
 	tmp[idxoftag(arg)] = True;
 
 	if(memcmp(seltags, tmp, TAGSZ) != 0) {
-		memcpy(prevtags, seltags, TAGSZ);
+		seltags = viewtags[viewtags_set ^= 1];  /* toggle tagset */
 		memcpy(seltags, tmp, TAGSZ);
 		arrange();
 	}
@@ -1860,10 +1860,8 @@ view(const char *arg) {
 
 void
 viewprevtag(const char *arg) {
+	seltags = viewtags[viewtags_set ^= 1];  /* toggle tagset */
 
-	memcpy(tmp, seltags, TAGSZ);
-	memcpy(seltags, prevtags, TAGSZ);
-	memcpy(prevtags, tmp, TAGSZ);
 	arrange();
 }
 

Reply via email to