diff --git a/calmwm.h b/calmwm.h
index b365983..9ac93b0 100644
--- a/calmwm.h
+++ b/calmwm.h
@@ -319,6 +319,7 @@ void                         client_map(struct client_ctx 
*);
 void                    client_maximize(struct client_ctx *);
 void                    client_move(struct client_ctx *);
 void                    client_mtf(struct client_ctx *);
+struct client_ctx      *client_mrusearch(struct screen_ctx *, struct group_ctx 
*);
 struct client_ctx      *client_new(Window, struct screen_ctx *, int);
 void                    client_ptrsave(struct client_ctx *);
 void                    client_ptrwarp(struct client_ctx *);
diff --git a/client.c b/client.c
index 2cb0b1e..a53ccb0 100644
--- a/client.c
+++ b/client.c
@@ -643,6 +643,32 @@ client_cycle(struct screen_ctx *sc, int flags)
        client_ptrwarp(newcc);
 }
 
+struct client_ctx *
+client_mrusearch(struct screen_ctx *sc, struct group_ctx *gc) 
+{
+       int again = 1;
+       struct client_ctx *cc;
+
+       if (TAILQ_EMPTY(&sc->mruq))
+               return NULL;
+
+       cc = TAILQ_FIRST(&sc->mruq);
+       while (again) {
+               again = 0;
+
+               /* Only cycle visible and non-ignored windows. */
+               if ((cc->flags & (CLIENT_HIDDEN|CLIENT_IGNORE))
+                               && cc->group != gc)
+                       again = 1;
+               else
+                       break;
+               cc = client_mrunext(cc);
+               if (cc == TAILQ_FIRST(&sc->mruq))
+                       return NULL;
+       }
+       return cc;
+}
+
 static struct client_ctx *
 client_mrunext(struct client_ctx *cc)
 {
diff --git a/group.c b/group.c
index f698cc7..f03e4a3 100644
--- a/group.c
+++ b/group.c
@@ -303,16 +303,22 @@ void
 group_only(struct screen_ctx *sc, int idx)
 {
        int      i;
+       struct group_ctx        *gc;
+       struct client_ctx       *cc;
 
        if (idx < 0 || idx >= CALMWM_NGROUPS)
                err(1, "group_only: index out of range (%d)", idx);
 
+       gc = &sc->groups[idx];
+
        for (i = 0; i < CALMWM_NGROUPS; i++) {
                if (i == idx)
                        group_show(sc, &sc->groups[i]);
                else
                        group_hide(sc, &sc->groups[i]);
        }
+       if ((cc = client_mrusearch(sc, gc)) != NULL)
+               client_ptrwarp(cc);
 }
 
 /*
-- 
1.7.6

Reply via email to