[hackers] [dwm][PATCH 1/2] add nextvisible and nextstackvisible

From: <ssd_AT_mailless.org>
Date: Fri, 21 Oct 2016 01:18:13 +0200

From: ssd <ssd_AT_mailless.org>

reads better and is less error prone. I trade this off for a few LOC
more.
---
 dwm.c | 30 ++++++++++++++++++++++--------
 1 file changed, 22 insertions(+), 8 deletions(-)
diff --git a/dwm.c b/dwm.c
index 421bf27..cc1d470 100644
--- a/dwm.c
+++ b/dwm.c
_AT_@ -186,6 +186,8 @@ static void monocle(Monitor *m);
 static void motionnotify(XEvent *e);
 static void movemouse(const Arg *arg);
 static Client *nexttiled(Client *c);
+static Client *nextvisible(Client *c);
+static Client *nextstackvisible(Client *c);
 static void pop(Client *);
 static void propertynotify(XEvent *e);
 static void quit(const Arg *arg);
_AT_@ -679,15 +681,13 @@ detach(Client *c)
 void
 detachstack(Client *c)
 {
-	Client **tc, *t;
+	Client **tc;
 
 	for (tc = &c->mon->stack; *tc && *tc != c; tc = &(*tc)->snext);
 	*tc = c->snext;
 
-	if (c == c->mon->sel) {
-		for (t = c->mon->stack; t && !ISVISIBLE(t); t = t->snext);
-		c->mon->sel = t;
-	}
+	if (c == c->mon->sel)
+		c->mon->sel = nextstackvisible(c->mon->stack);
 }
 
 Monitor *
_AT_@ -797,7 +797,7 @@ void
 focus(Client *c)
 {
 	if (!c || !ISVISIBLE(c))
-		for (c = selmon->stack; c && !ISVISIBLE(c); c = c->snext);
+		c = nextstackvisible(selmon->stack);
 	/* was if (selmon->sel) */
 	if (selmon->sel && selmon->sel != c)
 		unfocus(selmon->sel, 0);
_AT_@ -852,9 +852,9 @@ focusstack(const Arg *arg)
 	if (!selmon->sel)
 		return;
 	if (arg->i > 0) {
-		for (c = selmon->sel->next; c && !ISVISIBLE(c); c = c->next);
+		c = nextvisible(selmon->sel->next);
 		if (!c)
-			for (c = selmon->clients; c && !ISVISIBLE(c); c = c->next);
+			c = nextvisible(selmon->clients);
 	} else {
 		for (i = selmon->clients; i != selmon->sel; i = i->next)
 			if (ISVISIBLE(i))
_AT_@ -1219,6 +1219,20 @@ nexttiled(Client *c)
 	return c;
 }
 
+Client *
+nextvisible(Client *c)
+{
+	for (; c && !ISVISIBLE(c); c = c->next);
+	return c;
+}
+
+Client *
+nextstackvisible(Client *c)
+{
+	for (; c && !ISVISIBLE(c); c = c->snext);
+	return c;
+}
+
 void
 pop(Client *c)
 {
-- 
2.10.0
Received on Fri Oct 21 2016 - 01:18:13 CEST

This archive was generated by hypermail 2.3.0 : Fri Oct 21 2016 - 01:24:21 CEST