From bf9da23f07249cfe8f5a5a5c4256d919b353b10c Mon Sep 17 00:00:00 2001 From: Premysl Hruby Date: Thu, 12 Feb 2009 17:26:12 +0100 Subject: [PATCH 01/16] fix of typo, thx to Enno Gottox Boland --- dwm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dwm.c b/dwm.c index db9e9c0..cfe1e7b 100644 --- a/dwm.c +++ b/dwm.c @@ -1015,7 +1015,7 @@ propertynotify(XEvent *e) { Window trans; XPropertyEvent *ev = &e->xproperty; - if((ev->window == root) && (ev->atom = XA_WM_NAME)) + if((ev->window == root) && (ev->atom == XA_WM_NAME)) updatestatus(); else if(ev->state == PropertyDelete) return; /* ignore */ -- 2.20.1 From 1a26389e2bb90150786b20f7706091e3b5620b59 Mon Sep 17 00:00:00 2001 From: "a@null" Date: Sat, 14 Feb 2009 11:21:24 +0000 Subject: [PATCH 02/16] applied nsz' remark --- dwm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dwm.c b/dwm.c index cfe1e7b..ef723cc 100644 --- a/dwm.c +++ b/dwm.c @@ -1463,7 +1463,7 @@ toggletag(const Arg *arg) { return; mask = sel->tags ^ (arg->ui & TAGMASK); - if(sel && mask) { + if(mask) { sel->tags = mask; arrange(); } -- 2.20.1 From 1e350be22906033b950c989aedec9e2e68c3487d Mon Sep 17 00:00:00 2001 From: Anselm R Garbe Date: Sat, 21 Feb 2009 19:12:46 +0000 Subject: [PATCH 03/16] applied Gottox' adjustborder removal patch (thanks!) --- config.mk | 2 +- dwm.c | 20 +------------------- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/config.mk b/config.mk index e70799a..40e74b0 100644 --- a/config.mk +++ b/config.mk @@ -1,5 +1,5 @@ # dwm version -VERSION = 5.4.1 +VERSION = 5.5 # Customize below to fit your system diff --git a/dwm.c b/dwm.c index ef723cc..5f42cbe 100644 --- a/dwm.c +++ b/dwm.c @@ -128,7 +128,6 @@ typedef struct { } Rule; /* function declarations */ -static void adjustborder(Client *c, unsigned int bw); static void applyrules(Client *c); static void arrange(void); static void attach(Client *c); @@ -245,16 +244,6 @@ static Window root, barwin; struct NumTags { char limitexceeded[sizeof(unsigned int) * 8 < LENGTH(tags) ? -1 : 1]; }; /* function implementations */ -void -adjustborder(Client *c, unsigned int bw) { - XWindowChanges wc; - - if(c->bw != bw) { - c->bw = wc.border_width = bw; - XConfigureWindow(dpy, c->win, CWBorderWidth, &wc); - } -} - void applyrules(Client *c) { unsigned int i; @@ -939,12 +928,9 @@ maprequest(XEvent *e) { void monocle(void) { - unsigned int n; Client *c; - for(n = 0, c = nexttiled(clients); c && n < 2; c = nexttiled(c->next), n++); for(c = nexttiled(clients); c; c = nexttiled(c->next)) { - adjustborder(c, n == 1 ? 0 : borderpx); resize(c, wx, wy, ww - 2 * c->bw, wh - 2 * c->bw, resizehints); } } @@ -1349,8 +1335,6 @@ showhide(Client *c, unsigned int ntiled) { if(!c) return; if(ISVISIBLE(c)) { /* show clients top down */ - if(c->isfloating || ntiled > 1) /* avoid unnecessary border reverts */ - adjustborder(c, borderpx); XMoveWindow(dpy, c->win, c->x, c->y); if(!lt[sellt]->arrange || c->isfloating) resize(c, c->x, c->y, c->w, c->h, True); @@ -1414,7 +1398,6 @@ tile(void) { /* master */ c = nexttiled(clients); mw = mfact * ww; - adjustborder(c, n == 1 ? 0 : borderpx); resize(c, wx, wy, (n == 1 ? ww : mw) - 2 * c->bw, wh - 2 * c->bw, resizehints); if(--n == 0) @@ -1429,7 +1412,6 @@ tile(void) { h = wh; for(i = 0, c = nexttiled(c->next); c; c = nexttiled(c->next), i++) { - adjustborder(c, borderpx); resize(c, x, y, w - 2 * c->bw, /* remainder */ ((i + 1 == n) ? wy + wh - y - 2 * c->bw : h - 2 * c->bw), resizehints); if(h != wh) @@ -1713,7 +1695,7 @@ main(int argc, char *argv[]) { die("usage: dwm [-v]\n"); if(!setlocale(LC_CTYPE, "") || !XSupportsLocale()) - fprintf(stderr, "warning: no locale support\n"); + fputs("warning: no locale support\n", stderr); if(!(dpy = XOpenDisplay(0))) die("dwm: cannot open display\n"); -- 2.20.1 From 1c80c05587e0f9fc23fb774aa2ef3b297fc8f6d8 Mon Sep 17 00:00:00 2001 From: Anselm R Garbe Date: Sat, 21 Feb 2009 19:15:30 +0000 Subject: [PATCH 04/16] override_redirect is Bool --- dwm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dwm.c b/dwm.c index 5f42cbe..0866c06 100644 --- a/dwm.c +++ b/dwm.c @@ -1305,7 +1305,7 @@ setup(void) { blw = MAX(blw, w); } - wa.override_redirect = 1; + wa.override_redirect = True; wa.background_pixmap = ParentRelative; wa.event_mask = ButtonPressMask|ExposureMask; -- 2.20.1 From f0d1d5206f926f58b259af3294a4eebf53a9e7bd Mon Sep 17 00:00:00 2001 From: Anselm R Garbe Date: Sat, 21 Feb 2009 19:20:11 +0000 Subject: [PATCH 05/16] some NULL fixes --- dwm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dwm.c b/dwm.c index 0866c06..613b6f1 100644 --- a/dwm.c +++ b/dwm.c @@ -1294,7 +1294,7 @@ setup(void) { dc.sel[ColBG] = getcolor(selbgcolor); dc.sel[ColFG] = getcolor(selfgcolor); dc.drawable = XCreatePixmap(dpy, root, DisplayWidth(dpy, screen), bh, DefaultDepth(dpy, screen)); - dc.gc = XCreateGC(dpy, root, 0, 0); + dc.gc = XCreateGC(dpy, root, 0, NULL); XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter); if(!dc.font.set) XSetFont(dpy, dc.gc, dc.font.xfont->fid); @@ -1697,7 +1697,7 @@ main(int argc, char *argv[]) { if(!setlocale(LC_CTYPE, "") || !XSupportsLocale()) fputs("warning: no locale support\n", stderr); - if(!(dpy = XOpenDisplay(0))) + if(!(dpy = XOpenDisplay(NULL))) die("dwm: cannot open display\n"); checkotherwm(); -- 2.20.1 From af508c2e8209a5e967dc67726919bc4da60b2c2c Mon Sep 17 00:00:00 2001 From: Anselm R Garbe Date: Mon, 2 Mar 2009 10:43:48 +0000 Subject: [PATCH 06/16] applied Gottox' resizehints patch, thanks Gottox! --- dwm.c | 97 ++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 52 insertions(+), 45 deletions(-) diff --git a/dwm.c b/dwm.c index 613b6f1..e1c0645 100644 --- a/dwm.c +++ b/dwm.c @@ -129,6 +129,7 @@ typedef struct { /* function declarations */ static void applyrules(Client *c); +static void applysizehints(Client *c, int *w, int *h); static void arrange(void); static void attach(Client *c); static void attachstack(Client *c); @@ -270,6 +271,55 @@ applyrules(Client *c) { c->tags = tagset[seltags]; } +void +applysizehints(Client *c, int *w, int *h) { + Bool baseismin; + + /* see last two sentences in ICCCM 4.1.2.3 */ + baseismin = c->basew == c->minw && c->baseh == c->minh; + + /* set minimum possible */ + *w = MAX(1, *w); + *h = MAX(1, *h); + + if(!baseismin) { /* temporarily remove base dimensions */ + *w -= c->basew; + *h -= c->baseh; + } + + /* adjust for aspect limits */ + if(c->mina > 0 && c->maxa > 0) { + if(c->maxa < (float)*w / *h) + *w = *h * c->maxa; + else if(c->mina < (float)*h / *w) + *h = *w * c->mina; + } + + if(baseismin) { /* increment calculation requires this */ + *w -= c->basew; + *h -= c->baseh; + } + + /* adjust for increment value */ + if(c->incw) + *w -= *w % c->incw; + if(c->inch) + *h -= *h % c->inch; + + /* restore base dimensions */ + *w += c->basew; + *h += c->baseh; + + *w = MAX(*w, c->minw); + *h = MAX(*h, c->minh); + + if(c->maxw) + *w = MIN(*w, c->maxw); + + if(c->maxh) + *h = MIN(*h, c->maxh); +} + void arrange(void) { unsigned int nt; @@ -1038,51 +1088,8 @@ void resize(Client *c, int x, int y, int w, int h, Bool sizehints) { XWindowChanges wc; - if(sizehints) { - /* see last two sentences in ICCCM 4.1.2.3 */ - Bool baseismin = c->basew == c->minw && c->baseh == c->minh; - - /* set minimum possible */ - w = MAX(1, w); - h = MAX(1, h); - - if(!baseismin) { /* temporarily remove base dimensions */ - w -= c->basew; - h -= c->baseh; - } - - /* adjust for aspect limits */ - if(c->mina > 0 && c->maxa > 0) { - if(c->maxa < (float)w / h) - w = h * c->maxa; - else if(c->mina < (float)h / w) - h = w * c->mina; - } - - if(baseismin) { /* increment calculation requires this */ - w -= c->basew; - h -= c->baseh; - } - - /* adjust for increment value */ - if(c->incw) - w -= w % c->incw; - if(c->inch) - h -= h % c->inch; - - /* restore base dimensions */ - w += c->basew; - h += c->baseh; - - w = MAX(w, c->minw); - h = MAX(h, c->minh); - - if(c->maxw) - w = MIN(w, c->maxw); - - if(c->maxh) - h = MIN(h, c->maxh); - } + if(sizehints) + applysizehints(c, &w, &h); if(w <= 0 || h <= 0) return; if(x > sx + sw) -- 2.20.1 From ea0008cba24b57f7955541568c8c527c06329ccd Mon Sep 17 00:00:00 2001 From: "arg@garbe.us" Date: Tue, 3 Mar 2009 11:22:16 +0000 Subject: [PATCH 07/16] applied the patch I missed from Gottox, thanks mate! --- dwm.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/dwm.c b/dwm.c index e1c0645..3ae709b 100644 --- a/dwm.c +++ b/dwm.c @@ -170,7 +170,7 @@ static void movemouse(const Arg *arg); static Client *nexttiled(Client *c); static void propertynotify(XEvent *e); static void quit(const Arg *arg); -static void resize(Client *c, int x, int y, int w, int h, Bool sizehints); +static void resize(Client *c, int x, int y, int w, int h); static void resizemouse(const Arg *arg); static void restack(void); static void run(void); @@ -275,6 +275,9 @@ void applysizehints(Client *c, int *w, int *h) { Bool baseismin; + if(!resizehints && !c->isfloating) + return; + /* see last two sentences in ICCCM 4.1.2.3 */ baseismin = c->basew == c->minw && c->baseh == c->minh; @@ -981,7 +984,7 @@ monocle(void) { Client *c; for(c = nexttiled(clients); c; c = nexttiled(c->next)) { - resize(c, wx, wy, ww - 2 * c->bw, wh - 2 * c->bw, resizehints); + resize(c, wx, wy, ww - 2 * c->bw, wh - 2 * c->bw); } } @@ -1029,7 +1032,7 @@ movemouse(const Arg *arg) { togglefloating(NULL); } if(!lt[sellt]->arrange || c->isfloating) - resize(c, nx, ny, c->w, c->h, False); + resize(c, nx, ny, c->w, c->h); break; } } @@ -1085,11 +1088,10 @@ quit(const Arg *arg) { } void -resize(Client *c, int x, int y, int w, int h, Bool sizehints) { +resize(Client *c, int x, int y, int w, int h) { XWindowChanges wc; - if(sizehints) - applysizehints(c, &w, &h); + applysizehints(c, &w, &h); if(w <= 0 || h <= 0) return; if(x > sx + sw) @@ -1154,7 +1156,7 @@ resizemouse(const Arg *arg) { togglefloating(NULL); } if(!lt[sellt]->arrange || c->isfloating) - resize(c, c->x, c->y, nw, nh, True); + resize(c, c->x, c->y, nw, nh); break; } } @@ -1344,7 +1346,7 @@ showhide(Client *c, unsigned int ntiled) { if(ISVISIBLE(c)) { /* show clients top down */ XMoveWindow(dpy, c->win, c->x, c->y); if(!lt[sellt]->arrange || c->isfloating) - resize(c, c->x, c->y, c->w, c->h, True); + resize(c, c->x, c->y, c->w, c->h); showhide(c->snext, ntiled); } else { /* hide clients bottom up */ @@ -1405,7 +1407,7 @@ tile(void) { /* master */ c = nexttiled(clients); mw = mfact * ww; - resize(c, wx, wy, (n == 1 ? ww : mw) - 2 * c->bw, wh - 2 * c->bw, resizehints); + resize(c, wx, wy, (n == 1 ? ww : mw) - 2 * c->bw, wh - 2 * c->bw); if(--n == 0) return; @@ -1420,7 +1422,7 @@ tile(void) { for(i = 0, c = nexttiled(c->next); c; c = nexttiled(c->next), i++) { resize(c, x, y, w - 2 * c->bw, /* remainder */ ((i + 1 == n) - ? wy + wh - y - 2 * c->bw : h - 2 * c->bw), resizehints); + ? wy + wh - y - 2 * c->bw : h - 2 * c->bw)); if(h != wh) y = c->y + HEIGHT(c); } @@ -1440,7 +1442,7 @@ togglefloating(const Arg *arg) { return; sel->isfloating = !sel->isfloating || sel->isfixed; if(sel->isfloating) - resize(sel, sel->x, sel->y, sel->w, sel->h, True); + resize(sel, sel->x, sel->y, sel->w, sel->h); arrange(); } -- 2.20.1 From 565697087b92db6eb09e896f60f68503ce0a4ac1 Mon Sep 17 00:00:00 2001 From: Anselm R Garbe Date: Tue, 17 Mar 2009 19:53:00 +0000 Subject: [PATCH 08/16] applied Gottox' patches, and also removed usegrab --- config.def.h | 2 - dwm.c | 120 +++++++++++++++++++++++---------------------------- 2 files changed, 55 insertions(+), 67 deletions(-) diff --git a/config.def.h b/config.def.h index bb60471..b270fef 100644 --- a/config.def.h +++ b/config.def.h @@ -12,8 +12,6 @@ static unsigned int borderpx = 1; /* border pixel of windows */ static unsigned int snap = 32; /* snap pixel */ static Bool showbar = True; /* False means no bar */ static Bool topbar = True; /* False means bottom bar */ -static Bool usegrab = False; /* True means grabbing the X server - during mouse-based resizals */ /* tagging */ static const char tags[][MAXTAGLEN] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; diff --git a/dwm.c b/dwm.c index 3ae709b..43dcdc0 100644 --- a/dwm.c +++ b/dwm.c @@ -129,7 +129,7 @@ typedef struct { /* function declarations */ static void applyrules(Client *c); -static void applysizehints(Client *c, int *w, int *h); +static Bool applysizehints(Client *c, int *x, int *y, int *w, int *h); static void arrange(void); static void attach(Client *c); static void attachstack(Client *c); @@ -252,6 +252,7 @@ applyrules(Client *c) { XClassHint ch = { 0 }; /* rule matching */ + c->isfloating = c->tags = 0; if(XGetClassHint(dpy, c->win, &ch)) { for(i = 0; i < LENGTH(rules); i++) { r = &rules[i]; @@ -259,7 +260,7 @@ applyrules(Client *c) { && (!r->class || (ch.res_class && strstr(ch.res_class, r->class))) && (!r->instance || (ch.res_name && strstr(ch.res_name, r->instance)))) { c->isfloating = r->isfloating; - c->tags |= r->tags & TAGMASK ? r->tags & TAGMASK : tagset[seltags]; + c->tags |= r->tags; } } if(ch.res_class) @@ -267,60 +268,72 @@ applyrules(Client *c) { if(ch.res_name) XFree(ch.res_name); } - if(!c->tags) - c->tags = tagset[seltags]; + c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : tagset[seltags]; } -void -applysizehints(Client *c, int *w, int *h) { +Bool +applysizehints(Client *c, int *x, int *y, int *w, int *h) { Bool baseismin; - if(!resizehints && !c->isfloating) - return; - - /* see last two sentences in ICCCM 4.1.2.3 */ - baseismin = c->basew == c->minw && c->baseh == c->minh; - /* set minimum possible */ *w = MAX(1, *w); *h = MAX(1, *h); - if(!baseismin) { /* temporarily remove base dimensions */ - *w -= c->basew; - *h -= c->baseh; - } + if(*x > sx + sw) + *x = sw - WIDTH(c); + if(*y > sy + sh) + *y = sh - HEIGHT(c); + if(*x + *w + 2 * c->bw < sx) + *x = sx; + if(*y + *h + 2 * c->bw < sy) + *y = sy; + if(*h < bh) + *h = bh; + if(*w < bh) + *w = bh; + + if(resizehints || c->isfloating) { + /* see last two sentences in ICCCM 4.1.2.3 */ + baseismin = c->basew == c->minw && c->baseh == c->minh; + + if(!baseismin) { /* temporarily remove base dimensions */ + *w -= c->basew; + *h -= c->baseh; + } - /* adjust for aspect limits */ - if(c->mina > 0 && c->maxa > 0) { - if(c->maxa < (float)*w / *h) - *w = *h * c->maxa; - else if(c->mina < (float)*h / *w) - *h = *w * c->mina; - } + /* adjust for aspect limits */ + if(c->mina > 0 && c->maxa > 0) { + if(c->maxa < (float)*w / *h) + *w = *h * c->maxa; + else if(c->mina < (float)*h / *w) + *h = *w * c->mina; + } - if(baseismin) { /* increment calculation requires this */ - *w -= c->basew; - *h -= c->baseh; - } + if(baseismin) { /* increment calculation requires this */ + *w -= c->basew; + *h -= c->baseh; + } - /* adjust for increment value */ - if(c->incw) - *w -= *w % c->incw; - if(c->inch) - *h -= *h % c->inch; + /* adjust for increment value */ + if(c->incw) + *w -= *w % c->incw; + if(c->inch) + *h -= *h % c->inch; - /* restore base dimensions */ - *w += c->basew; - *h += c->baseh; + /* restore base dimensions */ + *w += c->basew; + *h += c->baseh; - *w = MAX(*w, c->minw); - *h = MAX(*h, c->minh); + *w = MAX(*w, c->minw); + *h = MAX(*h, c->minh); - if(c->maxw) - *w = MIN(*w, c->maxw); + if(c->maxw) + *w = MIN(*w, c->maxw); - if(c->maxh) - *h = MIN(*h, c->maxh); + if(c->maxh) + *h = MIN(*h, c->maxh); + } + return *x != c->x || *y != c->y || *w != c->w || *h != c->h; } void @@ -1005,8 +1018,6 @@ movemouse(const Arg *arg) { None, cursor[CurMove], CurrentTime) != GrabSuccess) return; XQueryPointer(dpy, root, &dummy, &dummy, &x, &y, &di, &di, &dui); - if(usegrab) - XGrabServer(dpy); do { XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev); switch (ev.type) { @@ -1037,8 +1048,6 @@ movemouse(const Arg *arg) { } } while(ev.type != ButtonRelease); - if(usegrab) - XUngrabServer(dpy); XUngrabPointer(dpy, CurrentTime); } @@ -1091,22 +1100,7 @@ void resize(Client *c, int x, int y, int w, int h) { XWindowChanges wc; - applysizehints(c, &w, &h); - if(w <= 0 || h <= 0) - return; - if(x > sx + sw) - x = sw - WIDTH(c); - if(y > sy + sh) - y = sh - HEIGHT(c); - if(x + w + 2 * c->bw < sx) - x = sx; - if(y + h + 2 * c->bw < sy) - y = sy; - if(h < bh) - h = bh; - if(w < bh) - w = bh; - if(c->x != x || c->y != y || c->w != w || c->h != h) { + if(applysizehints(c, &x, &y, &w, &h)) { c->x = wc.x = x; c->y = wc.y = y; c->w = wc.width = w; @@ -1135,8 +1129,6 @@ resizemouse(const Arg *arg) { None, cursor[CurResize], CurrentTime) != GrabSuccess) return; XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1); - if(usegrab) - XGrabServer(dpy); do { XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev); switch(ev.type) { @@ -1161,8 +1153,6 @@ resizemouse(const Arg *arg) { } } while(ev.type != ButtonRelease); - if(usegrab) - XUngrabServer(dpy); XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1); XUngrabPointer(dpy, CurrentTime); while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); -- 2.20.1 From 3632d7132fc212a50e62327858a3d15c0e81e030 Mon Sep 17 00:00:00 2001 From: Anselm R Garbe Date: Thu, 19 Mar 2009 13:06:15 +0000 Subject: [PATCH 09/16] applied Marc Andre Tanners showhide patch, the removal of ntiled --- config.mk | 4 ++-- dwm.c | 14 +++++--------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/config.mk b/config.mk index 40e74b0..957a92c 100644 --- a/config.mk +++ b/config.mk @@ -11,8 +11,8 @@ X11INC = /usr/X11R6/include X11LIB = /usr/X11R6/lib # Xinerama, un-comment if you want it -#XINERAMALIBS = -L${X11LIB} -lXinerama -#XINERAMAFLAGS = -DXINERAMA +XINERAMALIBS = -L${X11LIB} -lXinerama +XINERAMAFLAGS = -DXINERAMA # includes and libs INCS = -I. -I/usr/include -I${X11INC} diff --git a/dwm.c b/dwm.c index 43dcdc0..8620306 100644 --- a/dwm.c +++ b/dwm.c @@ -179,7 +179,7 @@ static void setclientstate(Client *c, long state); static void setlayout(const Arg *arg); static void setmfact(const Arg *arg); static void setup(void); -static void showhide(Client *c, unsigned int ntiled); +static void showhide(Client *c); static void sigchld(int signal); static void spawn(const Arg *arg); static void tag(const Arg *arg); @@ -338,11 +338,7 @@ applysizehints(Client *c, int *x, int *y, int *w, int *h) { void arrange(void) { - unsigned int nt; - Client *c; - - for(nt = 0, c = nexttiled(clients); c; c = nexttiled(c->next), nt++); - showhide(stack, nt); + showhide(stack); focus(NULL); if(lt[sellt]->arrange) lt[sellt]->arrange(); @@ -1330,17 +1326,17 @@ setup(void) { } void -showhide(Client *c, unsigned int ntiled) { +showhide(Client *c) { if(!c) return; if(ISVISIBLE(c)) { /* show clients top down */ XMoveWindow(dpy, c->win, c->x, c->y); if(!lt[sellt]->arrange || c->isfloating) resize(c, c->x, c->y, c->w, c->h); - showhide(c->snext, ntiled); + showhide(c->snext); } else { /* hide clients bottom up */ - showhide(c->snext, ntiled); + showhide(c->snext); XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y); } } -- 2.20.1 From 0b45199cecd4f77ff0da2c42e763511dcfba2d9a Mon Sep 17 00:00:00 2001 From: Anselm R Garbe Date: Sat, 18 Apr 2009 12:49:34 +0100 Subject: [PATCH 10/16] Added tag 5.5 for changeset deaa276abac1 --- .hgtags | 1 + 1 file changed, 1 insertion(+) diff --git a/.hgtags b/.hgtags index 105c2c1..6ea1fa7 100644 --- a/.hgtags +++ b/.hgtags @@ -60,3 +60,4 @@ e4bcaca8e6ef13d2c3b81f1218ad15e5da4d68bd 5.2 335301ed102fec9b1a15d06bfa0184d53b38fa54 5.3.1 8b7836a471f8f9ee61bec980df00971888d76343 5.4 85a78d8afa0fe8b106a8223b5327e5bddb5dd5e3 5.4.1 +deaa276abac17ca08fbeb936916e4c8292d293a4 5.5 -- 2.20.1 From 7df39f3fc71aa62e64664787902152b41617fe1c Mon Sep 17 00:00:00 2001 From: Anselm R Garbe Date: Mon, 20 Apr 2009 11:03:33 +0100 Subject: [PATCH 11/16] next version will be 5.6, shortened some very long lines --- config.mk | 2 +- dwm.c | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/config.mk b/config.mk index 957a92c..bd9c6b3 100644 --- a/config.mk +++ b/config.mk @@ -1,5 +1,5 @@ # dwm version -VERSION = 5.5 +VERSION = 5.6 # Customize below to fit your system diff --git a/dwm.c b/dwm.c index 8620306..9266892 100644 --- a/dwm.c +++ b/dwm.c @@ -797,7 +797,10 @@ grabbuttons(Client *c, Bool focused) { for(i = 0; i < LENGTH(buttons); i++) if(buttons[i].click == ClkClientWin) for(j = 0; j < LENGTH(modifiers); j++) - XGrabButton(dpy, buttons[i].button, buttons[i].mask | modifiers[j], c->win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None); + XGrabButton(dpy, buttons[i].button, + buttons[i].mask | modifiers[j], + c->win, False, BUTTONMASK, + GrabModeAsync, GrabModeSync, None, None); } else XGrabButton(dpy, AnyButton, AnyModifier, c->win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None); @@ -936,7 +939,8 @@ manage(Window w, XWindowAttributes *wa) { c->y = sy + sh - HEIGHT(c); c->x = MAX(c->x, sx); /* only fix client y-offset, if the client center might cover the bar */ - c->y = MAX(c->y, ((by == 0) && (c->x + (c->w / 2) >= wx) && (c->x + (c->w / 2) < wx + ww)) ? bh : sy); + c->y = MAX(c->y, ((by == 0) && (c->x + (c->w / 2) >= wx) + && (c->x + (c->w / 2) < wx + ww)) ? bh : sy); c->bw = borderpx; } @@ -1035,7 +1039,8 @@ movemouse(const Arg *arg) { ny = wy; else if(abs((wy + wh) - (ny + HEIGHT(c))) < snap) ny = wy + wh - HEIGHT(c); - if(!c->isfloating && lt[sellt]->arrange && (abs(nx - c->x) > snap || abs(ny - c->y) > snap)) + if(!c->isfloating && lt[sellt]->arrange + && (abs(nx - c->x) > snap || abs(ny - c->y) > snap)) togglefloating(NULL); } if(!lt[sellt]->arrange || c->isfloating) @@ -1540,7 +1545,8 @@ updatenumlockmask(void) { modmap = XGetModifierMapping(dpy); for(i = 0; i < 8; i++) for(j = 0; j < modmap->max_keypermod; j++) - if(modmap->modifiermap[i * modmap->max_keypermod + j] == XKeysymToKeycode(dpy, XK_Num_Lock)) + if(modmap->modifiermap[i * modmap->max_keypermod + j] + == XKeysymToKeycode(dpy, XK_Num_Lock)) numlockmask = (1 << i); XFreeModifiermap(modmap); } -- 2.20.1 From 2dbfda72f0c7269c3fcbb5c93173013e7dd0bea6 Mon Sep 17 00:00:00 2001 From: Anselm R Garbe Date: Fri, 29 May 2009 09:29:22 +0100 Subject: [PATCH 12/16] removed MAXTAGLEN --- config.def.h | 4 ++-- dwm.c | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/config.def.h b/config.def.h index b270fef..ca2d423 100644 --- a/config.def.h +++ b/config.def.h @@ -1,7 +1,7 @@ /* See LICENSE file for copyright and license details. */ /* appearance */ -static const char font[] = "-*-terminus-medium-r-normal-*-14-*-*-*-*-*-*-*"; +static const char font[] = "-*-*-medium-*-*-*-14-*-*-*-*-*-*-*"; static const char normbordercolor[] = "#cccccc"; static const char normbgcolor[] = "#cccccc"; static const char normfgcolor[] = "#000000"; @@ -14,7 +14,7 @@ static Bool showbar = True; /* False means no bar */ static Bool topbar = True; /* False means bottom bar */ /* tagging */ -static const char tags[][MAXTAGLEN] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; +static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; static unsigned int tagset[] = {1, 1}; /* after start, first tag is selected */ static Rule rules[] = { diff --git a/dwm.c b/dwm.c index 9266892..1709db0 100644 --- a/dwm.c +++ b/dwm.c @@ -48,7 +48,6 @@ #define LENGTH(x) (sizeof x / sizeof x[0]) #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b)) -#define MAXTAGLEN 16 #define MOUSEMASK (BUTTONMASK|PointerMotionMask) #define WIDTH(x) ((x)->w + 2 * (x)->bw) #define HEIGHT(x) ((x)->h + 2 * (x)->bw) -- 2.20.1 From f27ccc5c60e4518c90f33bb20e68ea7bb23a2947 Mon Sep 17 00:00:00 2001 From: Anselm R Garbe Date: Fri, 19 Jun 2009 20:15:15 +0100 Subject: [PATCH 13/16] introduction of Monitor for better Xinerama support, work in progress --- config.mk | 4 +- dwm.c | 183 +++++++++++++++++++++++++++++++----------------------- 2 files changed, 109 insertions(+), 78 deletions(-) diff --git a/config.mk b/config.mk index bd9c6b3..43c324b 100644 --- a/config.mk +++ b/config.mk @@ -11,8 +11,8 @@ X11INC = /usr/X11R6/include X11LIB = /usr/X11R6/lib # Xinerama, un-comment if you want it -XINERAMALIBS = -L${X11LIB} -lXinerama -XINERAMAFLAGS = -DXINERAMA +#XINERAMALIBS = -L${X11LIB} -lXinerama +#XINERAMAFLAGS = -DXINERAMA # includes and libs INCS = -I. -I/usr/include -I${X11INC} diff --git a/dwm.c b/dwm.c index 1709db0..75c9a76 100644 --- a/dwm.c +++ b/dwm.c @@ -44,7 +44,7 @@ #define BUTTONMASK (ButtonPressMask|ButtonReleaseMask) #define CLEANMASK(mask) (mask & ~(numlockmask|LockMask)) #define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= (RY) && (Y) < (RY) + (RH)) -#define ISVISIBLE(x) (x->tags & tagset[seltags]) +#define ISVISIBLE(x) (x->tags & tagset[selmon->seltags]) #define LENGTH(x) (sizeof x / sizeof x[0]) #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b)) @@ -85,6 +85,7 @@ struct Client { int basew, baseh, incw, inch, maxw, maxh, minw, minh; int bw, oldbw; unsigned int tags; + unsigned int mon; Bool isfixed, isfloating, isurgent; Client *next; Client *snext; @@ -118,6 +119,12 @@ typedef struct { void (*arrange)(void); } Layout; +typedef struct { + int wx, wy, ww, wh; + unsigned int seltags; + unsigned int sellt; +} Monitor; + typedef struct { const char *class; const char *instance; @@ -208,8 +215,6 @@ static char stext[256]; static int screen; static int sx, sy, sw, sh; /* X display screen geometry x, y, width, height */ static int by, bh, blw; /* bar geometry y, height and layout symbol width */ -static int wx, wy, ww, wh; /* window area geometry x, y, width, height, bar excluded */ -static unsigned int seltags = 0, sellt = 0; static int (*xerrorxlib)(Display *, XErrorEvent *); static unsigned int numlockmask = 0; static void (*handler[LASTEvent]) (XEvent *) = { @@ -236,6 +241,8 @@ static Cursor cursor[CurLast]; static Display *dpy; static DC dc; static Layout *lt[] = { NULL, NULL }; +static Monitor *mon = NULL, *selmon = NULL; +static unsigned int nmons; static Window root, barwin; /* configuration, allows nested code to access above variables */ #include "config.h" @@ -267,7 +274,7 @@ applyrules(Client *c) { if(ch.res_name) XFree(ch.res_name); } - c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : tagset[seltags]; + c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : tagset[mon[c->mon].seltags]; } Bool @@ -339,8 +346,8 @@ void arrange(void) { showhide(stack); focus(NULL); - if(lt[sellt]->arrange) - lt[sellt]->arrange(); + if(lt[selmon->sellt]->arrange) + lt[selmon->sellt]->arrange(); restack(); } @@ -373,7 +380,7 @@ buttonpress(XEvent *e) { } else if(ev->x < x + blw) click = ClkLtSymbol; - else if(ev->x > wx + ww - TEXTW(stext)) + else if(ev->x > selmon->wx + selmon->ww - TEXTW(stext)) click = ClkStatusText; else click = ClkWinTitle; @@ -409,7 +416,7 @@ cleanup(void) { Layout foo = { "", NULL }; view(&a); - lt[sellt] = &foo; + lt[selmon->sellt] = &foo; while(stack) unmanage(stack); if(dc.font.set) @@ -479,7 +486,7 @@ configurerequest(XEvent *e) { if((c = getclient(ev->window))) { if(ev->value_mask & CWBorderWidth) c->bw = ev->border_width; - else if(c->isfloating || !lt[sellt]->arrange) { + else if(c->isfloating || !lt[selmon->sellt]->arrange) { if(ev->value_mask & CWX) c->x = sx + ev->x; if(ev->value_mask & CWY) @@ -564,23 +571,23 @@ drawbar(void) { dc.x = 0; for(i = 0; i < LENGTH(tags); i++) { dc.w = TEXTW(tags[i]); - col = tagset[seltags] & 1 << i ? dc.sel : dc.norm; + col = tagset[selmon->seltags] & 1 << i ? dc.sel : dc.norm; drawtext(tags[i], col, urg & 1 << i); drawsquare(sel && sel->tags & 1 << i, occ & 1 << i, urg & 1 << i, col); dc.x += dc.w; } if(blw > 0) { dc.w = blw; - drawtext(lt[sellt]->symbol, dc.norm, False); + drawtext(lt[selmon->sellt]->symbol, dc.norm, False); x = dc.x + dc.w; } else x = dc.x; dc.w = TEXTW(stext); - dc.x = ww - dc.w; + dc.x = selmon->ww - dc.w; if(dc.x < x) { dc.x = x; - dc.w = ww - x; + dc.w = selmon->ww - x; } drawtext(stext, dc.norm, False); if((dc.w = dc.x - x) > bh) { @@ -592,7 +599,7 @@ drawbar(void) { else drawtext(NULL, dc.norm, False); } - XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, ww, bh, 0, 0); + XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, selmon->ww, bh, 0, 0); XSync(dpy, False); } @@ -919,6 +926,7 @@ manage(Window w, XWindowAttributes *wa) { die("fatal: could not malloc() %u bytes\n", sizeof(Client)); *c = cz; c->win = w; + for(c->mon = 0; selmon != &mon[c->mon]; c->mon++); /* geometry */ c->x = wa->x; @@ -938,8 +946,9 @@ manage(Window w, XWindowAttributes *wa) { c->y = sy + sh - HEIGHT(c); c->x = MAX(c->x, sx); /* only fix client y-offset, if the client center might cover the bar */ - c->y = MAX(c->y, ((by == 0) && (c->x + (c->w / 2) >= wx) - && (c->x + (c->w / 2) < wx + ww)) ? bh : sy); + /* TODO: is c always attached to selmon? */ + c->y = MAX(c->y, ((by == 0) && (c->x + (c->w / 2) >= selmon->wx) + && (c->x + (c->w / 2) < selmon->wx + selmon->ww)) ? bh : sy); c->bw = borderpx; } @@ -994,9 +1003,11 @@ maprequest(XEvent *e) { void monocle(void) { Client *c; + Monitor *m; for(c = nexttiled(clients); c; c = nexttiled(c->next)) { - resize(c, wx, wy, ww - 2 * c->bw, wh - 2 * c->bw); + m = &mon[c->mon]; + resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw); } } @@ -1028,21 +1039,21 @@ movemouse(const Arg *arg) { case MotionNotify: nx = ocx + (ev.xmotion.x - x); ny = ocy + (ev.xmotion.y - y); - if(snap && nx >= wx && nx <= wx + ww - && ny >= wy && ny <= wy + wh) { - if(abs(wx - nx) < snap) - nx = wx; - else if(abs((wx + ww) - (nx + WIDTH(c))) < snap) - nx = wx + ww - WIDTH(c); - if(abs(wy - ny) < snap) - ny = wy; - else if(abs((wy + wh) - (ny + HEIGHT(c))) < snap) - ny = wy + wh - HEIGHT(c); - if(!c->isfloating && lt[sellt]->arrange + if(snap && nx >= selmon->wx && nx <= selmon->wx + selmon->ww + && ny >= selmon->wy && ny <= selmon->wy + selmon->wh) { + if(abs(selmon->wx - nx) < snap) + nx = selmon->wx; + else if(abs((selmon->wx + selmon->ww) - (nx + WIDTH(c))) < snap) + nx = selmon->wx + selmon->ww - WIDTH(c); + if(abs(selmon->wy - ny) < snap) + ny = selmon->wy; + else if(abs((selmon->wy + selmon->wh) - (ny + HEIGHT(c))) < snap) + ny = selmon->wy + selmon->wh - HEIGHT(c); + if(!c->isfloating && lt[selmon->sellt]->arrange && (abs(nx - c->x) > snap || abs(ny - c->y) > snap)) togglefloating(NULL); } - if(!lt[sellt]->arrange || c->isfloating) + if(!lt[selmon->sellt]->arrange || c->isfloating) resize(c, nx, ny, c->w, c->h); break; } @@ -1141,13 +1152,13 @@ resizemouse(const Arg *arg) { nw = MAX(ev.xmotion.x - ocx - 2 * c->bw + 1, 1); nh = MAX(ev.xmotion.y - ocy - 2 * c->bw + 1, 1); - if(snap && nw >= wx && nw <= wx + ww - && nh >= wy && nh <= wy + wh) { - if(!c->isfloating && lt[sellt]->arrange + if(snap && nw >= selmon->wx && nw <= selmon->wx + selmon->ww + && nh >= selmon->wy && nh <= selmon->wy + selmon->wh) { + if(!c->isfloating && lt[selmon->sellt]->arrange && (abs(nw - c->w) > snap || abs(nh - c->h) > snap)) togglefloating(NULL); } - if(!lt[sellt]->arrange || c->isfloating) + if(!lt[selmon->sellt]->arrange || c->isfloating) resize(c, c->x, c->y, nw, nh); break; } @@ -1167,9 +1178,9 @@ restack(void) { drawbar(); if(!sel) return; - if(sel->isfloating || !lt[sellt]->arrange) + if(sel->isfloating || !lt[selmon->sellt]->arrange) XRaiseWindow(dpy, sel->win); - if(lt[sellt]->arrange) { + if(lt[selmon->sellt]->arrange) { wc.stack_mode = Below; wc.sibling = barwin; for(c = stack; c; c = c->snext) @@ -1230,10 +1241,10 @@ setclientstate(Client *c, long state) { void setlayout(const Arg *arg) { - if(!arg || !arg->v || arg->v != lt[sellt]) - sellt ^= 1; + if(!arg || !arg->v || arg->v != lt[selmon->sellt]) + selmon->sellt ^= 1; if(arg && arg->v) - lt[sellt] = (Layout *)arg->v; + lt[selmon->sellt] = (Layout *)arg->v; if(sel) arrange(); else @@ -1245,7 +1256,7 @@ void setmfact(const Arg *arg) { float f; - if(!arg || !lt[sellt]->arrange) + if(!arg || !lt[selmon->sellt]->arrange) return; f = arg->f < 1.0 ? arg->f + mfact : arg->f - 1.0; if(f < 0.1 || f > 0.9) @@ -1308,7 +1319,7 @@ setup(void) { wa.background_pixmap = ParentRelative; wa.event_mask = ButtonPressMask|ExposureMask; - barwin = XCreateWindow(dpy, root, wx, by, ww, bh, 0, DefaultDepth(dpy, screen), + barwin = XCreateWindow(dpy, root, selmon->wx, by, selmon->ww, bh, 0, DefaultDepth(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen), CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa); XDefineCursor(dpy, barwin, cursor[CurNormal]); @@ -1335,7 +1346,7 @@ showhide(Client *c) { return; if(ISVISIBLE(c)) { /* show clients top down */ XMoveWindow(dpy, c->win, c->x, c->y); - if(!lt[sellt]->arrange || c->isfloating) + if(!lt[selmon->sellt]->arrange || c->isfloating) resize(c, c->x, c->y, c->w, c->h); showhide(c->snext); } @@ -1389,6 +1400,7 @@ tile(void) { int x, y, h, w, mw; unsigned int i, n; Client *c; + Monitor *m; for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next), n++); if(n == 0) @@ -1396,24 +1408,25 @@ tile(void) { /* master */ c = nexttiled(clients); - mw = mfact * ww; - resize(c, wx, wy, (n == 1 ? ww : mw) - 2 * c->bw, wh - 2 * c->bw); + m = &mon[c->mon]; + mw = mfact * m->ww; + resize(c, m->wx, m->wy, (n == 1 ? m->ww : mw) - 2 * c->bw, m->wh - 2 * c->bw); if(--n == 0) return; /* tile stack */ - x = (wx + mw > c->x + c->w) ? c->x + c->w + 2 * c->bw : wx + mw; - y = wy; - w = (wx + mw > c->x + c->w) ? wx + ww - x : ww - mw; - h = wh / n; + x = (m->wx + mw > c->x + c->w) ? c->x + c->w + 2 * c->bw : m->wx + mw; + y = m->wy; + w = (m->wx + mw > c->x + c->w) ? m->wx + m->ww - x : m->ww - mw; + h = m->wh / n; if(h < bh) - h = wh; + h = m->wh; for(i = 0, c = nexttiled(c->next); c; c = nexttiled(c->next), i++) { resize(c, x, y, w - 2 * c->bw, /* remainder */ ((i + 1 == n) - ? wy + wh - y - 2 * c->bw : h - 2 * c->bw)); - if(h != wh) + ? m->wy + m->wh - y - 2 * c->bw : h - 2 * c->bw)); + if(h != m->wh) y = c->y + HEIGHT(c); } } @@ -1452,10 +1465,10 @@ toggletag(const Arg *arg) { void toggleview(const Arg *arg) { - unsigned int mask = tagset[seltags] ^ (arg->ui & TAGMASK); + unsigned int mask = tagset[selmon->seltags] ^ (arg->ui & TAGMASK); if(mask) { - tagset[seltags] = mask; + tagset[selmon->seltags] = mask; arrange(); } } @@ -1495,44 +1508,62 @@ void updatebar(void) { if(dc.drawable != 0) XFreePixmap(dpy, dc.drawable); - dc.drawable = XCreatePixmap(dpy, root, ww, bh, DefaultDepth(dpy, screen)); - XMoveResizeWindow(dpy, barwin, wx, by, ww, bh); + dc.drawable = XCreatePixmap(dpy, root, selmon->ww, bh, DefaultDepth(dpy, screen)); + XMoveResizeWindow(dpy, barwin, selmon->wx, by, selmon->ww, bh); } void updategeom(void) { #ifdef XINERAMA - int n, i = 0; + int di, x, y, n; + unsigned int dui, i = 0; + Bool pquery; + Client *c; + Window dummy; XineramaScreenInfo *info = NULL; /* window area geometry */ if(XineramaIsActive(dpy) && (info = XineramaQueryScreens(dpy, &n))) { - if(n > 1) { - int di, x, y; - unsigned int dui; - Window dummy; - if(XQueryPointer(dpy, root, &dummy, &dummy, &x, &y, &di, &di, &dui)) - for(i = 0; i < n; i++) - if(INRECT(x, y, info[i].x_org, info[i].y_org, info[i].width, info[i].height)) - break; + nmons = (unsigned int)n; + for(c = clients; c; c = c->next) + if(c->mon >= nmons) + c->mon = nmons - 1; + if(!(mon = (Monitor *)realloc(mon, sizeof(Monitor) * nmons))) + die("fatal: could not realloc() %u bytes\n", sizeof(Monitor) * nmons); + pquery = XQueryPointer(dpy, root, &dummy, &dummy, &x, &y, &di, &di, &dui); + for(i = 0; i < nmons; i++) { + /* TODO: consider re-using XineramaScreenInfo */ + mon[i].wx = info[i].x_org; + mon[i].wy = info[i].y_org; + mon[i].ww = info[i].width; + mon[i].wh = info[i].height; + mon[i].seltags = 0; + mon[i].sellt = 0; + if(pquery && INRECT(x, y, info[i].x_org, info[i].y_org, info[i].width, info[i].height)) + selmon = &mon[i]; } - wx = info[i].x_org; - wy = showbar && topbar ? info[i].y_org + bh : info[i].y_org; - ww = info[i].width; - wh = showbar ? info[i].height - bh : info[i].height; + /* bar adjustments of selmon */ + selmon->wy = showbar && topbar ? selmon->wy + bh : selmon->wy; + selmon->wh = showbar ? selmon->wh - bh : selmon->wh; XFree(info); } else #endif { - wx = sx; - wy = showbar && topbar ? sy + bh : sy; - ww = sw; - wh = showbar ? sh - bh : sh; + nmons = 1; + if(!(mon = (Monitor *)realloc(mon, sizeof(Monitor)))) + die("fatal: could not realloc() %u bytes\n", sizeof(Monitor)); + selmon = &mon[0]; + mon[0].wx = sx; + mon[0].wy = showbar && topbar ? sy + bh : sy; + mon[0].ww = sw; + mon[0].wh = showbar ? sh - bh : sh; + mon[0].seltags = 0; + mon[0].sellt = 0; } /* bar position */ - by = showbar ? (topbar ? wy - bh : wy + wh) : -bh; + by = showbar ? (topbar ? selmon->wy - bh : selmon->wy + selmon->wh) : -bh; } void @@ -1631,11 +1662,11 @@ updatewmhints(Client *c) { void view(const Arg *arg) { - if((arg->ui & TAGMASK) == tagset[seltags]) + if((arg->ui & TAGMASK) == tagset[selmon->seltags]) return; - seltags ^= 1; /* toggle sel tagset */ + selmon->seltags ^= 1; /* toggle sel tagset */ if(arg->ui & TAGMASK) - tagset[seltags] = arg->ui & TAGMASK; + tagset[selmon->seltags] = arg->ui & TAGMASK; arrange(); } @@ -1676,7 +1707,7 @@ void zoom(const Arg *arg) { Client *c = sel; - if(!lt[sellt]->arrange || lt[sellt]->arrange == monocle || (sel && sel->isfloating)) + if(!lt[selmon->sellt]->arrange || lt[selmon->sellt]->arrange == monocle || (sel && sel->isfloating)) return; if(c == nexttiled(clients)) if(!c || !(c = nexttiled(c->next))) -- 2.20.1 From 2ce37bc69ee72af7ea88376c73133f8a833204cf Mon Sep 17 00:00:00 2001 From: Anselm R Garbe Date: Sat, 20 Jun 2009 15:10:04 +0100 Subject: [PATCH 14/16] experimental xinerama support, two new actions, Mod1-w/e and Mod1-Shift-w/e --- config.def.h | 10 +- config.mk | 10 +- dwm.c | 310 ++++++++++++++++++++++++++++++++------------------- 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 */ static Bool showbar = True; /* False means no bar */ static Bool topbar = True; /* False means bottom bar */ + /* tagging */ static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; static 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 */ static Rule rules[] = { /* class instance title tags mask isfloating */ { "Gimp", NULL, NULL, 0, True }, - { "Firefox", NULL, NULL, 1 << 8, True }, + { "Firefox", NULL, NULL, 1 << 8, False }, + }; /* layout(s) */ @@ -68,6 +70,12 @@ static Key keys[] = { { MODKEY|ShiftMask, XK_space, togglefloating, {0} }, { MODKEY, XK_0, view, {.ui = ~0 } }, { MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } }, +#ifdef XINERAMA + { MODKEY, XK_w, focusmon, {.ui = 0 } }, + { MODKEY, XK_e, focusmon, {.ui = 1 } }, + { MODKEY|ShiftMask, XK_w, tagmon, {.ui = 0 } }, + { MODKEY|ShiftMask, XK_e, tagmon, {.ui = 1 } }, +#endif /* XINERAMA */ TAGKEYS( XK_1, 0) TAGKEYS( XK_2, 1) 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 X11LIB = /usr/X11R6/lib # Xinerama, un-comment if you want it -#XINERAMALIBS = -L${X11LIB} -lXinerama -#XINERAMAFLAGS = -DXINERAMA +XINERAMALIBS = -L${X11LIB} -lXinerama +XINERAMAFLAGS = -DXINERAMA # includes and libs INCS = -I. -I/usr/include -I${X11INC} @@ -20,8 +20,10 @@ LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 ${XINERAMALIBS} # flags CPPFLAGS = -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} -CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS} -LDFLAGS = -s ${LIBS} +CFLAGS = -g -std=c99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS} +#CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS} +LDFLAGS = -g ${LIBS} +#LDFLAGS = -s ${LIBS} # Solaris #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 @@ #include #ifdef XINERAMA #include -#endif +#endif /* XINERAMA */ /* macros */ #define BUTTONMASK (ButtonPressMask|ButtonReleaseMask) #define CLEANMASK(mask) (mask & ~(numlockmask|LockMask)) #define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= (RY) && (Y) < (RY) + (RH)) -#define ISVISIBLE(x) (x->tags & tagset[selmon->seltags]) +#define ISVISIBLE(x) (x->tags & tagset[mon[x->mon].seltags]) #define LENGTH(x) (sizeof x / sizeof x[0]) #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b)) @@ -115,16 +115,21 @@ typedef struct { } Key; typedef struct { - const char *symbol; - void (*arrange)(void); -} Layout; - -typedef struct { - int wx, wy, ww, wh; + char symbol[4]; + int by, btx; /* bar geometry */ + int wx, wy, ww, wh; /* window area */ unsigned int seltags; unsigned int sellt; + Bool showbar; + Bool topbar; + Window barwin; } Monitor; +typedef struct { + const char *symbol; + void (*arrange)(Monitor *); +} Layout; + typedef struct { const char *class; const char *instance; @@ -150,7 +155,8 @@ static void destroynotify(XEvent *e); static void detach(Client *c); static void detachstack(Client *c); static void die(const char *errstr, ...); -static void drawbar(void); +static void drawbar(Monitor *m); +static void drawbars(); static void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]); static void drawtext(const char *text, unsigned long col[ColLast], Bool invert); static void enternotify(XEvent *e); @@ -171,14 +177,14 @@ static void killclient(const Arg *arg); static void manage(Window w, XWindowAttributes *wa); static void mappingnotify(XEvent *e); static void maprequest(XEvent *e); -static void monocle(void); +static void monocle(Monitor *m); static void movemouse(const Arg *arg); -static Client *nexttiled(Client *c); +static Client *nexttiled(Monitor *m, Client *c); static void propertynotify(XEvent *e); static void quit(const Arg *arg); static void resize(Client *c, int x, int y, int w, int h); static void resizemouse(const Arg *arg); -static void restack(void); +static void restack(Monitor *m); static void run(void); static void scan(void); static void setclientstate(Client *c, long state); @@ -190,14 +196,13 @@ static void sigchld(int signal); static void spawn(const Arg *arg); static void tag(const Arg *arg); static int textnw(const char *text, unsigned int len); -static void tile(void); +static void tile(Monitor *); static void togglebar(const Arg *arg); static void togglefloating(const Arg *arg); static void toggletag(const Arg *arg); static void toggleview(const Arg *arg); static void unmanage(Client *c); static void unmapnotify(XEvent *e); -static void updatebar(void); static void updategeom(void); static void updatenumlockmask(void); static void updatesizehints(Client *c); @@ -209,12 +214,16 @@ static int xerror(Display *dpy, XErrorEvent *ee); static int xerrordummy(Display *dpy, XErrorEvent *ee); static int xerrorstart(Display *dpy, XErrorEvent *ee); static void zoom(const Arg *arg); +#ifdef XINERAMA +static void focusmon(const Arg *arg); +static void tagmon(const Arg *arg); +#endif /* XINERAMA */ /* variables */ static char stext[256]; static int screen; -static int sx, sy, sw, sh; /* X display screen geometry x, y, width, height */ -static int by, bh, blw; /* bar geometry y, height and layout symbol width */ +static int sx, sy, sw, sh; /* X display screen geometry x, y, width, height */ +static int bh, blw = 0; /* bar geometry */ static int (*xerrorxlib)(Display *, XErrorEvent *); static unsigned int numlockmask = 0; static void (*handler[LASTEvent]) (XEvent *) = { @@ -243,7 +252,7 @@ static DC dc; static Layout *lt[] = { NULL, NULL }; static Monitor *mon = NULL, *selmon = NULL; static unsigned int nmons; -static Window root, barwin; +static Window root; /* configuration, allows nested code to access above variables */ #include "config.h" @@ -266,7 +275,7 @@ applyrules(Client *c) { && (!r->class || (ch.res_class && strstr(ch.res_class, r->class))) && (!r->instance || (ch.res_name && strstr(ch.res_name, r->instance)))) { c->isfloating = r->isfloating; - c->tags |= r->tags; + c->tags |= r->tags; } } if(ch.res_class) @@ -344,11 +353,14 @@ applysizehints(Client *c, int *x, int *y, int *w, int *h) { void arrange(void) { + unsigned int i; showhide(stack); focus(NULL); - if(lt[selmon->sellt]->arrange) - lt[selmon->sellt]->arrange(); - restack(); + for(i = 0; i < nmons; i++) { + if(lt[mon[i].sellt]->arrange) + lt[mon[i].sellt]->arrange(&mon[i]); + restack(&mon[i]); + } } void @@ -371,9 +383,12 @@ buttonpress(XEvent *e) { XButtonPressedEvent *ev = &e->xbutton; click = ClkRootWin; - if(ev->window == barwin) { - i = x = 0; - do x += TEXTW(tags[i]); while(ev->x >= x && ++i < LENGTH(tags)); + if(ev->window == selmon->barwin) { + i = 0; + x = selmon->btx; + do + x += TEXTW(tags[i]); + while(ev->x >= x && ++i < LENGTH(tags)); if(i < LENGTH(tags)) { click = ClkTagBar; arg.ui = 1 << i; @@ -412,6 +427,7 @@ checkotherwm(void) { void cleanup(void) { + unsigned int i; Arg a = {.ui = ~0}; Layout foo = { "", NULL }; @@ -429,7 +445,9 @@ cleanup(void) { XFreeCursor(dpy, cursor[CurNormal]); XFreeCursor(dpy, cursor[CurResize]); XFreeCursor(dpy, cursor[CurMove]); - XDestroyWindow(dpy, barwin); + for(i = 0; i < nmons; i++) + XDestroyWindow(dpy, mon[i].barwin); + free(mon); XSync(dpy, False); XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); } @@ -466,13 +484,18 @@ configure(Client *c) { void configurenotify(XEvent *e) { + unsigned int i; XConfigureEvent *ev = &e->xconfigure; if(ev->window == root && (ev->width != sw || ev->height != sh)) { sw = ev->width; sh = ev->height; updategeom(); - updatebar(); + if(dc.drawable != 0) + XFreePixmap(dpy, dc.drawable); + dc.drawable = XCreatePixmap(dpy, root, DisplayWidth(dpy, screen), bh, DefaultDepth(dpy, screen)); + for(i = 0; i < nmons; i++) + XMoveResizeWindow(dpy, mon[i].barwin, mon[i].wx, mon[i].by, mon[i].ww, bh); arrange(); } } @@ -556,53 +579,78 @@ die(const char *errstr, ...) { } void -drawbar(void) { +drawbar(Monitor *m) { int x; unsigned int i, occ = 0, urg = 0; unsigned long *col; Client *c; for(c = clients; c; c = c->next) { - occ |= c->tags; - if(c->isurgent) - urg |= c->tags; + if(m == &mon[c->mon]) { + occ |= c->tags; + if(c->isurgent) + urg |= c->tags; + } } dc.x = 0; +#ifdef XINERAMA + { + dc.w = TEXTW(m->symbol); + drawtext(m->symbol, selmon == m ? dc.sel : dc.norm, False); + dc.x += dc.w; + } +#endif /* XINERAMA */ + m->btx = dc.x; for(i = 0; i < LENGTH(tags); i++) { dc.w = TEXTW(tags[i]); - col = tagset[selmon->seltags] & 1 << i ? dc.sel : dc.norm; + col = tagset[m->seltags] & 1 << i ? dc.sel : dc.norm; drawtext(tags[i], col, urg & 1 << i); - drawsquare(sel && sel->tags & 1 << i, occ & 1 << i, urg & 1 << i, col); + drawsquare(m == selmon && sel && sel->tags & 1 << i, + occ & 1 << i, urg & 1 << i, col); dc.x += dc.w; } if(blw > 0) { dc.w = blw; - drawtext(lt[selmon->sellt]->symbol, dc.norm, False); + drawtext(lt[m->sellt]->symbol, dc.norm, False); x = dc.x + dc.w; } else x = dc.x; - dc.w = TEXTW(stext); - dc.x = selmon->ww - dc.w; - if(dc.x < x) { - dc.x = x; - dc.w = selmon->ww - x; - } - drawtext(stext, dc.norm, False); - if((dc.w = dc.x - x) > bh) { - dc.x = x; - if(sel) { - drawtext(sel->name, dc.sel, False); - drawsquare(sel->isfixed, sel->isfloating, False, dc.sel); + if(m == selmon) { + dc.w = TEXTW(stext); + dc.x = m->ww - dc.w; + if(dc.x < x) { + dc.x = x; + dc.w = m->ww - x; + } + drawtext(stext, dc.norm, False); + if((dc.w = dc.x - x) > bh) { + dc.x = x; + if(sel) { + drawtext(sel->name, dc.sel, False); + drawsquare(sel->isfixed, sel->isfloating, False, dc.sel); + } + else + drawtext(NULL, dc.norm, False); } - else - drawtext(NULL, dc.norm, False); } - XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, selmon->ww, bh, 0, 0); + else { + dc.w = m->ww - x; + drawtext(NULL, dc.norm, False); + } + XCopyArea(dpy, dc.drawable, m->barwin, dc.gc, 0, 0, m->ww, bh, 0, 0); XSync(dpy, False); } +void +drawbars() { + unsigned int i; + + for(i = 0; i < nmons; i++) + drawbar(&mon[i]); +} + void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]) { int x; @@ -667,10 +715,14 @@ enternotify(XEvent *e) { void expose(XEvent *e) { + unsigned int i; XExposeEvent *ev = &e->xexpose; - if(ev->count == 0 && (ev->window == barwin)) - drawbar(); + for(i = 0; i < nmons; i++) + if(ev->count == 0 && (ev->window == mon[i].barwin)) { + drawbar(&mon[i]); + break; + } } void @@ -693,7 +745,9 @@ focus(Client *c) { else XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); sel = c; - drawbar(); + if(c) + selmon = &mon[c->mon]; + drawbars(); } void @@ -704,13 +758,24 @@ focusin(XEvent *e) { /* there are some broken focus acquiring clients */ XSetInputFocus(dpy, sel->win, RevertToPointerRoot, CurrentTime); } +#ifdef XINERAMA +void +focusmon(const Arg *arg) { + if(arg->ui >= nmons) + return; + selmon = &mon[arg->ui]; + focus(NULL); + drawbars(); +} +#endif /* XINERAMA */ + void focusstack(const Arg *arg) { Client *c = NULL, *i; if(!sel) return; - if (arg->i > 0) { + if(arg->i > 0) { for(c = sel->next; c && !ISVISIBLE(c); c = c->next); if(!c) for(c = clients; c && !ISVISIBLE(c); c = c->next); @@ -726,7 +791,7 @@ focusstack(const Arg *arg) { } if(c) { focus(c); - restack(); + restack(selmon); } } @@ -946,9 +1011,8 @@ manage(Window w, XWindowAttributes *wa) { c->y = sy + sh - HEIGHT(c); c->x = MAX(c->x, sx); /* only fix client y-offset, if the client center might cover the bar */ - /* TODO: is c always attached to selmon? */ - c->y = MAX(c->y, ((by == 0) && (c->x + (c->w / 2) >= selmon->wx) - && (c->x + (c->w / 2) < selmon->wx + selmon->ww)) ? bh : sy); + c->y = MAX(c->y, ((selmon->by == 0) && (c->x + (c->w / 2) >= selmon->wx) + && (c->x + (c->w / 2) < selmon->wx + selmon->ww)) ? bh : sy); c->bw = borderpx; } @@ -1001,14 +1065,11 @@ maprequest(XEvent *e) { } void -monocle(void) { +monocle(Monitor *m) { Client *c; - Monitor *m; - for(c = nexttiled(clients); c; c = nexttiled(c->next)) { - m = &mon[c->mon]; + for(c = nexttiled(m, clients); c; c = nexttiled(m, c->next)) resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw); - } } void @@ -1021,7 +1082,7 @@ movemouse(const Arg *arg) { if(!(c = sel)) return; - restack(); + restack(selmon); ocx = c->x; ocy = c->y; if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, @@ -1063,8 +1124,9 @@ movemouse(const Arg *arg) { } Client * -nexttiled(Client *c) { - for(; c && (c->isfloating || !ISVISIBLE(c)); c = c->next); +nexttiled(Monitor *m, Client *c) { + // TODO: m handling + for(; c && (c->isfloating || m != &mon[c->mon] || !ISVISIBLE(c)); c = c->next); return c; } @@ -1091,13 +1153,13 @@ propertynotify(XEvent *e) { break; case XA_WM_HINTS: updatewmhints(c); - drawbar(); + drawbars(); break; } if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) { updatetitle(c); if(c == sel) - drawbar(); + drawbars(); } } } @@ -1133,7 +1195,7 @@ resizemouse(const Arg *arg) { if(!(c = sel)) return; - restack(); + restack(selmon); ocx = c->x; ocy = c->y; if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, @@ -1170,21 +1232,21 @@ resizemouse(const Arg *arg) { } void -restack(void) { +restack(Monitor *m) { Client *c; XEvent ev; XWindowChanges wc; - drawbar(); + drawbars(); if(!sel) return; - if(sel->isfloating || !lt[selmon->sellt]->arrange) + if(m == selmon && (sel->isfloating || !lt[m->sellt]->arrange)) XRaiseWindow(dpy, sel->win); - if(lt[selmon->sellt]->arrange) { + if(lt[m->sellt]->arrange) { wc.stack_mode = Below; - wc.sibling = barwin; + wc.sibling = m->barwin; for(c = stack; c; c = c->snext) - if(!c->isfloating && ISVISIBLE(c)) { + if(!c->isfloating && m == &mon[c->mon] && ISVISIBLE(c)) { XConfigureWindow(dpy, c->win, CWSibling|CWStackMode, &wc); wc.sibling = c->win; } @@ -1248,7 +1310,7 @@ setlayout(const Arg *arg) { if(sel) arrange(); else - drawbar(); + drawbars(); } /* arg > 1.0 will set mfact absolutly */ @@ -1309,21 +1371,23 @@ setup(void) { if(!dc.font.set) XSetFont(dpy, dc.gc, dc.font.xfont->fid); - /* init bar */ + /* init bars */ + wa.override_redirect = True; + wa.background_pixmap = ParentRelative; + wa.event_mask = ButtonPressMask|ExposureMask; for(blw = i = 0; LENGTH(layouts) > 1 && i < LENGTH(layouts); i++) { w = TEXTW(layouts[i].symbol); blw = MAX(blw, w); } - wa.override_redirect = True; - wa.background_pixmap = ParentRelative; - wa.event_mask = ButtonPressMask|ExposureMask; + for(i = 0; i < nmons; i++) { + mon[i].barwin = XCreateWindow(dpy, root, mon[i].wx, mon[i].by, mon[i].ww, bh, 0, DefaultDepth(dpy, screen), - barwin = XCreateWindow(dpy, root, selmon->wx, by, selmon->ww, bh, 0, DefaultDepth(dpy, screen), - CopyFromParent, DefaultVisual(dpy, screen), - CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa); - XDefineCursor(dpy, barwin, cursor[CurNormal]); - XMapRaised(dpy, barwin); + CopyFromParent, DefaultVisual(dpy, screen), + CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa); + XDefineCursor(dpy, mon[i].barwin, cursor[CurNormal]); + XMapRaised(dpy, mon[i].barwin); + } updatestatus(); /* EWMH support per view */ @@ -1384,6 +1448,16 @@ tag(const Arg *arg) { } } +#ifdef XINERAMA +void +tagmon(const Arg *arg) { + if(!sel || arg->ui >= nmons) + return; + sel->mon = arg->ui; + arrange(); +} +#endif /* XINERAMA */ + int textnw(const char *text, unsigned int len) { XRectangle r; @@ -1396,19 +1470,17 @@ textnw(const char *text, unsigned int len) { } void -tile(void) { +tile(Monitor *m) { int x, y, h, w, mw; unsigned int i, n; Client *c; - Monitor *m; - for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next), n++); + for(n = 0, c = nexttiled(m, clients); c; c = nexttiled(m, c->next), n++); if(n == 0) return; /* master */ - c = nexttiled(clients); - m = &mon[c->mon]; + c = nexttiled(m, clients); mw = mfact * m->ww; resize(c, m->wx, m->wy, (n == 1 ? m->ww : mw) - 2 * c->bw, m->wh - 2 * c->bw); @@ -1423,7 +1495,7 @@ tile(void) { if(h < bh) h = m->wh; - for(i = 0, c = nexttiled(c->next); c; c = nexttiled(c->next), i++) { + for(i = 0, c = nexttiled(m, c->next); c; c = nexttiled(m, c->next), i++) { resize(c, x, y, w - 2 * c->bw, /* remainder */ ((i + 1 == n) ? m->wy + m->wh - y - 2 * c->bw : h - 2 * c->bw)); if(h != m->wh) @@ -1433,9 +1505,9 @@ tile(void) { void togglebar(const Arg *arg) { - showbar = !showbar; + selmon->showbar = !selmon->showbar; updategeom(); - updatebar(); + XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh); arrange(); } @@ -1453,7 +1525,7 @@ void toggletag(const Arg *arg) { unsigned int mask; - if (!sel) + if(!sel) return; mask = sel->tags ^ (arg->ui & TAGMASK); @@ -1504,14 +1576,6 @@ unmapnotify(XEvent *e) { unmanage(c); } -void -updatebar(void) { - if(dc.drawable != 0) - XFreePixmap(dpy, dc.drawable); - dc.drawable = XCreatePixmap(dpy, root, selmon->ww, bh, DefaultDepth(dpy, screen)); - XMoveResizeWindow(dpy, barwin, selmon->wx, by, selmon->ww, bh); -} - void updategeom(void) { #ifdef XINERAMA @@ -1523,7 +1587,7 @@ updategeom(void) { XineramaScreenInfo *info = NULL; /* window area geometry */ - if(XineramaIsActive(dpy) && (info = XineramaQueryScreens(dpy, &n))) { + if(XineramaIsActive(dpy) && (info = XineramaQueryScreens(dpy, &n))) { nmons = (unsigned int)n; for(c = clients; c; c = c->next) if(c->mon >= nmons) @@ -1533,37 +1597,51 @@ updategeom(void) { pquery = XQueryPointer(dpy, root, &dummy, &dummy, &x, &y, &di, &di, &dui); for(i = 0; i < nmons; i++) { /* TODO: consider re-using XineramaScreenInfo */ + mon[i].symbol[0] = '['; + mon[i].symbol[1] = '0' + info[i].screen_number; + mon[i].symbol[2] = ']'; + mon[i].symbol[3] = 0; + mon[i].showbar = showbar; + mon[i].topbar = topbar; mon[i].wx = info[i].x_org; - mon[i].wy = info[i].y_org; + mon[i].wy = mon[i].showbar && mon[i].topbar ? info[i].y_org + bh : info[i].y_org; mon[i].ww = info[i].width; - mon[i].wh = info[i].height; + mon[i].wh = mon[i].showbar ? info[i].height - bh : info[i].height; mon[i].seltags = 0; mon[i].sellt = 0; + if(mon[i].showbar) + mon[i].by = mon[i].topbar ? info[i].y_org : mon[i].wy + mon[i].wh; + else + mon[i].by = -bh; if(pquery && INRECT(x, y, info[i].x_org, info[i].y_org, info[i].width, info[i].height)) selmon = &mon[i]; } - /* bar adjustments of selmon */ - selmon->wy = showbar && topbar ? selmon->wy + bh : selmon->wy; - selmon->wh = showbar ? selmon->wh - bh : selmon->wh; XFree(info); } else -#endif +#endif /* XINERAMA */ { nmons = 1; if(!(mon = (Monitor *)realloc(mon, sizeof(Monitor)))) die("fatal: could not realloc() %u bytes\n", sizeof(Monitor)); selmon = &mon[0]; + mon[0].symbol[0] = '['; + mon[0].symbol[1] = '0'; + mon[0].symbol[2] = ']'; + mon[0].symbol[3] = 0; + mon[0].showbar = showbar; + mon[0].topbar = topbar; mon[0].wx = sx; - mon[0].wy = showbar && topbar ? sy + bh : sy; + mon[0].wy = mon[0].showbar && mon[0].topbar ? sy + bh : sy; mon[0].ww = sw; - mon[0].wh = showbar ? sh - bh : sh; + mon[0].wh = mon[0].showbar ? sh - bh : sh; mon[0].seltags = 0; mon[0].sellt = 0; + if(mon[0].showbar) + mon[0].by = mon[0].topbar ? sy : mon[0].wy + mon[0].wh; + else + mon[0].by = -bh; } - - /* bar position */ - by = showbar ? (topbar ? selmon->wy - bh : selmon->wy + selmon->wh) : -bh; } void @@ -1588,7 +1666,7 @@ updatesizehints(Client *c) { if(!XGetWMNormalHints(dpy, c->win, &size, &msize)) /* size is uninitialized, ensure that size.flags aren't used */ - size.flags = PSize; + size.flags = PSize; if(size.flags & PBaseSize) { c->basew = size.base_width; c->baseh = size.base_height; @@ -1641,7 +1719,7 @@ void updatestatus() { if(!gettextprop(root, XA_WM_NAME, stext, sizeof(stext))) strcpy(stext, "dwm-"VERSION); - drawbar(); + drawbar(selmon); } void @@ -1709,8 +1787,8 @@ zoom(const Arg *arg) { if(!lt[selmon->sellt]->arrange || lt[selmon->sellt]->arrange == monocle || (sel && sel->isfloating)) return; - if(c == nexttiled(clients)) - if(!c || !(c = nexttiled(c->next))) + if(c == nexttiled(selmon, clients)) + if(!c || !(c = nexttiled(selmon, c->next))) return; detach(c); attach(c); -- 2.20.1 From 3da24539976b4474862415606f641d0f69336729 Mon Sep 17 00:00:00 2001 From: Anselm R Garbe Date: Sat, 20 Jun 2009 15:51:34 +0100 Subject: [PATCH 15/16] several fixes through ISVISIBLE change (takes Monitor into account) --- dwm.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/dwm.c b/dwm.c index 0e8c927..6084123 100644 --- a/dwm.c +++ b/dwm.c @@ -44,8 +44,8 @@ #define BUTTONMASK (ButtonPressMask|ButtonReleaseMask) #define CLEANMASK(mask) (mask & ~(numlockmask|LockMask)) #define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= (RY) && (Y) < (RY) + (RH)) -#define ISVISIBLE(x) (x->tags & tagset[mon[x->mon].seltags]) -#define LENGTH(x) (sizeof x / sizeof x[0]) +#define ISVISIBLE(M, C) ((M) == (&mon[C->mon]) && (C->tags & tagset[M->seltags])) +#define LENGTH(X) (sizeof X / sizeof X[0]) #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MOUSEMASK (BUTTONMASK|PointerMotionMask) @@ -493,7 +493,7 @@ configurenotify(XEvent *e) { updategeom(); if(dc.drawable != 0) XFreePixmap(dpy, dc.drawable); - dc.drawable = XCreatePixmap(dpy, root, DisplayWidth(dpy, screen), bh, DefaultDepth(dpy, screen)); + dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen)); for(i = 0; i < nmons; i++) XMoveResizeWindow(dpy, mon[i].barwin, mon[i].wx, mon[i].by, mon[i].ww, bh); arrange(); @@ -524,7 +524,7 @@ configurerequest(XEvent *e) { c->y = sy + (sh / 2 - c->h / 2); /* center in y direction */ if((ev->value_mask & (CWX|CWY)) && !(ev->value_mask & (CWWidth|CWHeight))) configure(c); - if(ISVISIBLE(c)) + if(ISVISIBLE((&mon[c->mon]), c)) XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); } else @@ -636,6 +636,7 @@ drawbar(Monitor *m) { } } else { + dc.x = x; dc.w = m->ww - x; drawtext(NULL, dc.norm, False); } @@ -718,17 +719,18 @@ expose(XEvent *e) { unsigned int i; XExposeEvent *ev = &e->xexpose; - for(i = 0; i < nmons; i++) - if(ev->count == 0 && (ev->window == mon[i].barwin)) { - drawbar(&mon[i]); - break; - } + if(ev->count == 0) + for(i = 0; i < nmons; i++) + if(ev->window == mon[i].barwin) { + drawbar(&mon[i]); + break; + } } void focus(Client *c) { - if(!c || !ISVISIBLE(c)) - for(c = stack; c && !ISVISIBLE(c); c = c->snext); + if(!c || !ISVISIBLE((&mon[c->mon]), c)) + for(c = stack; c && !ISVISIBLE(selmon, c); c = c->snext); if(sel && sel != c) { grabbuttons(sel, False); XSetWindowBorder(dpy, sel->win, dc.norm[ColBorder]); @@ -776,17 +778,17 @@ focusstack(const Arg *arg) { if(!sel) return; if(arg->i > 0) { - for(c = sel->next; c && !ISVISIBLE(c); c = c->next); + for(c = sel->next; c && !ISVISIBLE(selmon, c); c = c->next); if(!c) - for(c = clients; c && !ISVISIBLE(c); c = c->next); + for(c = clients; c && !ISVISIBLE(selmon, c); c = c->next); } else { for(i = clients; i != sel; i = i->next) - if(ISVISIBLE(i)) + if(ISVISIBLE(selmon, i)) c = i; if(!c) for(; i; i = i->next) - if(ISVISIBLE(i)) + if(ISVISIBLE(selmon, i)) c = i; } if(c) { @@ -1126,7 +1128,7 @@ movemouse(const Arg *arg) { Client * nexttiled(Monitor *m, Client *c) { // TODO: m handling - for(; c && (c->isfloating || m != &mon[c->mon] || !ISVISIBLE(c)); c = c->next); + for(; c && (c->isfloating || !ISVISIBLE(m, c)); c = c->next); return c; } @@ -1246,7 +1248,7 @@ restack(Monitor *m) { wc.stack_mode = Below; wc.sibling = m->barwin; for(c = stack; c; c = c->snext) - if(!c->isfloating && m == &mon[c->mon] && ISVISIBLE(c)) { + if(!c->isfloating && ISVISIBLE(m, c)) { XConfigureWindow(dpy, c->win, CWSibling|CWStackMode, &wc); wc.sibling = c->win; } @@ -1408,7 +1410,7 @@ void showhide(Client *c) { if(!c) return; - if(ISVISIBLE(c)) { /* show clients top down */ + if(ISVISIBLE((&mon[c->mon]), c)) { /* show clients top down */ XMoveWindow(dpy, c->win, c->x, c->y); if(!lt[selmon->sellt]->arrange || c->isfloating) resize(c, c->x, c->y, c->w, c->h); -- 2.20.1 From 6644a6aa2e4267fa67c811f60e6f9f99a0b1e067 Mon Sep 17 00:00:00 2001 From: Anselm R Garbe Date: Sat, 20 Jun 2009 16:18:02 +0100 Subject: [PATCH 16/16] some minor fixes regarding the new xinerama support --- dwm.c | 78 ++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 30 deletions(-) diff --git a/dwm.c b/dwm.c index 6084123..7ac3e5f 100644 --- a/dwm.c +++ b/dwm.c @@ -116,6 +116,7 @@ typedef struct { typedef struct { char symbol[4]; + float mfact; int by, btx; /* bar geometry */ int wx, wy, ww, wh; /* window area */ unsigned int seltags; @@ -251,7 +252,7 @@ static Display *dpy; static DC dc; static Layout *lt[] = { NULL, NULL }; static Monitor *mon = NULL, *selmon = NULL; -static unsigned int nmons; +static unsigned int nmons = 0; static Window root; /* configuration, allows nested code to access above variables */ #include "config.h" @@ -1322,10 +1323,10 @@ setmfact(const Arg *arg) { if(!arg || !lt[selmon->sellt]->arrange) return; - f = arg->f < 1.0 ? arg->f + mfact : arg->f - 1.0; + f = arg->f < 1.0 ? arg->f + selmon->mfact : arg->f - 1.0; if(f < 0.1 || f > 0.9) return; - mfact = f; + selmon->mfact = f; arrange(); } @@ -1483,7 +1484,7 @@ tile(Monitor *m) { /* master */ c = nexttiled(m, clients); - mw = mfact * m->ww; + mw = m->mfact * m->ww; resize(c, m->wx, m->wy, (n == 1 ? m->ww : mw) - 2 * c->bw, m->wh - 2 * c->bw); if(--n == 0) @@ -1581,30 +1582,31 @@ unmapnotify(XEvent *e) { void updategeom(void) { #ifdef XINERAMA - int di, x, y, n; - unsigned int dui, i = 0; - Bool pquery; + int n; + unsigned int i = 0; Client *c; - Window dummy; XineramaScreenInfo *info = NULL; /* window area geometry */ if(XineramaIsActive(dpy) && (info = XineramaQueryScreens(dpy, &n))) { - nmons = (unsigned int)n; - for(c = clients; c; c = c->next) - if(c->mon >= nmons) - c->mon = nmons - 1; - if(!(mon = (Monitor *)realloc(mon, sizeof(Monitor) * nmons))) - die("fatal: could not realloc() %u bytes\n", sizeof(Monitor) * nmons); - pquery = XQueryPointer(dpy, root, &dummy, &dummy, &x, &y, &di, &di, &dui); - for(i = 0; i < nmons; i++) { + if(n != nmons) { + for(c = clients; c; c = c->next) + if(c->mon >= n) + c->mon = n - 1; + if(!(mon = (Monitor *)realloc(mon, sizeof(Monitor) * n))) + die("fatal: could not realloc() %u bytes\n", sizeof(Monitor) * nmons); + } + for(i = 0; i < n ; i++) { /* TODO: consider re-using XineramaScreenInfo */ mon[i].symbol[0] = '['; mon[i].symbol[1] = '0' + info[i].screen_number; mon[i].symbol[2] = ']'; mon[i].symbol[3] = 0; - mon[i].showbar = showbar; - mon[i].topbar = topbar; + if(!selmon) { /* not initialised yet */ + mon[i].mfact = mfact; + mon[i].showbar = showbar; + mon[i].topbar = topbar; + } mon[i].wx = info[i].x_org; mon[i].wy = mon[i].showbar && mon[i].topbar ? info[i].y_org + bh : info[i].y_org; mon[i].ww = info[i].width; @@ -1615,24 +1617,39 @@ updategeom(void) { mon[i].by = mon[i].topbar ? info[i].y_org : mon[i].wy + mon[i].wh; else mon[i].by = -bh; - if(pquery && INRECT(x, y, info[i].x_org, info[i].y_org, info[i].width, info[i].height)) - selmon = &mon[i]; + } + nmons = (unsigned int)n; + if(!selmon) { + selmon = &mon[0]; + int di, x, y; + unsigned int dui; + Window dummy; + if(XQueryPointer(dpy, root, &dummy, &dummy, &x, &y, &di, &di, &dui)) + for(i = 0; i < nmons; i++) + if(INRECT(x, y, info[i].x_org, info[i].y_org, info[i].width, info[i].height)) { + selmon = &mon[i]; + break; + } } XFree(info); } else #endif /* XINERAMA */ { - nmons = 1; - if(!(mon = (Monitor *)realloc(mon, sizeof(Monitor)))) - die("fatal: could not realloc() %u bytes\n", sizeof(Monitor)); - selmon = &mon[0]; - mon[0].symbol[0] = '['; - mon[0].symbol[1] = '0'; - mon[0].symbol[2] = ']'; - mon[0].symbol[3] = 0; - mon[0].showbar = showbar; - mon[0].topbar = topbar; + if(!mon) { + nmons = 1; + if(!(mon = (Monitor *)malloc(sizeof(Monitor)))) + die("fatal: could not malloc() %u bytes\n", sizeof(Monitor)); + } + if(!selmon) { + mon[0].symbol[0] = '['; + mon[0].symbol[1] = '0'; + mon[0].symbol[2] = ']'; + mon[0].symbol[3] = 0; + mon[0].mfact = mfact; + mon[0].showbar = showbar; + mon[0].topbar = topbar; + } mon[0].wx = sx; mon[0].wy = mon[0].showbar && mon[0].topbar ? sy + bh : sy; mon[0].ww = sw; @@ -1643,6 +1660,7 @@ updategeom(void) { mon[0].by = mon[0].topbar ? sy : mon[0].wy + mon[0].wh; else mon[0].by = -bh; + selmon = &mon[0]; } } -- 2.20.1