- /* reassign left over clients with disappeared screen number */
- for(c = clients; c; c = c->next)
- if(c->m->screen_number >= n)
- c->m = newmons;
+ /* reassign left over clients of disappeared monitors */
+ for(tm = mons; tm; tm = tm->next) {
+ while(tm->clients) {
+ c = tm->clients->next;
+ tm->clients->next = newmons->clients;
+ tm->clients->mon = newmons;
+ newmons->clients = tm->clients;
+ tm->clients = c;
+ }
+ while(tm->stack) {
+ c = tm->stack->snext;
+ tm->stack->snext = newmons->stack;
+ newmons->sel = newmons->stack = tm->stack;
+ tm->stack = c;
+ }
+ }