made restack, drawbar also Monitor-related only
55edd2d6
1 file(s) · +91 −89
| 144 | 144 | void destroynotify(XEvent *e); |
|
| 145 | 145 | void detach(Client *c); |
|
| 146 | 146 | void detachstack(Client *c); |
|
| 147 | - | void drawbar(void); |
|
| 148 | - | void drawsquare(Monitor *, Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]); |
|
| 149 | - | void drawtext(Monitor *, const char *text, unsigned long col[ColLast], Bool invert); |
|
| 147 | + | void drawbar(Monitor *m); |
|
| 148 | + | void drawsquare(Monitor *m, Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]); |
|
| 149 | + | void drawtext(Monitor *m, const char *text, unsigned long col[ColLast], Bool invert); |
|
| 150 | 150 | void *emallocz(unsigned int size); |
|
| 151 | 151 | void enternotify(XEvent *e); |
|
| 152 | 152 | void eprint(const char *errstr, ...); |
|
| 158 | 158 | void focusprev(const char *arg); |
|
| 159 | 159 | Client *getclient(Window w); |
|
| 160 | 160 | unsigned long getcolor(const char *colstr); |
|
| 161 | + | Monitor *getmonitor(Window barwin); |
|
| 161 | 162 | long getstate(Window w); |
|
| 162 | 163 | Bool gettextprop(Window w, Atom atom, char *text, unsigned int size); |
|
| 163 | 164 | void grabbuttons(Client *c, Bool focused); |
|
| 180 | 181 | void reapply(const char *arg); |
|
| 181 | 182 | void resize(Client *c, int x, int y, int w, int h, Bool sizehints); |
|
| 182 | 183 | void resizemouse(Client *c); |
|
| 183 | - | void restack(void); |
|
| 184 | + | void restack(Monitor *m); |
|
| 184 | 185 | void run(void); |
|
| 185 | 186 | void scan(void); |
|
| 186 | 187 | void setclientstate(Client *c, long state); |
|
| 309 | 310 | ||
| 310 | 311 | monitors[selmonitor].layout->arrange(&monitors[selmonitor]); |
|
| 311 | 312 | focus(NULL); |
|
| 312 | - | restack(); |
|
| 313 | + | restack(&monitors[selmonitor]); |
|
| 313 | 314 | } |
|
| 314 | 315 | ||
| 315 | 316 | void |
|
| 370 | 371 | if(CLEANMASK(ev->state) != MODKEY) |
|
| 371 | 372 | return; |
|
| 372 | 373 | if(ev->button == Button1) { |
|
| 373 | - | restack(); |
|
| 374 | + | restack(&monitors[c->monitor]); |
|
| 374 | 375 | movemouse(c); |
|
| 375 | 376 | } |
|
| 376 | 377 | else if(ev->button == Button2) { |
|
| 380 | 381 | zoom(NULL); |
|
| 381 | 382 | } |
|
| 382 | 383 | else if(ev->button == Button3 && !c->isfixed) { |
|
| 383 | - | restack(); |
|
| 384 | + | restack(&monitors[c->monitor]); |
|
| 384 | 385 | resizemouse(c); |
|
| 385 | 386 | } |
|
| 386 | 387 | } |
|
| 562 | 563 | } |
|
| 563 | 564 | ||
| 564 | 565 | void |
|
| 565 | - | drawbar(void) { |
|
| 566 | - | int i, j, x; |
|
| 566 | + | drawbar(Monitor *m) { |
|
| 567 | + | int j, x; |
|
| 567 | 568 | Client *c; |
|
| 568 | 569 | ||
| 569 | - | for(i = 0; i < mcount; i++) { |
|
| 570 | - | Monitor *m = &monitors[i]; |
|
| 571 | - | dc.x = 0; |
|
| 572 | - | for(c = stack; c && !isvisible(c, i); c = c->snext); |
|
| 573 | - | fprintf(stderr, "m%d %s\n", i, c ? c->name : "NIL"); |
|
| 574 | - | for(j = 0; j < LENGTH(tags); j++) { |
|
| 575 | - | dc.w = textw(tags[j]); |
|
| 576 | - | if(m->seltags[j]) { |
|
| 577 | - | drawtext(m, tags[j], dc.sel, isurgent(i, j)); |
|
| 578 | - | drawsquare(m, c && c->tags[j] && c->monitor == i, |
|
| 579 | - | isoccupied(i, j), isurgent(i, j), dc.sel); |
|
| 580 | - | } |
|
| 581 | - | else { |
|
| 582 | - | drawtext(m, tags[j], dc.norm, isurgent(i, j)); |
|
| 583 | - | drawsquare(m, c && c->tags[j] && c->monitor == i, |
|
| 584 | - | isoccupied(i, j), isurgent(i, j), dc.norm); |
|
| 585 | - | } |
|
| 586 | - | dc.x += dc.w; |
|
| 570 | + | dc.x = 0; |
|
| 571 | + | for(c = stack; c && !isvisible(c, m->id); c = c->snext); |
|
| 572 | + | for(j = 0; j < LENGTH(tags); j++) { |
|
| 573 | + | dc.w = textw(tags[j]); |
|
| 574 | + | if(m->seltags[j]) { |
|
| 575 | + | drawtext(m, tags[j], dc.sel, isurgent(m->id, j)); |
|
| 576 | + | drawsquare(m, c && c->tags[j] && c->monitor == m->id, |
|
| 577 | + | isoccupied(m->id, j), isurgent(m->id, j), dc.sel); |
|
| 587 | 578 | } |
|
| 588 | - | dc.w = blw; |
|
| 589 | - | drawtext(m, m->layout->symbol, dc.norm, False); |
|
| 590 | - | x = dc.x + dc.w; |
|
| 591 | - | if(i == selmonitor) { |
|
| 592 | - | dc.w = textw(stext); |
|
| 593 | - | dc.x = m->sw - dc.w; |
|
| 594 | - | if(dc.x < x) { |
|
| 595 | - | dc.x = x; |
|
| 596 | - | dc.w = m->sw - x; |
|
| 597 | - | } |
|
| 598 | - | drawtext(m, stext, dc.norm, False); |
|
| 579 | + | else { |
|
| 580 | + | drawtext(m, tags[j], dc.norm, isurgent(m->id, j)); |
|
| 581 | + | drawsquare(m, c && c->tags[j] && c->monitor == m->id, |
|
| 582 | + | isoccupied(m->id, j), isurgent(m->id, j), dc.norm); |
|
| 599 | 583 | } |
|
| 600 | - | else |
|
| 601 | - | dc.x = m->sw; |
|
| 602 | - | if((dc.w = dc.x - x) > bh) { |
|
| 584 | + | dc.x += dc.w; |
|
| 585 | + | } |
|
| 586 | + | dc.w = blw; |
|
| 587 | + | drawtext(m, m->layout->symbol, dc.norm, False); |
|
| 588 | + | x = dc.x + dc.w; |
|
| 589 | + | if(m->id == selmonitor) { |
|
| 590 | + | dc.w = textw(stext); |
|
| 591 | + | dc.x = m->sw - dc.w; |
|
| 592 | + | if(dc.x < x) { |
|
| 603 | 593 | dc.x = x; |
|
| 604 | - | if(c) { |
|
| 605 | - | drawtext(m, c->name, dc.sel, False); |
|
| 606 | - | drawsquare(m, False, c->isfloating, False, dc.sel); |
|
| 607 | - | } |
|
| 608 | - | else |
|
| 609 | - | drawtext(m, NULL, dc.norm, False); |
|
| 594 | + | dc.w = m->sw - x; |
|
| 610 | 595 | } |
|
| 611 | - | XCopyArea(dpy, dc.drawable, m->barwin, dc.gc, 0, 0, m->sw, bh, 0, 0); |
|
| 612 | - | XSync(dpy, False); |
|
| 596 | + | drawtext(m, stext, dc.norm, False); |
|
| 613 | 597 | } |
|
| 598 | + | else |
|
| 599 | + | dc.x = m->sw; |
|
| 600 | + | if((dc.w = dc.x - x) > bh) { |
|
| 601 | + | dc.x = x; |
|
| 602 | + | if(c) { |
|
| 603 | + | drawtext(m, c->name, dc.sel, False); |
|
| 604 | + | drawsquare(m, False, c->isfloating, False, dc.sel); |
|
| 605 | + | } |
|
| 606 | + | else |
|
| 607 | + | drawtext(m, NULL, dc.norm, False); |
|
| 608 | + | } |
|
| 609 | + | XCopyArea(dpy, dc.drawable, m->barwin, dc.gc, 0, 0, m->sw, bh, 0, 0); |
|
| 610 | + | XSync(dpy, False); |
|
| 614 | 611 | } |
|
| 615 | 612 | ||
| 616 | 613 | void |
|
| 713 | 710 | ||
| 714 | 711 | void |
|
| 715 | 712 | expose(XEvent *e) { |
|
| 713 | + | Monitor *m; |
|
| 716 | 714 | XExposeEvent *ev = &e->xexpose; |
|
| 717 | 715 | ||
| 718 | - | if(ev->count == 0) { |
|
| 719 | - | if(ev->window == monitors[selmonitor].barwin) |
|
| 720 | - | drawbar(); |
|
| 721 | - | } |
|
| 716 | + | if(ev->count == 0 && (m = getmonitor(ev->window))) |
|
| 717 | + | drawbar(m); |
|
| 722 | 718 | } |
|
| 723 | 719 | ||
| 724 | 720 | void |
|
| 750 | 746 | grabbuttons(c, True); |
|
| 751 | 747 | } |
|
| 752 | 748 | sel = c; |
|
| 753 | - | drawbar(); |
|
| 754 | 749 | if(c) { |
|
| 755 | 750 | XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]); |
|
| 756 | 751 | XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); |
|
| 757 | 752 | selmonitor = c->monitor; |
|
| 758 | 753 | } |
|
| 759 | - | else { |
|
| 754 | + | else |
|
| 760 | 755 | XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); |
|
| 761 | - | drawbar(); |
|
| 762 | - | } |
|
| 756 | + | drawbar(&monitors[selmonitor]); |
|
| 763 | 757 | } |
|
| 764 | 758 | ||
| 765 | 759 | void |
|
| 781 | 775 | for(c = clients; c && !isvisible(c, selmonitor); c = c->next); |
|
| 782 | 776 | if(c) { |
|
| 783 | 777 | focus(c); |
|
| 784 | - | restack(); |
|
| 778 | + | restack(&monitors[c->monitor]); |
|
| 785 | 779 | } |
|
| 786 | 780 | } |
|
| 787 | 781 | ||
| 798 | 792 | } |
|
| 799 | 793 | if(c) { |
|
| 800 | 794 | focus(c); |
|
| 801 | - | restack(); |
|
| 795 | + | restack(&monitors[c->monitor]); |
|
| 802 | 796 | } |
|
| 803 | 797 | } |
|
| 804 | 798 | ||
| 818 | 812 | if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color)) |
|
| 819 | 813 | eprint("error, cannot allocate color '%s'\n", colstr); |
|
| 820 | 814 | return color.pixel; |
|
| 815 | + | } |
|
| 816 | + | ||
| 817 | + | Monitor * |
|
| 818 | + | getmonitor(Window barwin) { |
|
| 819 | + | unsigned int i; |
|
| 820 | + | ||
| 821 | + | for(i = 0; i < mcount; i++) |
|
| 822 | + | if(monitors[i].barwin == barwin) |
|
| 823 | + | return &monitors[i]; |
|
| 824 | + | return NULL; |
|
| 821 | 825 | } |
|
| 822 | 826 | ||
| 823 | 827 | long |
|
| 1225 | 1229 | return; /* ignore */ |
|
| 1226 | 1230 | if((c = getclient(ev->window))) { |
|
| 1227 | 1231 | switch (ev->atom) { |
|
| 1228 | - | default: break; |
|
| 1229 | - | case XA_WM_TRANSIENT_FOR: |
|
| 1230 | - | XGetTransientForHint(dpy, c->win, &trans); |
|
| 1231 | - | if(!c->isfloating && (c->isfloating = (getclient(trans) != NULL))) |
|
| 1232 | - | arrange(); |
|
| 1233 | - | break; |
|
| 1234 | - | case XA_WM_NORMAL_HINTS: |
|
| 1235 | - | updatesizehints(c); |
|
| 1236 | - | break; |
|
| 1237 | - | case XA_WM_HINTS: |
|
| 1238 | - | updatewmhints(c); |
|
| 1239 | - | drawbar(); |
|
| 1240 | - | break; |
|
| 1232 | + | default: break; |
|
| 1233 | + | case XA_WM_TRANSIENT_FOR: |
|
| 1234 | + | XGetTransientForHint(dpy, c->win, &trans); |
|
| 1235 | + | if(!c->isfloating && (c->isfloating = (getclient(trans) != NULL))) |
|
| 1236 | + | arrange(); |
|
| 1237 | + | break; |
|
| 1238 | + | case XA_WM_NORMAL_HINTS: |
|
| 1239 | + | updatesizehints(c); |
|
| 1240 | + | break; |
|
| 1241 | + | case XA_WM_HINTS: |
|
| 1242 | + | updatewmhints(c); |
|
| 1243 | + | drawbar(&monitors[c->monitor]); |
|
| 1244 | + | break; |
|
| 1241 | 1245 | } |
|
| 1242 | 1246 | if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) { |
|
| 1243 | 1247 | updatetitle(c); |
|
| 1244 | 1248 | if(c == sel) |
|
| 1245 | - | drawbar(); |
|
| 1249 | + | drawbar(&monitors[c->monitor]); |
|
| 1246 | 1250 | } |
|
| 1247 | 1251 | } |
|
| 1248 | 1252 | } |
|
| 1375 | 1379 | } |
|
| 1376 | 1380 | ||
| 1377 | 1381 | void |
|
| 1378 | - | restack(void) { |
|
| 1379 | - | unsigned int i; |
|
| 1382 | + | restack(Monitor *m) { |
|
| 1380 | 1383 | Client *c; |
|
| 1381 | 1384 | XEvent ev; |
|
| 1382 | 1385 | XWindowChanges wc; |
|
| 1383 | 1386 | ||
| 1384 | - | drawbar(); |
|
| 1387 | + | drawbar(m); |
|
| 1385 | 1388 | if(!sel) |
|
| 1386 | 1389 | return; |
|
| 1387 | - | if(sel->isfloating || (monitors[selmonitor].layout->arrange == floating)) |
|
| 1390 | + | if(sel->isfloating || (m->layout->arrange == floating)) |
|
| 1388 | 1391 | XRaiseWindow(dpy, sel->win); |
|
| 1389 | - | if(monitors[selmonitor].layout->arrange != floating) { |
|
| 1392 | + | if(m->layout->arrange != floating) { |
|
| 1390 | 1393 | wc.stack_mode = Below; |
|
| 1391 | - | wc.sibling = monitors[selmonitor].barwin; |
|
| 1394 | + | wc.sibling = m->barwin; |
|
| 1392 | 1395 | if(!sel->isfloating) { |
|
| 1393 | 1396 | XConfigureWindow(dpy, sel->win, CWSibling | CWStackMode, &wc); |
|
| 1394 | 1397 | wc.sibling = sel->win; |
|
| 1395 | 1398 | } |
|
| 1396 | - | for(i = 0; i < mcount; i++) { |
|
| 1397 | - | for(c = nexttiled(clients, i); c; c = nexttiled(c->next, i)) { |
|
| 1398 | - | if(c == sel) |
|
| 1399 | - | continue; |
|
| 1400 | - | XConfigureWindow(dpy, c->win, CWSibling | CWStackMode, &wc); |
|
| 1401 | - | wc.sibling = c->win; |
|
| 1402 | - | } |
|
| 1399 | + | for(c = nexttiled(clients, m->id); c; c = nexttiled(c->next, m->id)) { |
|
| 1400 | + | if(c == sel) |
|
| 1401 | + | continue; |
|
| 1402 | + | XConfigureWindow(dpy, c->win, CWSibling | CWStackMode, &wc); |
|
| 1403 | + | wc.sibling = c->win; |
|
| 1403 | 1404 | } |
|
| 1404 | 1405 | } |
|
| 1405 | 1406 | XSync(dpy, False); |
|
| 1456 | 1457 | } |
|
| 1457 | 1458 | break; |
|
| 1458 | 1459 | } |
|
| 1459 | - | drawbar(); |
|
| 1460 | + | drawbar(&monitors[selmonitor]); |
|
| 1460 | 1461 | } |
|
| 1461 | 1462 | while(XPending(dpy)) { |
|
| 1462 | 1463 | XNextEvent(dpy, &ev); |
|
| 1522 | 1523 | if(sel) |
|
| 1523 | 1524 | arrange(); |
|
| 1524 | 1525 | else |
|
| 1525 | - | drawbar(); |
|
| 1526 | + | drawbar(m); |
|
| 1526 | 1527 | } |
|
| 1527 | 1528 | ||
| 1528 | 1529 | void |
|
| 1651 | 1652 | | EnterWindowMask | LeaveWindowMask | StructureNotifyMask; |
|
| 1652 | 1653 | XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); |
|
| 1653 | 1654 | XSelectInput(dpy, root, wa.event_mask); |
|
| 1655 | + | ||
| 1656 | + | drawbar(m); |
|
| 1654 | 1657 | } |
|
| 1655 | 1658 | if(info) |
|
| 1656 | 1659 | XFree(info); |
|
| 2054 | 2057 | ||
| 2055 | 2058 | checkotherwm(); |
|
| 2056 | 2059 | setup(); |
|
| 2057 | - | drawbar(); |
|
| 2058 | 2060 | scan(); |
|
| 2059 | 2061 | run(); |
|
| 2060 | 2062 | cleanup(); |
|