- /* if we're not cycling and a window gets focus, add it to the top of the
- * cycle stack.
- */
- if (_stacked_cycling && !_cycling) {
- _clients.remove(*_active);
- _clients.push_front(*_active);
+ if (_active != end) {
+ /* if we're not cycling and a window gets focus, add it to the top of the
+ * cycle stack.
+ */
+ if (_stacked_cycling && !_cycling) {
+ XWindow *win = *_active;
+ _clients.remove(win);
+ _clients.push_front(win);
+ _active = _clients.begin();
+
+ _last_active = _active;
+ }