// WARNING if you detach() before detachstack() this will select last visible window
for(i = nextvisible(c->mon->clients); i && i != c; i = nextvisible(i->next))
next_sel = i;
- // failing that, find first visible window
+ // failing that, find first visible window (besides c)
if (!next_sel)
- for(i = nextvisible(c->mon->clients); i && i != c; i = nextvisible(i->next))
+ for(i = nextvisible(c->mon->clients); i && i == c; i = nextvisible(i->next));
+ if (i != c)
next_sel = i;
c->mon->sel = next_sel;
}