JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
simplified left over re-assignment
[dwm.git] / dwm.c
diff --git a/dwm.c b/dwm.c
index 5625237..fbda0bb 100644 (file)
--- a/dwm.c
+++ b/dwm.c
@@ -375,14 +375,14 @@ arrange(void) {
 
 void
 attach(Client *c) {
-       c->next = selmon->clients;
-       selmon->clients = c;
+       c->next = c->mon->clients;
+       c->mon->clients = c;
 }
 
 void
 attachstack(Client *c) {
-       c->snext = selmon->stack;
-       selmon->stack = c;
+       c->snext = c->mon->stack;
+       c->mon->stack = c;
 }
 
 void
@@ -1475,11 +1475,20 @@ tag(const Arg *arg) {
 void
 tagmon(const Arg *arg) {
        unsigned int i;
+       Client *c;
        Monitor *m;
 
+       if(!(c = selmon->sel))
+               return;
        for(i = 0, m = mons; m; m = m->next, i++)
                if(i == arg->ui) {
-                       selmon->sel->m = m;
+                       detach(c);
+                       detachstack(c);
+                       c->mon = m;
+                       attach(c);
+                       attachstack(c);
+                       selmon->sel = selmon->stack;
+                       m->sel = c;
                        arrange();
                        break;
                }
@@ -1695,7 +1704,7 @@ updategeom(void) {
                for(tm = mons; tm; tm = tm->next)
                        if(tm->screen_number == m->screen_number) {
                                m->clients = tm->clients;
-                               m->stack = tm->stack;
+                               m->sel = m->stack = tm->stack;
                                tm->clients = NULL;
                                tm->stack = NULL;
                                for(c = m->clients; c; c = c->next)
@@ -1705,18 +1714,12 @@ updategeom(void) {
 
        /* 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->stack = tm->stack;
-                       tm->stack = c;
+               while((c = tm->clients)) {
+                       detach(c);
+                       detachstack(c);
+                       c->mon = newmons;
+                       attach(c);
+                       attachstack(c);
                }
        }