I accidentally killed restacking on group_show().  Sorry about
that.  Here's version 2 of the patch.

Vadik.

Quoth Vadim Vygonets on Sat, Nov 21, 2015:
> After cycling through many windows, the original window may be
> obscured by many others, and if you still want to see its
> contents you end up doing the Alt-Tab-Tab-Tab-Tab-Tab, Alt-Tab,
> Alt-Tab dance.
> 
> This patch adds restacking of windows during cycling.  Hold Alt,
> press Tab and a window will be raised.  Press Tab again while
> still holding Alt and that window will be lowered back before
> another is raised.  Once you release Alt, the original window
> will be hidden behind no more than one other (the target),
> assuming it was raised before.

-- 
Parents often talk about the younger generation as if they
didn't have much of anything to do with it.
Index: calmwm.h
===================================================================
RCS file: /cvs/xenocara/app/cwm/calmwm.h,v
retrieving revision 1.311
diff -u -r1.311 calmwm.h
--- calmwm.h	12 Nov 2015 21:28:03 -0000	1.311
+++ calmwm.h	22 Nov 2015 15:33:22 -0000
@@ -62,6 +62,9 @@
 #define CWM_CLIENT_RCYCLE	0x0002
 #define CWM_CLIENT_CYCLE_INGRP	0x0004
 
+#define CWM_CLIENT_RESTACK_GROUP	0x0001
+#define CWM_CLIENT_RESTACK_HIDDEN	0x0002
+
 #define CWM_CLIENT_TILE_HORIZ	0x0001
 #define CWM_CLIENT_TILE_VERT	0x0002
 
@@ -385,6 +388,7 @@
 void			 client_applysizehints(struct client_ctx *);
 void			 client_config(struct client_ctx *);
 struct client_ctx	*client_current(void);
+void			 client_restack(struct client_ctx_q *, int);
 void			 client_cycle(struct screen_ctx *, int);
 void			 client_cycle_leave(struct screen_ctx *);
 void			 client_delete(struct client_ctx *);
Index: client.c
===================================================================
RCS file: /cvs/xenocara/app/cwm/client.c,v
retrieving revision 1.214
diff -u -r1.214 client.c
--- client.c	12 Nov 2015 18:33:30 -0000	1.214
+++ client.c	22 Nov 2015 15:33:22 -0000
@@ -664,6 +664,54 @@
 }
 
 void
+client_restack(struct client_ctx_q *clientq, int flags)
+{
+#define CLIENTQ_FOREACH(var, head, ingrp)				\
+	for((var) = TAILQ_FIRST(head);					\
+	    (var) != TAILQ_END(head);					\
+	    (var) = (ingrp) ?						\
+		TAILQ_NEXT(var, group_entry) : TAILQ_NEXT(var, entry))
+	struct client_ctx	*cc;
+	Window			*winlist;
+	int			 i, lastempty = -1;
+	int			 nwins = 0, highstack = 0;
+
+	CLIENTQ_FOREACH(cc, clientq, flags & CWM_CLIENT_RESTACK_GROUP) {
+		if (!(flags & CWM_CLIENT_RESTACK_HIDDEN) &&
+		    (cc->flags & CLIENT_HIDDEN)) {
+			continue;
+		}
+		if (cc->stackingorder > highstack)
+			highstack = cc->stackingorder;
+	}
+	winlist = xreallocarray(NULL, (highstack + 1), sizeof(*winlist));
+
+	/* Invert the stacking order for XRestackWindows(). */
+	CLIENTQ_FOREACH(cc, clientq, flags & CWM_CLIENT_RESTACK_GROUP) {
+		if (!(flags & CWM_CLIENT_RESTACK_HIDDEN) &&
+		    (cc->flags & CLIENT_HIDDEN)) {
+			continue;
+		}
+		winlist[highstack - cc->stackingorder] = cc->win;
+		nwins++;
+	}
+
+	/* Un-sparseify */
+	for (i = 0; i <= highstack; i++) {
+		if (!winlist[i] && lastempty == -1)
+			lastempty = i;
+		else if (winlist[i] && lastempty != -1) {
+			winlist[lastempty] = winlist[i];
+			if (++lastempty == i)
+				lastempty = -1;
+		}
+	}
+
+	XRestackWindows(X_Dpy, winlist, nwins);
+	free(winlist);
+}
+
+void
 client_cycle(struct screen_ctx *sc, int flags)
 {
 	struct client_ctx	*newcc, *oldcc;
@@ -704,9 +752,15 @@
 		}
 	}
 
-	/* reset when cycling mod is released. XXX I hate this hack */
-	sc->cycling = 1;
 	client_ptrsave(oldcc);
+	if (!sc->cycling) {
+		/* reset when cycling mod is released. XXX I hate this hack */
+		sc->cycling = 1;
+		screen_updatestackingorder(sc);
+	} else {
+		client_restack(&sc->clientq, (flags & CWM_CLIENT_CYCLE_INGRP) ?
+		    CWM_CLIENT_RESTACK_GROUP : 0);
+	}
 	client_ptrwarp(newcc);
 }
 
Index: group.c
===================================================================
RCS file: /cvs/xenocara/app/cwm/group.c,v
retrieving revision 1.121
diff -u -r1.121 group.c
--- group.c	10 Nov 2015 20:05:33 -0000	1.121
+++ group.c	22 Nov 2015 15:33:22 -0000
@@ -34,7 +34,6 @@
 
 static struct group_ctx	*group_next(struct group_ctx *);
 static struct group_ctx	*group_prev(struct group_ctx *);
-static void		 group_restack(struct group_ctx *);
 static void		 group_setactive(struct group_ctx *);
 
 const char *num_to_name[] = {
@@ -82,43 +81,9 @@
 			client_unhide(cc);
 	}
 
-	group_restack(gc);
+	client_restack(&gc->clientq,
+	    CWM_CLIENT_RESTACK_GROUP | CWM_CLIENT_RESTACK_HIDDEN);
 	group_setactive(gc);
-}
-
-static void
-group_restack(struct group_ctx *gc)
-{
-	struct client_ctx	*cc;
-	Window			*winlist;
-	int			 i, lastempty = -1;
-	int			 nwins = 0, highstack = 0;
-
-	TAILQ_FOREACH(cc, &gc->clientq, group_entry) {
-		if (cc->stackingorder > highstack)
-			highstack = cc->stackingorder;
-	}
-	winlist = xreallocarray(NULL, (highstack + 1), sizeof(*winlist));
-
-	/* Invert the stacking order for XRestackWindows(). */
-	TAILQ_FOREACH(cc, &gc->clientq, group_entry) {
-		winlist[highstack - cc->stackingorder] = cc->win;
-		nwins++;
-	}
-
-	/* Un-sparseify */
-	for (i = 0; i <= highstack; i++) {
-		if (!winlist[i] && lastempty == -1)
-			lastempty = i;
-		else if (winlist[i] && lastempty != -1) {
-			winlist[lastempty] = winlist[i];
-			if (++lastempty == i)
-				lastempty = -1;
-		}
-	}
-
-	XRestackWindows(X_Dpy, winlist, nwins);
-	free(winlist);
 }
 
 void

Reply via email to