- // determine if this window is invalid for cycling to
- const XWindow *t = *target;
- if (t->iconic()) continue;
- if (! allscreens && t->getScreen() != this) continue;
- if (! alldesktops && ! (t->desktop() == _active_desktop ||
- t->desktop() == 0xffffffff)) continue;
- if (sameclass && ! classname.empty() &&
- t->appClass() != classname) continue;
- if (! t->canFocus()) continue;
-
- // found a good window!
- t->focus();
- return;
+ // start back at the beginning of the loop
+ if (target == end)
+ continue;
+
+ // determine if this window is invalid for cycling to
+ t = *target;
+ if (t->iconic()) continue;
+ if (! allscreens && t->getScreen() != this) continue;
+ if (! alldesktops && ! (t->desktop() == _active_desktop ||
+ t->desktop() == 0xffffffff)) continue;
+ if (sameclass && ! classname.empty() &&
+ t->appClass() != classname) continue;
+ if (! t->canFocus()) continue;
+
+ // found a good window so break out of the while, and perhaps continue
+ // with the for loop
+ break;
+ }