summary refs log tree commit diff
path: root/group.c
diff options
context:
space:
mode:
authorokan <okan>2015-08-21 15:52:49 +0000
committerokan <okan>2015-08-21 15:52:49 +0000
commit871c9f24ba413a7c528ddff2d5c4c8f1601364f3 (patch)
tree8a9d22031c8ccf85297376e52df5abc2c1945f61 /group.c
parent54bbd88e5108cc44822763038bb9bebb4cf4dcbb (diff)
downloadcwm-871c9f24ba413a7c528ddff2d5c4c8f1601364f3.tar.gz
cwm-871c9f24ba413a7c528ddff2d5c4c8f1601364f3.tar.xz
cwm-871c9f24ba413a7c528ddff2d5c4c8f1601364f3.zip
Bring group and client cycle closer together.
Diffstat (limited to 'group.c')
-rw-r--r--group.c54
1 files changed, 34 insertions, 20 deletions
diff --git a/group.c b/group.c
index 1bf2fd7..bbcd6cf 100644
--- a/group.c
+++ b/group.c
@@ -32,6 +32,8 @@
 
 #include "calmwm.h"
 
+static struct group_ctx	*group_next(struct group_ctx *);
+static struct group_ctx	*group_prev(struct group_ctx *);
 static void		 group_assign(struct group_ctx *, struct client_ctx *);
 static void		 group_restack(struct group_ctx *);
 static void		 group_setactive(struct group_ctx *);
@@ -255,36 +257,28 @@ group_only(struct screen_ctx *sc, int idx)
 	}
 }
 
-/*
- * Cycle through active groups.  If none exist, then just stay put.
- */
 void
 group_cycle(struct screen_ctx *sc, int flags)
 {
-	struct group_ctx	*gc, *showgroup = NULL;
+	struct group_ctx	*newgc, *oldgc, *showgroup = NULL;
 
-	if (((gc = sc->group_active)) == NULL)
-		errx(1, "group_cycle: no active group");
+	oldgc = sc->group_active;
 
+	newgc = oldgc;
 	for (;;) {
-		gc = (flags & CWM_RCYCLE) ? TAILQ_PREV(gc, group_ctx_q,
-		    entry) : TAILQ_NEXT(gc, entry);
-		if (gc == NULL)
-			gc = (flags & CWM_RCYCLE) ? TAILQ_LAST(&sc->groupq,
-			    group_ctx_q) : TAILQ_FIRST(&sc->groupq);
-		if (gc == sc->group_active)
+		newgc = (flags & CWM_RCYCLE) ? group_prev(newgc) :
+		    group_next(newgc);
+
+		if (newgc == oldgc)
 			break;
 
-		if (!group_holds_only_sticky(gc) && showgroup == NULL)
-			showgroup = gc;
-		else if (!group_holds_only_hidden(gc))
-			group_hide(gc);
+		if (!group_holds_only_sticky(newgc) && showgroup == NULL)
+			showgroup = newgc;
+		else if (!group_holds_only_hidden(newgc))
+			group_hide(newgc);
 	}
 
-	if (showgroup == NULL)
-		return;
-
-	group_hide(sc->group_active);
+	group_hide(oldgc);
 
 	if (group_holds_only_hidden(showgroup))
 		group_show(showgroup);
@@ -292,6 +286,26 @@ group_cycle(struct screen_ctx *sc, int flags)
 		group_setactive(showgroup);
 }
 
+static struct group_ctx *
+group_next(struct group_ctx *gc)
+{
+	struct screen_ctx	*sc = gc->sc;
+	struct group_ctx	*newgc;
+
+	return(((newgc = TAILQ_NEXT(gc, entry)) != NULL) ?
+	    newgc : TAILQ_FIRST(&sc->groupq));
+}
+
+static struct group_ctx *
+group_prev(struct group_ctx *gc)
+{
+	struct screen_ctx	*sc = gc->sc;
+	struct group_ctx	*newgc;
+
+	return(((newgc = TAILQ_PREV(gc, group_ctx_q, entry)) != NULL) ?
+	    newgc : TAILQ_LAST(&sc->groupq, group_ctx_q));
+}
+
 void
 group_alltoggle(struct screen_ctx *sc)
 {