summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnselm R Garbe <anselm@garbe.us>2009-06-20 15:10:04 +0100
committerAnselm R Garbe <anselm@garbe.us>2009-06-20 15:10:04 +0100
commit2ce37bc69ee72af7ea88376c73133f8a833204cf (patch)
tree1addc0295edac05a9396b66d96f86be852c7ef71
parentintroduction of Monitor for better Xinerama support, work in progress (diff)
downloaddwm-2ce37bc69ee72af7ea88376c73133f8a833204cf.tar.gz
dwm-2ce37bc69ee72af7ea88376c73133f8a833204cf.zip
experimental xinerama support, two new actions, Mod1-w/e and Mod1-Shift-w/e
Diffstat (limited to '')
-rw-r--r--config.def.h10
-rw-r--r--config.mk10
-rw-r--r--dwm.c310
3 files changed, 209 insertions, 121 deletions
diff --git a/config.def.h b/config.def.h
index ca2d423..e1953c3 100644
--- a/config.def.h
+++ b/config.def.h
@@ -13,6 +13,7 @@ static unsigned int snap = 32; /* snap pixel */
13static Bool showbar = True; /* False means no bar */ 13static Bool showbar = True; /* False means no bar */
14static Bool topbar = True; /* False means bottom bar */ 14static Bool topbar = True; /* False means bottom bar */
15 15
16
16/* tagging */ 17/* tagging */
17static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; 18static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
18static unsigned int tagset[] = {1, 1}; /* after start, first tag is selected */ 19static unsigned int tagset[] = {1, 1}; /* after start, first tag is selected */
@@ -20,7 +21,8 @@ static unsigned int tagset[] = {1, 1}; /* after start, first tag is selected */
20static Rule rules[] = { 21static Rule rules[] = {
21 /* class instance title tags mask isfloating */ 22 /* class instance title tags mask isfloating */
22 { "Gimp", NULL, NULL, 0, True }, 23 { "Gimp", NULL, NULL, 0, True },
23 { "Firefox", NULL, NULL, 1 << 8, True }, 24 { "Firefox", NULL, NULL, 1 << 8, False },
25
24}; 26};
25 27
26/* layout(s) */ 28/* layout(s) */
@@ -68,6 +70,12 @@ static Key keys[] = {
68 { MODKEY|ShiftMask, XK_space, togglefloating, {0} }, 70 { MODKEY|ShiftMask, XK_space, togglefloating, {0} },
69 { MODKEY, XK_0, view, {.ui = ~0 } }, 71 { MODKEY, XK_0, view, {.ui = ~0 } },
70 { MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } }, 72 { MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } },
73#ifdef XINERAMA
74 { MODKEY, XK_w, focusmon, {.ui = 0 } },
75 { MODKEY, XK_e, focusmon, {.ui = 1 } },
76 { MODKEY|ShiftMask, XK_w, tagmon, {.ui = 0 } },
77 { MODKEY|ShiftMask, XK_e, tagmon, {.ui = 1 } },
78#endif /* XINERAMA */
71 TAGKEYS( XK_1, 0) 79 TAGKEYS( XK_1, 0)
72 TAGKEYS( XK_2, 1) 80 TAGKEYS( XK_2, 1)
73 TAGKEYS( XK_3, 2) 81 TAGKEYS( XK_3, 2)
diff --git a/config.mk b/config.mk
index 43c324b..f5ec4c1 100644
--- a/config.mk
+++ b/config.mk
@@ -11,8 +11,8 @@ X11INC = /usr/X11R6/include
11X11LIB = /usr/X11R6/lib 11X11LIB = /usr/X11R6/lib
12 12
13# Xinerama, un-comment if you want it 13# Xinerama, un-comment if you want it
14#XINERAMALIBS = -L${X11LIB} -lXinerama 14XINERAMALIBS = -L${X11LIB} -lXinerama
15#XINERAMAFLAGS = -DXINERAMA 15XINERAMAFLAGS = -DXINERAMA
16 16
17# includes and libs 17# includes and libs
18INCS = -I. -I/usr/include -I${X11INC} 18INCS = -I. -I/usr/include -I${X11INC}
@@ -20,8 +20,10 @@ LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 ${XINERAMALIBS}
20 20
21# flags 21# flags
22CPPFLAGS = -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} 22CPPFLAGS = -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
23CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS} 23CFLAGS = -g -std=c99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS}
24LDFLAGS = -s ${LIBS} 24#CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
25LDFLAGS = -g ${LIBS}
26#LDFLAGS = -s ${LIBS}
25 27
26# Solaris 28# Solaris
27#CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\" 29#CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\"
diff --git a/dwm.c b/dwm.c
index 75c9a76..0e8c927 100644
--- a/dwm.c
+++ b/dwm.c
@@ -38,13 +38,13 @@
38#include <X11/Xutil.h> 38#include <X11/Xutil.h>
39#ifdef XINERAMA 39#ifdef XINERAMA
40#include <X11/extensions/Xinerama.h> 40#include <X11/extensions/Xinerama.h>
41#endif 41#endif /* XINERAMA */
42 42
43/* macros */ 43/* macros */
44#define BUTTONMASK (ButtonPressMask|ButtonReleaseMask) 44#define BUTTONMASK (ButtonPressMask|ButtonReleaseMask)
45#define CLEANMASK(mask) (mask & ~(numlockmask|LockMask)) 45#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)) 46#define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= (RY) && (Y) < (RY) + (RH))
47#define ISVISIBLE(x) (x->tags & tagset[selmon->seltags]) 47#define ISVISIBLE(x) (x->tags & tagset[mon[x->mon].seltags])
48#define LENGTH(x) (sizeof x / sizeof x[0]) 48#define LENGTH(x) (sizeof x / sizeof x[0])
49#define MAX(a, b) ((a) > (b) ? (a) : (b)) 49#define MAX(a, b) ((a) > (b) ? (a) : (b))
50#define MIN(a, b) ((a) < (b) ? (a) : (b)) 50#define MIN(a, b) ((a) < (b) ? (a) : (b))
@@ -115,17 +115,22 @@ typedef struct {
115} Key; 115} Key;
116 116
117typedef struct { 117typedef struct {
118 const char *symbol; 118 char symbol[4];
119 void (*arrange)(void); 119 int by, btx; /* bar geometry */
120} Layout; 120 int wx, wy, ww, wh; /* window area */
121
122typedef struct {
123 int wx, wy, ww, wh;
124 unsigned int seltags; 121 unsigned int seltags;
125 unsigned int sellt; 122 unsigned int sellt;
123 Bool showbar;
124 Bool topbar;
125 Window barwin;
126} Monitor; 126} Monitor;
127 127
128typedef struct { 128typedef struct {
129 const char *symbol;
130 void (*arrange)(Monitor *);
131} Layout;
132
133typedef struct {
129 const char *class; 134 const char *class;
130 const char *instance; 135 const char *instance;
131 const char *title; 136 const char *title;
@@ -150,7 +155,8 @@ static void destroynotify(XEvent *e);
150static void detach(Client *c); 155static void detach(Client *c);
151static void detachstack(Client *c); 156static void detachstack(Client *c);
152static void die(const char *errstr, ...); 157static void die(const char *errstr, ...);
153static void drawbar(void); 158static void drawbar(Monitor *m);
159static void drawbars();
154static void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]); 160static void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]);
155static void drawtext(const char *text, unsigned long col[ColLast], Bool invert); 161static void drawtext(const char *text, unsigned long col[ColLast], Bool invert);
156static void enternotify(XEvent *e); 162static void enternotify(XEvent *e);
@@ -171,14 +177,14 @@ static void killclient(const Arg *arg);
171static void manage(Window w, XWindowAttributes *wa); 177static void manage(Window w, XWindowAttributes *wa);
172static void mappingnotify(XEvent *e); 178static void mappingnotify(XEvent *e);
173static void maprequest(XEvent *e); 179static void maprequest(XEvent *e);
174static void monocle(void); 180static void monocle(Monitor *m);
175static void movemouse(const Arg *arg); 181static void movemouse(const Arg *arg);
176static Client *nexttiled(Client *c); 182static Client *nexttiled(Monitor *m, Client *c);
177static void propertynotify(XEvent *e); 183static void propertynotify(XEvent *e);
178static void quit(const Arg *arg); 184static void quit(const Arg *arg);
179static void resize(Client *c, int x, int y, int w, int h); 185static void resize(Client *c, int x, int y, int w, int h);
180static void resizemouse(const Arg *arg); 186static void resizemouse(const Arg *arg);
181static void restack(void); 187static void restack(Monitor *m);
182static void run(void); 188static void run(void);
183static void scan(void); 189static void scan(void);
184static void setclientstate(Client *c, long state); 190static void setclientstate(Client *c, long state);
@@ -190,14 +196,13 @@ static void sigchld(int signal);
190static void spawn(const Arg *arg); 196static void spawn(const Arg *arg);
191static void tag(const Arg *arg); 197static void tag(const Arg *arg);
192static int textnw(const char *text, unsigned int len); 198static int textnw(const char *text, unsigned int len);
193static void tile(void); 199static void tile(Monitor *);
194static void togglebar(const Arg *arg); 200static void togglebar(const Arg *arg);
195static void togglefloating(const Arg *arg); 201static void togglefloating(const Arg *arg);
196static void toggletag(const Arg *arg); 202static void toggletag(const Arg *arg);
197static void toggleview(const Arg *arg); 203static void toggleview(const Arg *arg);
198static void unmanage(Client *c); 204static void unmanage(Client *c);
199static void unmapnotify(XEvent *e); 205static void unmapnotify(XEvent *e);
200static void updatebar(void);
201static void updategeom(void); 206static void updategeom(void);
202static void updatenumlockmask(void); 207static void updatenumlockmask(void);
203static void updatesizehints(Client *c); 208static void updatesizehints(Client *c);
@@ -209,12 +214,16 @@ static int xerror(Display *dpy, XErrorEvent *ee);
209static int xerrordummy(Display *dpy, XErrorEvent *ee); 214static int xerrordummy(Display *dpy, XErrorEvent *ee);
210static int xerrorstart(Display *dpy, XErrorEvent *ee); 215static int xerrorstart(Display *dpy, XErrorEvent *ee);
211static void zoom(const Arg *arg); 216static void zoom(const Arg *arg);
217#ifdef XINERAMA
218static void focusmon(const Arg *arg);
219static void tagmon(const Arg *arg);
220#endif /* XINERAMA */
212 221
213/* variables */ 222/* variables */
214static char stext[256]; 223static char stext[256];
215static int screen; 224static int screen;
216static int sx, sy, sw, sh; /* X display screen geometry x, y, width, height */ 225static int sx, sy, sw, sh; /* X display screen geometry x, y, width, height */
217static int by, bh, blw; /* bar geometry y, height and layout symbol width */ 226static int bh, blw = 0; /* bar geometry */
218static int (*xerrorxlib)(Display *, XErrorEvent *); 227static int (*xerrorxlib)(Display *, XErrorEvent *);
219static unsigned int numlockmask = 0; 228static unsigned int numlockmask = 0;
220static void (*handler[LASTEvent]) (XEvent *) = { 229static void (*handler[LASTEvent]) (XEvent *) = {
@@ -243,7 +252,7 @@ static DC dc;
243static Layout *lt[] = { NULL, NULL }; 252static Layout *lt[] = { NULL, NULL };
244static Monitor *mon = NULL, *selmon = NULL; 253static Monitor *mon = NULL, *selmon = NULL;
245static unsigned int nmons; 254static unsigned int nmons;
246static Window root, barwin; 255static Window root;
247/* configuration, allows nested code to access above variables */ 256/* configuration, allows nested code to access above variables */
248#include "config.h" 257#include "config.h"
249 258
@@ -266,7 +275,7 @@ applyrules(Client *c) {
266 && (!r->class || (ch.res_class && strstr(ch.res_class, r->class))) 275 && (!r->class || (ch.res_class && strstr(ch.res_class, r->class)))
267 && (!r->instance || (ch.res_name && strstr(ch.res_name, r->instance)))) { 276 && (!r->instance || (ch.res_name && strstr(ch.res_name, r->instance)))) {
268 c->isfloating = r->isfloating; 277 c->isfloating = r->isfloating;
269 c->tags |= r->tags; 278 c->tags |= r->tags;
270 } 279 }
271 } 280 }
272 if(ch.res_class) 281 if(ch.res_class)
@@ -344,11 +353,14 @@ applysizehints(Client *c, int *x, int *y, int *w, int *h) {
344 353
345void 354void
346arrange(void) { 355arrange(void) {
356 unsigned int i;
347 showhide(stack); 357 showhide(stack);
348 focus(NULL); 358 focus(NULL);
349 if(lt[selmon->sellt]->arrange) 359 for(i = 0; i < nmons; i++) {
350 lt[selmon->sellt]->arrange(); 360 if(lt[mon[i].sellt]->arrange)
351 restack(); 361 lt[mon[i].sellt]->arrange(&mon[i]);
362 restack(&mon[i]);
363 }
352} 364}
353 365
354void 366void
@@ -371,9 +383,12 @@ buttonpress(XEvent *e) {
371 XButtonPressedEvent *ev = &e->xbutton; 383 XButtonPressedEvent *ev = &e->xbutton;
372 384
373 click = ClkRootWin; 385 click = ClkRootWin;
374 if(ev->window == barwin) { 386 if(ev->window == selmon->barwin) {
375 i = x = 0; 387 i = 0;
376 do x += TEXTW(tags[i]); while(ev->x >= x && ++i < LENGTH(tags)); 388 x = selmon->btx;
389 do
390 x += TEXTW(tags[i]);
391 while(ev->x >= x && ++i < LENGTH(tags));
377 if(i < LENGTH(tags)) { 392 if(i < LENGTH(tags)) {
378 click = ClkTagBar; 393 click = ClkTagBar;
379 arg.ui = 1 << i; 394 arg.ui = 1 << i;
@@ -412,6 +427,7 @@ checkotherwm(void) {
412 427
413void 428void
414cleanup(void) { 429cleanup(void) {
430 unsigned int i;
415 Arg a = {.ui = ~0}; 431 Arg a = {.ui = ~0};
416 Layout foo = { "", NULL }; 432 Layout foo = { "", NULL };
417 433
@@ -429,7 +445,9 @@ cleanup(void) {
429 XFreeCursor(dpy, cursor[CurNormal]); 445 XFreeCursor(dpy, cursor[CurNormal]);
430 XFreeCursor(dpy, cursor[CurResize]); 446 XFreeCursor(dpy, cursor[CurResize]);
431 XFreeCursor(dpy, cursor[CurMove]); 447 XFreeCursor(dpy, cursor[CurMove]);
432 XDestroyWindow(dpy, barwin); 448 for(i = 0; i < nmons; i++)
449 XDestroyWindow(dpy, mon[i].barwin);
450 free(mon);
433 XSync(dpy, False); 451 XSync(dpy, False);
434 XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); 452 XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
435} 453}
@@ -466,13 +484,18 @@ configure(Client *c) {
466 484
467void 485void
468configurenotify(XEvent *e) { 486configurenotify(XEvent *e) {
487 unsigned int i;
469 XConfigureEvent *ev = &e->xconfigure; 488 XConfigureEvent *ev = &e->xconfigure;
470 489
471 if(ev->window == root && (ev->width != sw || ev->height != sh)) { 490 if(ev->window == root && (ev->width != sw || ev->height != sh)) {
472 sw = ev->width; 491 sw = ev->width;
473 sh = ev->height; 492 sh = ev->height;
474 updategeom(); 493 updategeom();
475 updatebar(); 494 if(dc.drawable != 0)
495 XFreePixmap(dpy, dc.drawable);
496 dc.drawable = XCreatePixmap(dpy, root, DisplayWidth(dpy, screen), bh, DefaultDepth(dpy, screen));
497 for(i = 0; i < nmons; i++)
498 XMoveResizeWindow(dpy, mon[i].barwin, mon[i].wx, mon[i].by, mon[i].ww, bh);
476 arrange(); 499 arrange();
477 } 500 }
478} 501}
@@ -556,54 +579,79 @@ die(const char *errstr, ...) {
556} 579}
557 580
558void 581void
559drawbar(void) { 582drawbar(Monitor *m) {
560 int x; 583 int x;
561 unsigned int i, occ = 0, urg = 0; 584 unsigned int i, occ = 0, urg = 0;
562 unsigned long *col; 585 unsigned long *col;
563 Client *c; 586 Client *c;
564 587
565 for(c = clients; c; c = c->next) { 588 for(c = clients; c; c = c->next) {
566 occ |= c->tags; 589 if(m == &mon[c->mon]) {
567 if(c->isurgent) 590 occ |= c->tags;
568 urg |= c->tags; 591 if(c->isurgent)
592 urg |= c->tags;
593 }
569 } 594 }
570 595
571 dc.x = 0; 596 dc.x = 0;
597#ifdef XINERAMA
598 {
599 dc.w = TEXTW(m->symbol);
600 drawtext(m->symbol, selmon == m ? dc.sel : dc.norm, False);
601 dc.x += dc.w;
602 }
603#endif /* XINERAMA */
604 m->btx = dc.x;
572 for(i = 0; i < LENGTH(tags); i++) { 605 for(i = 0; i < LENGTH(tags); i++) {
573 dc.w = TEXTW(tags[i]); 606 dc.w = TEXTW(tags[i]);
574 col = tagset[selmon->seltags] & 1 << i ? dc.sel : dc.norm; 607 col = tagset[m->seltags] & 1 << i ? dc.sel : dc.norm;
575 drawtext(tags[i], col, urg & 1 << i); 608 drawtext(tags[i], col, urg & 1 << i);
576 drawsquare(sel && sel->tags & 1 << i, occ & 1 << i, urg & 1 << i, col); 609 drawsquare(m == selmon && sel && sel->tags & 1 << i,
610 occ & 1 << i, urg & 1 << i, col);
577 dc.x += dc.w; 611 dc.x += dc.w;
578 } 612 }
579 if(blw > 0) { 613 if(blw > 0) {
580 dc.w = blw; 614 dc.w = blw;
581 drawtext(lt[selmon->sellt]->symbol, dc.norm, False); 615 drawtext(lt[m->sellt]->symbol, dc.norm, False);
582 x = dc.x + dc.w; 616 x = dc.x + dc.w;
583 } 617 }
584 else 618 else
585 x = dc.x; 619 x = dc.x;
586 dc.w = TEXTW(stext); 620 if(m == selmon) {
587 dc.x = selmon->ww - dc.w; 621 dc.w = TEXTW(stext);
588 if(dc.x < x) { 622 dc.x = m->ww - dc.w;
589 dc.x = x; 623 if(dc.x < x) {
590 dc.w = selmon->ww - x; 624 dc.x = x;
591 } 625 dc.w = m->ww - x;
592 drawtext(stext, dc.norm, False); 626 }
593 if((dc.w = dc.x - x) > bh) { 627 drawtext(stext, dc.norm, False);
594 dc.x = x; 628 if((dc.w = dc.x - x) > bh) {
595 if(sel) { 629 dc.x = x;
596 drawtext(sel->name, dc.sel, False); 630 if(sel) {
597 drawsquare(sel->isfixed, sel->isfloating, False, dc.sel); 631 drawtext(sel->name, dc.sel, False);
632 drawsquare(sel->isfixed, sel->isfloating, False, dc.sel);
633 }
634 else
635 drawtext(NULL, dc.norm, False);
598 } 636 }
599 else
600 drawtext(NULL, dc.norm, False);
601 } 637 }
602 XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, selmon->ww, bh, 0, 0); 638 else {
639 dc.w = m->ww - x;
640 drawtext(NULL, dc.norm, False);
641 }
642 XCopyArea(dpy, dc.drawable, m->barwin, dc.gc, 0, 0, m->ww, bh, 0, 0);
603 XSync(dpy, False); 643 XSync(dpy, False);
604} 644}
605 645
606void 646void
647drawbars() {
648 unsigned int i;
649
650 for(i = 0; i < nmons; i++)
651 drawbar(&mon[i]);
652}
653
654void
607drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]) { 655drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]) {
608 int x; 656 int x;
609 XGCValues gcv; 657 XGCValues gcv;
@@ -667,10 +715,14 @@ enternotify(XEvent *e) {
667 715
668void 716void
669expose(XEvent *e) { 717expose(XEvent *e) {
718 unsigned int i;
670 XExposeEvent *ev = &e->xexpose; 719 XExposeEvent *ev = &e->xexpose;
671 720
672 if(ev->count == 0 && (ev->window == barwin)) 721 for(i = 0; i < nmons; i++)
673 drawbar(); 722 if(ev->count == 0 && (ev->window == mon[i].barwin)) {
723 drawbar(&mon[i]);
724 break;
725 }
674} 726}
675 727
676void 728void
@@ -693,7 +745,9 @@ focus(Client *c) {
693 else 745 else
694 XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); 746 XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
695 sel = c; 747 sel = c;
696 drawbar(); 748 if(c)
749 selmon = &mon[c->mon];
750 drawbars();
697} 751}
698 752
699void 753void
@@ -704,13 +758,24 @@ focusin(XEvent *e) { /* there are some broken focus acquiring clients */
704 XSetInputFocus(dpy, sel->win, RevertToPointerRoot, CurrentTime); 758 XSetInputFocus(dpy, sel->win, RevertToPointerRoot, CurrentTime);
705} 759}
706 760
761#ifdef XINERAMA
762void
763focusmon(const Arg *arg) {
764 if(arg->ui >= nmons)
765 return;
766 selmon = &mon[arg->ui];
767 focus(NULL);
768 drawbars();
769}
770#endif /* XINERAMA */
771
707void 772void
708focusstack(const Arg *arg) { 773focusstack(const Arg *arg) {
709 Client *c = NULL, *i; 774 Client *c = NULL, *i;
710 775
711 if(!sel) 776 if(!sel)
712 return; 777 return;
713 if (arg->i > 0) { 778 if(arg->i > 0) {
714 for(c = sel->next; c && !ISVISIBLE(c); c = c->next); 779 for(c = sel->next; c && !ISVISIBLE(c); c = c->next);
715 if(!c) 780 if(!c)
716 for(c = clients; c && !ISVISIBLE(c); c = c->next); 781 for(c = clients; c && !ISVISIBLE(c); c = c->next);
@@ -726,7 +791,7 @@ focusstack(const Arg *arg) {
726 } 791 }
727 if(c) { 792 if(c) {
728 focus(c); 793 focus(c);
729 restack(); 794 restack(selmon);
730 } 795 }
731} 796}
732 797
@@ -946,9 +1011,8 @@ manage(Window w, XWindowAttributes *wa) {
946 c->y = sy + sh - HEIGHT(c); 1011 c->y = sy + sh - HEIGHT(c);
947 c->x = MAX(c->x, sx); 1012 c->x = MAX(c->x, sx);
948 /* only fix client y-offset, if the client center might cover the bar */ 1013 /* only fix client y-offset, if the client center might cover the bar */
949 /* TODO: is c always attached to selmon? */ 1014 c->y = MAX(c->y, ((selmon->by == 0) && (c->x + (c->w / 2) >= selmon->wx)
950 c->y = MAX(c->y, ((by == 0) && (c->x + (c->w / 2) >= selmon->wx) 1015 && (c->x + (c->w / 2) < selmon->wx + selmon->ww)) ? bh : sy);
951 && (c->x + (c->w / 2) < selmon->wx + selmon->ww)) ? bh : sy);
952 c->bw = borderpx; 1016 c->bw = borderpx;
953 } 1017 }
954 1018
@@ -1001,14 +1065,11 @@ maprequest(XEvent *e) {
1001} 1065}
1002 1066
1003void 1067void
1004monocle(void) { 1068monocle(Monitor *m) {
1005 Client *c; 1069 Client *c;
1006 Monitor *m;
1007 1070
1008 for(c = nexttiled(clients); c; c = nexttiled(c->next)) { 1071 for(c = nexttiled(m, clients); c; c = nexttiled(m, c->next))
1009 m = &mon[c->mon];
1010 resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw); 1072 resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw);
1011 }
1012} 1073}
1013 1074
1014void 1075void
@@ -1021,7 +1082,7 @@ movemouse(const Arg *arg) {
1021 1082
1022 if(!(c = sel)) 1083 if(!(c = sel))
1023 return; 1084 return;
1024 restack(); 1085 restack(selmon);
1025 ocx = c->x; 1086 ocx = c->x;
1026 ocy = c->y; 1087 ocy = c->y;
1027 if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, 1088 if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
@@ -1063,8 +1124,9 @@ movemouse(const Arg *arg) {
1063} 1124}
1064 1125
1065Client * 1126Client *
1066nexttiled(Client *c) { 1127nexttiled(Monitor *m, Client *c) {
1067 for(; c && (c->isfloating || !ISVISIBLE(c)); c = c->next); 1128 // TODO: m handling
1129 for(; c && (c->isfloating || m != &mon[c->mon] || !ISVISIBLE(c)); c = c->next);
1068 return c; 1130 return c;
1069} 1131}
1070 1132
@@ -1091,13 +1153,13 @@ propertynotify(XEvent *e) {
1091 break; 1153 break;
1092 case XA_WM_HINTS: 1154 case XA_WM_HINTS:
1093 updatewmhints(c); 1155 updatewmhints(c);
1094 drawbar(); 1156 drawbars();
1095 break; 1157 break;
1096 } 1158 }
1097 if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) { 1159 if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) {
1098 updatetitle(c); 1160 updatetitle(c);
1099 if(c == sel) 1161 if(c == sel)
1100 drawbar(); 1162 drawbars();
1101 } 1163 }
1102 } 1164 }
1103} 1165}
@@ -1133,7 +1195,7 @@ resizemouse(const Arg *arg) {
1133 1195
1134 if(!(c = sel)) 1196 if(!(c = sel))
1135 return; 1197 return;
1136 restack(); 1198 restack(selmon);
1137 ocx = c->x; 1199 ocx = c->x;
1138 ocy = c->y; 1200 ocy = c->y;
1139 if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, 1201 if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
@@ -1170,21 +1232,21 @@ resizemouse(const Arg *arg) {
1170} 1232}
1171 1233
1172void 1234void
1173restack(void) { 1235restack(Monitor *m) {
1174 Client *c; 1236 Client *c;
1175 XEvent ev; 1237 XEvent ev;
1176 XWindowChanges wc; 1238 XWindowChanges wc;
1177 1239
1178 drawbar(); 1240 drawbars();
1179 if(!sel) 1241 if(!sel)
1180 return; 1242 return;
1181 if(sel->isfloating || !lt[selmon->sellt]->arrange) 1243 if(m == selmon && (sel->isfloating || !lt[m->sellt]->arrange))
1182 XRaiseWindow(dpy, sel->win); 1244 XRaiseWindow(dpy, sel->win);
1183 if(lt[selmon->sellt]->arrange) { 1245 if(lt[m->sellt]->arrange) {
1184 wc.stack_mode = Below; 1246 wc.stack_mode = Below;
1185 wc.sibling = barwin; 1247 wc.sibling = m->barwin;
1186 for(c = stack; c; c = c->snext) 1248 for(c = stack; c; c = c->snext)
1187 if(!c->isfloating && ISVISIBLE(c)) { 1249 if(!c->isfloating && m == &mon[c->mon] && ISVISIBLE(c)) {
1188 XConfigureWindow(dpy, c->win, CWSibling|CWStackMode, &wc); 1250 XConfigureWindow(dpy, c->win, CWSibling|CWStackMode, &wc);
1189 wc.sibling = c->win; 1251 wc.sibling = c->win;
1190 } 1252 }
@@ -1248,7 +1310,7 @@ setlayout(const Arg *arg) {
1248 if(sel) 1310 if(sel)
1249 arrange(); 1311 arrange();
1250 else 1312 else
1251 drawbar(); 1313 drawbars();
1252} 1314}
1253 1315
1254/* arg > 1.0 will set mfact absolutly */ 1316/* arg > 1.0 will set mfact absolutly */
@@ -1309,21 +1371,23 @@ setup(void) {
1309 if(!dc.font.set) 1371 if(!dc.font.set)
1310 XSetFont(dpy, dc.gc, dc.font.xfont->fid); 1372 XSetFont(dpy, dc.gc, dc.font.xfont->fid);
1311 1373
1312 /* init bar */ 1374 /* init bars */
1375 wa.override_redirect = True;
1376 wa.background_pixmap = ParentRelative;
1377 wa.event_mask = ButtonPressMask|ExposureMask;
1313 for(blw = i = 0; LENGTH(layouts) > 1 && i < LENGTH(layouts); i++) { 1378 for(blw = i = 0; LENGTH(layouts) > 1 && i < LENGTH(layouts); i++) {
1314 w = TEXTW(layouts[i].symbol); 1379 w = TEXTW(layouts[i].symbol);
1315 blw = MAX(blw, w); 1380 blw = MAX(blw, w);
1316 } 1381 }
1317 1382
1318 wa.override_redirect = True; 1383 for(i = 0; i < nmons; i++) {
1319 wa.background_pixmap = ParentRelative; 1384 mon[i].barwin = XCreateWindow(dpy, root, mon[i].wx, mon[i].by, mon[i].ww, bh, 0, DefaultDepth(dpy, screen),
1320 wa.event_mask = ButtonPressMask|ExposureMask;
1321 1385
1322 barwin = XCreateWindow(dpy, root, selmon->wx, by, selmon->ww, bh, 0, DefaultDepth(dpy, screen), 1386 CopyFromParent, DefaultVisual(dpy, screen),
1323 CopyFromParent, DefaultVisual(dpy, screen), 1387 CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa);
1324 CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa); 1388 XDefineCursor(dpy, mon[i].barwin, cursor[CurNormal]);
1325 XDefineCursor(dpy, barwin, cursor[CurNormal]); 1389 XMapRaised(dpy, mon[i].barwin);
1326 XMapRaised(dpy, barwin); 1390 }
1327 updatestatus(); 1391 updatestatus();
1328 1392
1329 /* EWMH support per view */ 1393 /* EWMH support per view */
@@ -1384,6 +1448,16 @@ tag(const Arg *arg) {
1384 } 1448 }
1385} 1449}
1386 1450
1451#ifdef XINERAMA
1452void
1453tagmon(const Arg *arg) {
1454 if(!sel || arg->ui >= nmons)
1455 return;
1456 sel->mon = arg->ui;
1457 arrange();
1458}
1459#endif /* XINERAMA */
1460
1387int 1461int
1388textnw(const char *text, unsigned int len) { 1462textnw(const char *text, unsigned int len) {
1389 XRectangle r; 1463 XRectangle r;
@@ -1396,19 +1470,17 @@ textnw(const char *text, unsigned int len) {
1396} 1470}
1397 1471
1398void 1472void
1399tile(void) { 1473tile(Monitor *m) {
1400 int x, y, h, w, mw; 1474 int x, y, h, w, mw;
1401 unsigned int i, n; 1475 unsigned int i, n;
1402 Client *c; 1476 Client *c;
1403 Monitor *m;
1404 1477
1405 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next), n++); 1478 for(n = 0, c = nexttiled(m, clients); c; c = nexttiled(m, c->next), n++);
1406 if(n == 0) 1479 if(n == 0)
1407 return; 1480 return;
1408 1481
1409 /* master */ 1482 /* master */
1410 c = nexttiled(clients); 1483 c = nexttiled(m, clients);
1411 m = &mon[c->mon];
1412 mw = mfact * m->ww; 1484 mw = mfact * m->ww;
1413 resize(c, m->wx, m->wy, (n == 1 ? m->ww : mw) - 2 * c->bw, m->wh - 2 * c->bw); 1485 resize(c, m->wx, m->wy, (n == 1 ? m->ww : mw) - 2 * c->bw, m->wh - 2 * c->bw);
1414 1486
@@ -1423,7 +1495,7 @@ tile(void) {
1423 if(h < bh) 1495 if(h < bh)
1424 h = m->wh; 1496 h = m->wh;
1425 1497
1426 for(i = 0, c = nexttiled(c->next); c; c = nexttiled(c->next), i++) { 1498 for(i = 0, c = nexttiled(m, c->next); c; c = nexttiled(m, c->next), i++) {
1427 resize(c, x, y, w - 2 * c->bw, /* remainder */ ((i + 1 == n) 1499 resize(c, x, y, w - 2 * c->bw, /* remainder */ ((i + 1 == n)
1428 ? m->wy + m->wh - y - 2 * c->bw : h - 2 * c->bw)); 1500 ? m->wy + m->wh - y - 2 * c->bw : h - 2 * c->bw));
1429 if(h != m->wh) 1501 if(h != m->wh)
@@ -1433,9 +1505,9 @@ tile(void) {
1433 1505
1434void 1506void
1435togglebar(const Arg *arg) { 1507togglebar(const Arg *arg) {
1436 showbar = !showbar; 1508 selmon->showbar = !selmon->showbar;
1437 updategeom(); 1509 updategeom();
1438 updatebar(); 1510 XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh);
1439 arrange(); 1511 arrange();
1440} 1512}
1441 1513
@@ -1453,7 +1525,7 @@ void
1453toggletag(const Arg *arg) { 1525toggletag(const Arg *arg) {
1454 unsigned int mask; 1526 unsigned int mask;
1455 1527
1456 if (!sel) 1528 if(!sel)
1457 return; 1529 return;
1458 1530
1459 mask = sel->tags ^ (arg->ui & TAGMASK); 1531 mask = sel->tags ^ (arg->ui & TAGMASK);
@@ -1505,14 +1577,6 @@ unmapnotify(XEvent *e) {
1505} 1577}
1506 1578
1507void 1579void
1508updatebar(void) {
1509 if(dc.drawable != 0)
1510 XFreePixmap(dpy, dc.drawable);
1511 dc.drawable = XCreatePixmap(dpy, root, selmon->ww, bh, DefaultDepth(dpy, screen));
1512 XMoveResizeWindow(dpy, barwin, selmon->wx, by, selmon->ww, bh);
1513}
1514
1515void
1516updategeom(void) { 1580updategeom(void) {
1517#ifdef XINERAMA 1581#ifdef XINERAMA
1518 int di, x, y, n; 1582 int di, x, y, n;
@@ -1523,7 +1587,7 @@ updategeom(void) {
1523 XineramaScreenInfo *info = NULL; 1587 XineramaScreenInfo *info = NULL;
1524 1588
1525 /* window area geometry */ 1589 /* window area geometry */
1526 if(XineramaIsActive(dpy) && (info = XineramaQueryScreens(dpy, &n))) { 1590 if(XineramaIsActive(dpy) && (info = XineramaQueryScreens(dpy, &n))) {
1527 nmons = (unsigned int)n; 1591 nmons = (unsigned int)n;
1528 for(c = clients; c; c = c->next) 1592 for(c = clients; c; c = c->next)
1529 if(c->mon >= nmons) 1593 if(c->mon >= nmons)
@@ -1533,37 +1597,51 @@ updategeom(void) {
1533 pquery = XQueryPointer(dpy, root, &dummy, &dummy, &x, &y, &di, &di, &dui); 1597 pquery = XQueryPointer(dpy, root, &dummy, &dummy, &x, &y, &di, &di, &dui);
1534 for(i = 0; i < nmons; i++) { 1598 for(i = 0; i < nmons; i++) {
1535 /* TODO: consider re-using XineramaScreenInfo */ 1599 /* TODO: consider re-using XineramaScreenInfo */
1600 mon[i].symbol[0] = '[';
1601 mon[i].symbol[1] = '0' + info[i].screen_number;
1602 mon[i].symbol[2] = ']';
1603 mon[i].symbol[3] = 0;
1604 mon[i].showbar = showbar;
1605 mon[i].topbar = topbar;
1536 mon[i].wx = info[i].x_org; 1606 mon[i].wx = info[i].x_org;
1537 mon[i].wy = info[i].y_org; 1607 mon[i].wy = mon[i].showbar && mon[i].topbar ? info[i].y_org + bh : info[i].y_org;
1538 mon[i].ww = info[i].width; 1608 mon[i].ww = info[i].width;
1539 mon[i].wh = info[i].height; 1609 mon[i].wh = mon[i].showbar ? info[i].height - bh : info[i].height;
1540 mon[i].seltags = 0; 1610 mon[i].seltags = 0;
1541 mon[i].sellt = 0; 1611 mon[i].sellt = 0;
1612 if(mon[i].showbar)
1613 mon[i].by = mon[i].topbar ? info[i].y_org : mon[i].wy + mon[i].wh;
1614 else
1615 mon[i].by = -bh;
1542 if(pquery && INRECT(x, y, info[i].x_org, info[i].y_org, info[i].width, info[i].height)) 1616 if(pquery && INRECT(x, y, info[i].x_org, info[i].y_org, info[i].width, info[i].height))
1543 selmon = &mon[i]; 1617 selmon = &mon[i];
1544 } 1618 }
1545 /* bar adjustments of selmon */
1546 selmon->wy = showbar && topbar ? selmon->wy + bh : selmon->wy;
1547 selmon->wh = showbar ? selmon->wh - bh : selmon->wh;
1548 XFree(info); 1619 XFree(info);
1549 } 1620 }
1550 else 1621 else
1551#endif 1622#endif /* XINERAMA */
1552 { 1623 {
1553 nmons = 1; 1624 nmons = 1;
1554 if(!(mon = (Monitor *)realloc(mon, sizeof(Monitor)))) 1625 if(!(mon = (Monitor *)realloc(mon, sizeof(Monitor))))
1555 die("fatal: could not realloc() %u bytes\n", sizeof(Monitor)); 1626 die("fatal: could not realloc() %u bytes\n", sizeof(Monitor));
1556 selmon = &mon[0]; 1627 selmon = &mon[0];
1628 mon[0].symbol[0] = '[';
1629 mon[0].symbol[1] = '0';
1630 mon[0].symbol[2] = ']';
1631 mon[0].symbol[3] = 0;
1632 mon[0].showbar = showbar;
1633 mon[0].topbar = topbar;
1557 mon[0].wx = sx; 1634 mon[0].wx = sx;
1558 mon[0].wy = showbar && topbar ? sy + bh : sy; 1635 mon[0].wy = mon[0].showbar && mon[0].topbar ? sy + bh : sy;
1559 mon[0].ww = sw; 1636 mon[0].ww = sw;
1560 mon[0].wh = showbar ? sh - bh : sh; 1637 mon[0].wh = mon[0].showbar ? sh - bh : sh;
1561 mon[0].seltags = 0; 1638 mon[0].seltags = 0;
1562 mon[0].sellt = 0; 1639 mon[0].sellt = 0;
1640 if(mon[0].showbar)
1641 mon[0].by = mon[0].topbar ? sy : mon[0].wy + mon[0].wh;
1642 else
1643 mon[0].by = -bh;
1563 } 1644 }
1564
1565 /* bar position */
1566 by = showbar ? (topbar ? selmon->wy - bh : selmon->wy + selmon->wh) : -bh;
1567} 1645}
1568 1646
1569void 1647void
@@ -1588,7 +1666,7 @@ updatesizehints(Client *c) {
1588 1666
1589 if(!XGetWMNormalHints(dpy, c->win, &size, &msize)) 1667 if(!XGetWMNormalHints(dpy, c->win, &size, &msize))
1590 /* size is uninitialized, ensure that size.flags aren't used */ 1668 /* size is uninitialized, ensure that size.flags aren't used */
1591 size.flags = PSize; 1669 size.flags = PSize;
1592 if(size.flags & PBaseSize) { 1670 if(size.flags & PBaseSize) {
1593 c->basew = size.base_width; 1671 c->basew = size.base_width;
1594 c->baseh = size.base_height; 1672 c->baseh = size.base_height;
@@ -1641,7 +1719,7 @@ void
1641updatestatus() { 1719updatestatus() {
1642 if(!gettextprop(root, XA_WM_NAME, stext, sizeof(stext))) 1720 if(!gettextprop(root, XA_WM_NAME, stext, sizeof(stext)))
1643 strcpy(stext, "dwm-"VERSION); 1721 strcpy(stext, "dwm-"VERSION);
1644 drawbar(); 1722 drawbar(selmon);
1645} 1723}
1646 1724
1647void 1725void
@@ -1709,8 +1787,8 @@ zoom(const Arg *arg) {
1709 1787
1710 if(!lt[selmon->sellt]->arrange || lt[selmon->sellt]->arrange == monocle || (sel && sel->isfloating)) 1788 if(!lt[selmon->sellt]->arrange || lt[selmon->sellt]->arrange == monocle || (sel && sel->isfloating))
1711 return; 1789 return;
1712 if(c == nexttiled(clients)) 1790 if(c == nexttiled(selmon, clients))
1713 if(!c || !(c = nexttiled(c->next))) 1791 if(!c || !(c = nexttiled(selmon, c->next)))
1714 return; 1792 return;
1715 detach(c); 1793 detach(c);
1716 attach(c); 1794 attach(c);