summaryrefslogtreecommitdiffstats
path: root/dwm.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--dwm.c194
1 files changed, 111 insertions, 83 deletions
diff --git a/dwm.c b/dwm.c
index 896c8a7..59722d3 100644
--- a/dwm.c
+++ b/dwm.c
@@ -1,3 +1,4 @@
1/* TODO: cleanup nexttiled, ISVISIBLE, etc */
1/* See LICENSE file for copyright and license details. 2/* See LICENSE file for copyright and license details.
2 * 3 *
3 * dynamic window manager is designed like any other X client as well. It is 4 * dynamic window manager is designed like any other X client as well. It is
@@ -44,7 +45,7 @@
44#define BUTTONMASK (ButtonPressMask|ButtonReleaseMask) 45#define BUTTONMASK (ButtonPressMask|ButtonReleaseMask)
45#define CLEANMASK(mask) (mask & ~(numlockmask|LockMask)) 46#define CLEANMASK(mask) (mask & ~(numlockmask|LockMask))
46#define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= (RY) && (Y) < (RY) + (RH)) 47#define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= (RY) && (Y) < (RY) + (RH))
47#define ISVISIBLE(M, C) ((M) == (C->m) && (C->tags & M->tagset[M->seltags])) 48#define ISVISIBLE(M, C) ((M) == (C->mon) && (C->tags & M->tagset[M->seltags]))
48#define LENGTH(X) (sizeof X / sizeof X[0]) 49#define LENGTH(X) (sizeof X / sizeof X[0])
49#define MAX(A, B) ((A) > (B) ? (A) : (B)) 50#define MAX(A, B) ((A) > (B) ? (A) : (B))
50#define MIN(A, B) ((A) < (B) ? (A) : (B)) 51#define MIN(A, B) ((A) < (B) ? (A) : (B))
@@ -89,7 +90,7 @@ struct Client {
89 Bool isfixed, isfloating, isurgent; 90 Bool isfixed, isfloating, isurgent;
90 Client *next; 91 Client *next;
91 Client *snext; 92 Client *snext;
92 Monitor *m; 93 Monitor *mon;
93 Window win; 94 Window win;
94}; 95};
95 96
@@ -131,8 +132,11 @@ struct Monitor {
131 unsigned int tagset[2]; 132 unsigned int tagset[2];
132 Bool showbar; 133 Bool showbar;
133 Bool topbar; 134 Bool topbar;
134 Window barwin; 135 Client *clients;
136 Client *sel;
137 Client *stack;
135 Monitor *next; 138 Monitor *next;
139 Window barwin;
136}; 140};
137 141
138typedef struct { 142typedef struct {
@@ -251,9 +255,6 @@ static void (*handler[LASTEvent]) (XEvent *) = {
251static Atom wmatom[WMLast], netatom[NetLast]; 255static Atom wmatom[WMLast], netatom[NetLast];
252static Bool otherwm; 256static Bool otherwm;
253static Bool running = True; 257static Bool running = True;
254static Client *clients = NULL;
255static Client *sel = NULL;
256static Client *stack = NULL;
257static Cursor cursor[CurLast]; 258static Cursor cursor[CurLast];
258static Display *dpy; 259static Display *dpy;
259static DC dc; 260static DC dc;
@@ -290,7 +291,7 @@ applyrules(Client *c) {
290 if(ch.res_name) 291 if(ch.res_name)
291 XFree(ch.res_name); 292 XFree(ch.res_name);
292 } 293 }
293 c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->m->tagset[c->m->seltags]; 294 c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->mon->tagset[c->mon->seltags];
294} 295}
295 296
296Bool 297Bool
@@ -362,7 +363,9 @@ void
362arrange(void) { 363arrange(void) {
363 Monitor *m; 364 Monitor *m;
364 365
365 showhide(stack); 366 /* optimise two loops into one, check focus(NULL) */
367 for(m = mons; m; m = m->next)
368 showhide(m->stack);
366 focus(NULL); 369 focus(NULL);
367 for(m = mons; m; m = m->next) { 370 for(m = mons; m; m = m->next) {
368 if(lt[m->sellt]->arrange) 371 if(lt[m->sellt]->arrange)
@@ -373,14 +376,14 @@ arrange(void) {
373 376
374void 377void
375attach(Client *c) { 378attach(Client *c) {
376 c->next = clients; 379 c->next = selmon->clients;
377 clients = c; 380 selmon->clients = c;
378} 381}
379 382
380void 383void
381attachstack(Client *c) { 384attachstack(Client *c) {
382 c->snext = stack; 385 c->snext = selmon->stack;
383 stack = c; 386 selmon->stack = c;
384} 387}
385 388
386void 389void
@@ -437,11 +440,15 @@ void
437cleanup(void) { 440cleanup(void) {
438 Arg a = {.ui = ~0}; 441 Arg a = {.ui = ~0};
439 Layout foo = { "", NULL }; 442 Layout foo = { "", NULL };
443 Monitor *m;
440 444
441 view(&a); 445 view(&a);
442 lt[selmon->sellt] = &foo; 446 lt[selmon->sellt] = &foo;
443 while(stack) 447
444 unmanage(stack); 448 /* TODO: consider simplifying cleanup code of the stack, perhaps do that in cleanmons() ? */
449 for(m = mons; m; m = m->next)
450 while(m->stack)
451 unmanage(m->stack);
445 if(dc.font.set) 452 if(dc.font.set)
446 XFreeFontSet(dpy, dc.font.set); 453 XFreeFontSet(dpy, dc.font.set);
447 else 454 else
@@ -543,7 +550,7 @@ configurerequest(XEvent *e) {
543 c->y = sy + (sh / 2 - c->h / 2); /* center in y direction */ 550 c->y = sy + (sh / 2 - c->h / 2); /* center in y direction */
544 if((ev->value_mask & (CWX|CWY)) && !(ev->value_mask & (CWWidth|CWHeight))) 551 if((ev->value_mask & (CWX|CWY)) && !(ev->value_mask & (CWWidth|CWHeight)))
545 configure(c); 552 configure(c);
546 if(ISVISIBLE((c->m), c)) 553 if(ISVISIBLE((c->mon), c))
547 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); 554 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
548 } 555 }
549 else 556 else
@@ -575,7 +582,7 @@ void
575detach(Client *c) { 582detach(Client *c) {
576 Client **tc; 583 Client **tc;
577 584
578 for(tc = &clients; *tc && *tc != c; tc = &(*tc)->next); 585 for(tc = &c->mon->clients; *tc && *tc != c; tc = &(*tc)->next);
579 *tc = c->next; 586 *tc = c->next;
580} 587}
581 588
@@ -583,7 +590,7 @@ void
583detachstack(Client *c) { 590detachstack(Client *c) {
584 Client **tc; 591 Client **tc;
585 592
586 for(tc = &stack; *tc && *tc != c; tc = &(*tc)->snext); 593 for(tc = &c->mon->stack; *tc && *tc != c; tc = &(*tc)->snext);
587 *tc = c->snext; 594 *tc = c->snext;
588} 595}
589 596
@@ -604,12 +611,10 @@ drawbar(Monitor *m) {
604 unsigned long *col; 611 unsigned long *col;
605 Client *c; 612 Client *c;
606 613
607 for(c = clients; c; c = c->next) { 614 for(c = m->clients; c; c = c->next) {
608 if(m == c->m) { 615 occ |= c->tags;
609 occ |= c->tags; 616 if(c->isurgent)
610 if(c->isurgent) 617 urg |= c->tags;
611 urg |= c->tags;
612 }
613 } 618 }
614 619
615 dc.x = 0; 620 dc.x = 0;
@@ -628,7 +633,7 @@ drawbar(Monitor *m) {
628 dc.w = TEXTW(tags[i]); 633 dc.w = TEXTW(tags[i]);
629 col = m->tagset[m->seltags] & 1 << i ? dc.sel : dc.norm; 634 col = m->tagset[m->seltags] & 1 << i ? dc.sel : dc.norm;
630 drawtext(tags[i], col, urg & 1 << i); 635 drawtext(tags[i], col, urg & 1 << i);
631 drawsquare(m == selmon && sel && sel->tags & 1 << i, 636 drawsquare(m == selmon && selmon->sel && selmon->sel->tags & 1 << i,
632 occ & 1 << i, urg & 1 << i, col); 637 occ & 1 << i, urg & 1 << i, col);
633 dc.x += dc.w; 638 dc.x += dc.w;
634 } 639 }
@@ -649,9 +654,9 @@ drawbar(Monitor *m) {
649 drawtext(stext, dc.norm, False); 654 drawtext(stext, dc.norm, False);
650 if((dc.w = dc.x - x) > bh) { 655 if((dc.w = dc.x - x) > bh) {
651 dc.x = x; 656 dc.x = x;
652 if(sel) { 657 if(selmon->sel) {
653 drawtext(sel->name, dc.sel, False); 658 drawtext(selmon->sel->name, dc.sel, False);
654 drawsquare(sel->isfixed, sel->isfloating, False, dc.sel); 659 drawsquare(selmon->sel->isfixed, selmon->sel->isfloating, False, dc.sel);
655 } 660 }
656 else 661 else
657 drawtext(NULL, dc.norm, False); 662 drawtext(NULL, dc.norm, False);
@@ -751,11 +756,11 @@ expose(XEvent *e) {
751 756
752void 757void
753focus(Client *c) { 758focus(Client *c) {
754 if(!c || !ISVISIBLE((c->m), c)) 759 if(!c || !ISVISIBLE((c->mon), c))
755 for(c = stack; c && !ISVISIBLE(selmon, c); c = c->snext); 760 for(c = selmon->stack; c && !ISVISIBLE(selmon, c); c = c->snext);
756 if(sel && sel != c) { 761 if(selmon->sel && selmon->sel != c) {
757 grabbuttons(sel, False); 762 grabbuttons(selmon->sel, False);
758 XSetWindowBorder(dpy, sel->win, dc.norm[ColBorder]); 763 XSetWindowBorder(dpy, selmon->sel->win, dc.norm[ColBorder]);
759 } 764 }
760 if(c) { 765 if(c) {
761 if(c->isurgent) 766 if(c->isurgent)
@@ -768,7 +773,7 @@ focus(Client *c) {
768 } 773 }
769 else 774 else
770 XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); 775 XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
771 sel = c; 776 selmon->sel = c;
772 drawbars(); 777 drawbars();
773} 778}
774 779
@@ -776,8 +781,8 @@ void
776focusin(XEvent *e) { /* there are some broken focus acquiring clients */ 781focusin(XEvent *e) { /* there are some broken focus acquiring clients */
777 XFocusChangeEvent *ev = &e->xfocus; 782 XFocusChangeEvent *ev = &e->xfocus;
778 783
779 if(sel && ev->window != sel->win) 784 if(selmon->sel && ev->window != selmon->sel->win)
780 XSetInputFocus(dpy, sel->win, RevertToPointerRoot, CurrentTime); 785 XSetInputFocus(dpy, selmon->sel->win, RevertToPointerRoot, CurrentTime);
781} 786}
782 787
783#ifdef XINERAMA 788#ifdef XINERAMA
@@ -800,15 +805,15 @@ void
800focusstack(const Arg *arg) { 805focusstack(const Arg *arg) {
801 Client *c = NULL, *i; 806 Client *c = NULL, *i;
802 807
803 if(!sel) 808 if(!selmon->sel)
804 return; 809 return;
805 if(arg->i > 0) { 810 if(arg->i > 0) {
806 for(c = sel->next; c && !ISVISIBLE(selmon, c); c = c->next); 811 for(c = selmon->sel->next; c && !ISVISIBLE(selmon, c); c = c->next);
807 if(!c) 812 if(!c)
808 for(c = clients; c && !ISVISIBLE(selmon, c); c = c->next); 813 for(c = selmon->clients; c && !ISVISIBLE(selmon, c); c = c->next);
809 } 814 }
810 else { 815 else {
811 for(i = clients; i != sel; i = i->next) 816 for(i = selmon->clients; i != selmon->sel; i = i->next)
812 if(ISVISIBLE(selmon, i)) 817 if(ISVISIBLE(selmon, i))
813 c = i; 818 c = i;
814 if(!c) 819 if(!c)
@@ -824,9 +829,11 @@ focusstack(const Arg *arg) {
824 829
825Client * 830Client *
826getclient(Window w) { 831getclient(Window w) {
827 Client *c; 832 Client *c = NULL;
833 Monitor *m;
828 834
829 for(c = clients; c && c->win != w; c = c->next); 835 for(m = mons; m; m = m->next)
836 for(c = m->clients; c && c->win != w; c = c->next);
830 return c; 837 return c;
831} 838}
832 839
@@ -992,19 +999,19 @@ void
992killclient(const Arg *arg) { 999killclient(const Arg *arg) {
993 XEvent ev; 1000 XEvent ev;
994 1001
995 if(!sel) 1002 if(!selmon->sel)
996 return; 1003 return;
997 if(isprotodel(sel)) { 1004 if(isprotodel(selmon->sel)) {
998 ev.type = ClientMessage; 1005 ev.type = ClientMessage;
999 ev.xclient.window = sel->win; 1006 ev.xclient.window = selmon->sel->win;
1000 ev.xclient.message_type = wmatom[WMProtocols]; 1007 ev.xclient.message_type = wmatom[WMProtocols];
1001 ev.xclient.format = 32; 1008 ev.xclient.format = 32;
1002 ev.xclient.data.l[0] = wmatom[WMDelete]; 1009 ev.xclient.data.l[0] = wmatom[WMDelete];
1003 ev.xclient.data.l[1] = CurrentTime; 1010 ev.xclient.data.l[1] = CurrentTime;
1004 XSendEvent(dpy, sel->win, False, NoEventMask, &ev); 1011 XSendEvent(dpy, selmon->sel->win, False, NoEventMask, &ev);
1005 } 1012 }
1006 else 1013 else
1007 XKillClient(dpy, sel->win); 1014 XKillClient(dpy, selmon->sel->win);
1008} 1015}
1009 1016
1010void 1017void
@@ -1018,7 +1025,7 @@ manage(Window w, XWindowAttributes *wa) {
1018 die("fatal: could not malloc() %u bytes\n", sizeof(Client)); 1025 die("fatal: could not malloc() %u bytes\n", sizeof(Client));
1019 *c = cz; 1026 *c = cz;
1020 c->win = w; 1027 c->win = w;
1021 c->m = selmon; 1028 c->mon = selmon;
1022 1029
1023 /* geometry */ 1030 /* geometry */
1024 c->x = wa->x; 1031 c->x = wa->x;
@@ -1095,7 +1102,7 @@ void
1095monocle(Monitor *m) { 1102monocle(Monitor *m) {
1096 Client *c; 1103 Client *c;
1097 1104
1098 for(c = nexttiled(m, clients); c; c = nexttiled(m, c->next)) 1105 for(c = nexttiled(m, selmon->clients); c; c = nexttiled(m, c->next))
1099 resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw); 1106 resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw);
1100} 1107}
1101 1108
@@ -1107,7 +1114,7 @@ movemouse(const Arg *arg) {
1107 Window dummy; 1114 Window dummy;
1108 XEvent ev; 1115 XEvent ev;
1109 1116
1110 if(!(c = sel)) 1117 if(!(c = selmon->sel))
1111 return; 1118 return;
1112 restack(selmon); 1119 restack(selmon);
1113 ocx = c->x; 1120 ocx = c->x;
@@ -1185,7 +1192,7 @@ propertynotify(XEvent *e) {
1185 } 1192 }
1186 if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) { 1193 if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) {
1187 updatetitle(c); 1194 updatetitle(c);
1188 if(c == sel) 1195 if(c == selmon->sel)
1189 drawbars(); 1196 drawbars();
1190 } 1197 }
1191 } 1198 }
@@ -1220,7 +1227,7 @@ resizemouse(const Arg *arg) {
1220 Client *c; 1227 Client *c;
1221 XEvent ev; 1228 XEvent ev;
1222 1229
1223 if(!(c = sel)) 1230 if(!(c = selmon->sel))
1224 return; 1231 return;
1225 restack(selmon); 1232 restack(selmon);
1226 ocx = c->x; 1233 ocx = c->x;
@@ -1265,14 +1272,14 @@ restack(Monitor *m) {
1265 XWindowChanges wc; 1272 XWindowChanges wc;
1266 1273
1267 drawbars(); 1274 drawbars();
1268 if(!sel) 1275 if(!selmon->sel)
1269 return; 1276 return;
1270 if(m == selmon && (sel->isfloating || !lt[m->sellt]->arrange)) 1277 if(m == selmon && (selmon->sel->isfloating || !lt[m->sellt]->arrange))
1271 XRaiseWindow(dpy, sel->win); 1278 XRaiseWindow(dpy, selmon->sel->win);
1272 if(lt[m->sellt]->arrange) { 1279 if(lt[m->sellt]->arrange) {
1273 wc.stack_mode = Below; 1280 wc.stack_mode = Below;
1274 wc.sibling = m->barwin; 1281 wc.sibling = m->barwin;
1275 for(c = stack; c; c = c->snext) 1282 for(c = m->stack; c; c = c->snext)
1276 if(!c->isfloating && ISVISIBLE(m, c)) { 1283 if(!c->isfloating && ISVISIBLE(m, c)) {
1277 XConfigureWindow(dpy, c->win, CWSibling|CWStackMode, &wc); 1284 XConfigureWindow(dpy, c->win, CWSibling|CWStackMode, &wc);
1278 wc.sibling = c->win; 1285 wc.sibling = c->win;
@@ -1334,7 +1341,7 @@ setlayout(const Arg *arg) {
1334 selmon->sellt ^= 1; 1341 selmon->sellt ^= 1;
1335 if(arg && arg->v) 1342 if(arg && arg->v)
1336 lt[selmon->sellt] = (Layout *)arg->v; 1343 lt[selmon->sellt] = (Layout *)arg->v;
1337 if(sel) 1344 if(selmon->sel)
1338 arrange(); 1345 arrange();
1339 else 1346 else
1340 drawbars(); 1347 drawbars();
@@ -1425,9 +1432,9 @@ void
1425showhide(Client *c) { 1432showhide(Client *c) {
1426 if(!c) 1433 if(!c)
1427 return; 1434 return;
1428 if(ISVISIBLE((c->m), c)) { /* show clients top down */ 1435 if(ISVISIBLE((c->mon), c)) { /* show clients top down */
1429 XMoveWindow(dpy, c->win, c->x, c->y); 1436 XMoveWindow(dpy, c->win, c->x, c->y);
1430 if(!lt[c->m->sellt]->arrange || c->isfloating) 1437 if(!lt[c->mon->sellt]->arrange || c->isfloating)
1431 resize(c, c->x, c->y, c->w, c->h); 1438 resize(c, c->x, c->y, c->w, c->h);
1432 showhide(c->snext); 1439 showhide(c->snext);
1433 } 1440 }
@@ -1459,8 +1466,8 @@ spawn(const Arg *arg) {
1459 1466
1460void 1467void
1461tag(const Arg *arg) { 1468tag(const Arg *arg) {
1462 if(sel && arg->ui & TAGMASK) { 1469 if(selmon->sel && arg->ui & TAGMASK) {
1463 sel->tags = arg->ui & TAGMASK; 1470 selmon->sel->tags = arg->ui & TAGMASK;
1464 arrange(); 1471 arrange();
1465 } 1472 }
1466} 1473}
@@ -1473,7 +1480,7 @@ tagmon(const Arg *arg) {
1473 1480
1474 for(i = 0, m = mons; m; m = m->next, i++) 1481 for(i = 0, m = mons; m; m = m->next, i++)
1475 if(i == arg->ui) { 1482 if(i == arg->ui) {
1476 sel->m = m; 1483 selmon->sel->m = m;
1477 arrange(); 1484 arrange();
1478 break; 1485 break;
1479 } 1486 }
@@ -1497,12 +1504,12 @@ tile(Monitor *m) {
1497 unsigned int i, n; 1504 unsigned int i, n;
1498 Client *c; 1505 Client *c;
1499 1506
1500 for(n = 0, c = nexttiled(m, clients); c; c = nexttiled(m, c->next), n++); 1507 for(n = 0, c = nexttiled(m, m->clients); c; c = nexttiled(m, c->next), n++);
1501 if(n == 0) 1508 if(n == 0)
1502 return; 1509 return;
1503 1510
1504 /* master */ 1511 /* master */
1505 c = nexttiled(m, clients); 1512 c = nexttiled(m, m->clients);
1506 mw = m->mfact * m->ww; 1513 mw = m->mfact * m->ww;
1507 resize(c, m->wx, m->wy, (n == 1 ? m->ww : mw) - 2 * c->bw, m->wh - 2 * c->bw); 1514 resize(c, m->wx, m->wy, (n == 1 ? m->ww : mw) - 2 * c->bw, m->wh - 2 * c->bw);
1508 1515
@@ -1535,11 +1542,11 @@ togglebar(const Arg *arg) {
1535 1542
1536void 1543void
1537togglefloating(const Arg *arg) { 1544togglefloating(const Arg *arg) {
1538 if(!sel) 1545 if(!selmon->sel)
1539 return; 1546 return;
1540 sel->isfloating = !sel->isfloating || sel->isfixed; 1547 selmon->sel->isfloating = !selmon->sel->isfloating || selmon->sel->isfixed;
1541 if(sel->isfloating) 1548 if(selmon->sel->isfloating)
1542 resize(sel, sel->x, sel->y, sel->w, sel->h); 1549 resize(selmon->sel, selmon->sel->x, selmon->sel->y, selmon->sel->w, selmon->sel->h);
1543 arrange(); 1550 arrange();
1544} 1551}
1545 1552
@@ -1547,12 +1554,12 @@ void
1547toggletag(const Arg *arg) { 1554toggletag(const Arg *arg) {
1548 unsigned int mask; 1555 unsigned int mask;
1549 1556
1550 if(!sel) 1557 if(!selmon->sel)
1551 return; 1558 return;
1552 1559
1553 mask = sel->tags ^ (arg->ui & TAGMASK); 1560 mask = selmon->sel->tags ^ (arg->ui & TAGMASK);
1554 if(mask) { 1561 if(mask) {
1555 sel->tags = mask; 1562 selmon->sel->tags = mask;
1556 arrange(); 1563 arrange();
1557 } 1564 }
1558} 1565}
@@ -1578,7 +1585,7 @@ unmanage(Client *c) {
1578 XConfigureWindow(dpy, c->win, CWBorderWidth, &wc); /* restore border */ 1585 XConfigureWindow(dpy, c->win, CWBorderWidth, &wc); /* restore border */
1579 detach(c); 1586 detach(c);
1580 detachstack(c); 1587 detachstack(c);
1581 if(sel == c) 1588 if(selmon->sel == c)
1582 focus(NULL); 1589 focus(NULL);
1583 XUngrabButton(dpy, AnyButton, AnyModifier, c->win); 1590 XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
1584 setclientstate(c, WithdrawnState); 1591 setclientstate(c, WithdrawnState);
@@ -1634,7 +1641,7 @@ void
1634updategeom(void) { 1641updategeom(void) {
1635 int i, n = 1; 1642 int i, n = 1;
1636 Client *c; 1643 Client *c;
1637 Monitor *newmons = NULL, *m; 1644 Monitor *newmons = NULL, *m, *tm;
1638 1645
1639#ifdef XINERAMA 1646#ifdef XINERAMA
1640 XineramaScreenInfo *info = NULL; 1647 XineramaScreenInfo *info = NULL;
@@ -1675,6 +1682,9 @@ updategeom(void) {
1675 /* bar geometry setup */ 1682 /* bar geometry setup */
1676 for(m = newmons; m; m = m->next) { 1683 for(m = newmons; m; m = m->next) {
1677 /* TODO: consider removing the following values from config.h */ 1684 /* TODO: consider removing the following values from config.h */
1685 m->clients = NULL;
1686 m->sel = NULL;
1687 m->stack = NULL;
1678 m->seltags = 0; 1688 m->seltags = 0;
1679 m->sellt = 0; 1689 m->sellt = 0;
1680 m->tagset[0] = m->tagset[1] = 1; 1690 m->tagset[0] = m->tagset[1] = 1;
@@ -1683,15 +1693,33 @@ updategeom(void) {
1683 m->topbar = topbar; 1693 m->topbar = topbar;
1684 updatebarpos(m); 1694 updatebarpos(m);
1685 /* reassign all clients with same screen number */ 1695 /* reassign all clients with same screen number */
1686 for(c = clients; c; c = c->next) 1696 for(tm = mons; tm; tm = tm->next)
1687 if(c->m->screen_number == m->screen_number) 1697 if(tm->screen_number == m->screen_number) {
1688 c->m = m; 1698 m->clients = tm->clients;
1699 m->stack = tm->stack;
1700 tm->clients = NULL;
1701 tm->stack = NULL;
1702 for(c = m->clients; c; c = c->next)
1703 c->mon = m;
1704 }
1689 } 1705 }
1690 1706
1691 /* reassign left over clients with disappeared screen number */ 1707 /* reassign left over clients of disappeared monitors */
1692 for(c = clients; c; c = c->next) 1708 for(tm = mons; tm; tm = tm->next) {
1693 if(c->m->screen_number >= n) 1709 while(tm->clients) {
1694 c->m = newmons; 1710 c = tm->clients->next;
1711 tm->clients->next = newmons->clients;
1712 tm->clients->mon = newmons;
1713 newmons->clients = tm->clients;
1714 tm->clients = c;
1715 }
1716 while(tm->stack) {
1717 c = tm->stack->snext;
1718 tm->stack->snext = newmons->stack;
1719 newmons->stack = tm->stack;
1720 tm->stack = c;
1721 }
1722 }
1695 1723
1696 /* select focused monitor */ 1724 /* select focused monitor */
1697 if(!selmon) { 1725 if(!selmon) {
@@ -1795,7 +1823,7 @@ updatewmhints(Client *c) {
1795 XWMHints *wmh; 1823 XWMHints *wmh;
1796 1824
1797 if((wmh = XGetWMHints(dpy, c->win))) { 1825 if((wmh = XGetWMHints(dpy, c->win))) {
1798 if(c == sel && wmh->flags & XUrgencyHint) { 1826 if(c == selmon->sel && wmh->flags & XUrgencyHint) {
1799 wmh->flags &= ~XUrgencyHint; 1827 wmh->flags &= ~XUrgencyHint;
1800 XSetWMHints(dpy, c->win, wmh); 1828 XSetWMHints(dpy, c->win, wmh);
1801 } 1829 }
@@ -1851,11 +1879,11 @@ xerrorstart(Display *dpy, XErrorEvent *ee) {
1851 1879
1852void 1880void
1853zoom(const Arg *arg) { 1881zoom(const Arg *arg) {
1854 Client *c = sel; 1882 Client *c = selmon->sel;
1855 1883
1856 if(!lt[selmon->sellt]->arrange || lt[selmon->sellt]->arrange == monocle || (sel && sel->isfloating)) 1884 if(!lt[selmon->sellt]->arrange || lt[selmon->sellt]->arrange == monocle || (selmon->sel && selmon->sel->isfloating))
1857 return; 1885 return;
1858 if(c == nexttiled(selmon, clients)) 1886 if(c == nexttiled(selmon, selmon->clients))
1859 if(!c || !(c = nexttiled(selmon, c->next))) 1887 if(!c || !(c = nexttiled(selmon, c->next)))
1860 return; 1888 return;
1861 detach(c); 1889 detach(c);