From: ssd <[email protected]>

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
@@ -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);
@@ -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 *
@@ -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);
@@ -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))
@@ -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


Reply via email to