From e8244395e4fb7f0617367187c799b1fbddeac7a2 Mon Sep 17 00:00:00 2001 From: Anselm R Garbe Date: Wed, 13 Feb 2008 20:34:17 +0000 Subject: [PATCH 01/16] urgency hook handling needs also to invert the square if present --- dwm.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/dwm.c b/dwm.c index 79a3a33..f992ea9 100644 --- a/dwm.c +++ b/dwm.c @@ -145,7 +145,7 @@ void destroynotify(XEvent *e); void detach(Client *c); void detachstack(Client *c); void drawbar(void); -void drawsquare(Monitor *, Bool filled, Bool empty, unsigned long col[ColLast]); +void drawsquare(Monitor *, Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]); void drawtext(Monitor *, const char *text, unsigned long col[ColLast], Bool invert); void *emallocz(unsigned int size); void enternotify(XEvent *e); @@ -570,11 +570,13 @@ drawbar(void) { m->dc.w = textw(m, tags[j]); if(m->seltags[j]) { drawtext(m, tags[j], m->dc.sel, isurgent(i, j)); - drawsquare(m, sel && sel->tags[j] && sel->monitor == selmonitor, isoccupied(m, j), m->dc.sel); + drawsquare(m, sel && sel->tags[j] && sel->monitor == selmonitor, + isoccupied(m, j), isurgent(i, j), m->dc.sel); } else { drawtext(m, tags[j], m->dc.norm, isurgent(i, j)); - drawsquare(m, sel && sel->tags[j] && sel->monitor == selmonitor, isoccupied(m, j), m->dc.norm); + drawsquare(m, sel && sel->tags[j] && sel->monitor == selmonitor, + isoccupied(m, j), isurgent(i, j), m->dc.norm); } m->dc.x += m->dc.w; } @@ -592,7 +594,7 @@ drawbar(void) { m->dc.x = x; if(sel && sel->monitor == selmonitor) { drawtext(m, sel->name, m->dc.sel, False); - drawsquare(m, False, sel->isfloating, m->dc.sel); + drawsquare(m, False, sel->isfloating, False, m->dc.sel); } else drawtext(m, NULL, m->dc.norm, False); @@ -603,12 +605,12 @@ drawbar(void) { } void -drawsquare(Monitor *m, Bool filled, Bool empty, unsigned long col[ColLast]) { +drawsquare(Monitor *m, Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]) { int x; XGCValues gcv; XRectangle r = { m->dc.x, m->dc.y, m->dc.w, m->dc.h }; - gcv.foreground = col[ColFG]; + gcv.foreground = col[invert ? ColBG : ColFG]; XChangeGC(dpy, m->dc.gc, GCForeground, &gcv); x = (m->dc.font.ascent + m->dc.font.descent + 2) / 4; r.x = m->dc.x + 1; @@ -1141,14 +1143,11 @@ monitorat() { XQueryPointer(dpy, monitors[selmonitor].root, &win, &win, &x, &y, &i, &i, &mask); for(i = 0; i < mcount; i++) { - fprintf(stderr, "checking monitor[%d]: %d %d %d %d\n", i, monitors[i].sx, monitors[i].sy, monitors[i].sw, monitors[i].sh); if((x >= monitors[i].sx && x < monitors[i].sx + monitors[i].sw) && (y >= monitors[i].sy && y < monitors[i].sy + monitors[i].sh)) { - fprintf(stderr, "%d,%d -> %d\n", x, y, i); return i; } } - fprintf(stderr, "?,? -> 0\n"); return 0; } -- 2.20.1 From 6ab163c6955cf7830dfbf39b6c7ba16114054d94 Mon Sep 17 00:00:00 2001 From: Anselm R Garbe Date: Fri, 15 Feb 2008 16:00:02 +0000 Subject: [PATCH 02/16] some drawbar() polishing, and certain related fixes --- dwm.c | 54 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/dwm.c b/dwm.c index f992ea9..9f1b1f4 100644 --- a/dwm.c +++ b/dwm.c @@ -164,9 +164,9 @@ void grabbuttons(Client *c, Bool focused); void grabkeys(void); unsigned int idxoftag(const char *tag); void initfont(Monitor*, const char *fontstr); -Bool isoccupied(Monitor *m, unsigned int t); +Bool isoccupied(unsigned int monitor, unsigned int t); Bool isprotodel(Client *c); -Bool isurgent(int monitor, unsigned int t); +Bool isurgent(unsigned int monitor, unsigned int t); Bool isvisible(Client *c, int monitor); void keypress(XEvent *e); void killclient(const char *arg); @@ -562,39 +562,46 @@ detachstack(Client *c) { void drawbar(void) { int i, j, x; + Client *c; for(i = 0; i < mcount; i++) { Monitor *m = &monitors[i]; m->dc.x = 0; + for(c = stack; c && !isvisible(c, i); c = c->snext); + fprintf(stderr, "m%d %s\n", i, c ? c->name : "NIL"); for(j = 0; j < LENGTH(tags); j++) { m->dc.w = textw(m, tags[j]); if(m->seltags[j]) { drawtext(m, tags[j], m->dc.sel, isurgent(i, j)); - drawsquare(m, sel && sel->tags[j] && sel->monitor == selmonitor, - isoccupied(m, j), isurgent(i, j), m->dc.sel); + drawsquare(m, c && c->tags[j] && c->monitor == i, + isoccupied(i, j), isurgent(i, j), m->dc.sel); } else { drawtext(m, tags[j], m->dc.norm, isurgent(i, j)); - drawsquare(m, sel && sel->tags[j] && sel->monitor == selmonitor, - isoccupied(m, j), isurgent(i, j), m->dc.norm); + drawsquare(m, c && c->tags[j] && c->monitor == i, + isoccupied(i, j), isurgent(i, j), m->dc.norm); } m->dc.x += m->dc.w; } m->dc.w = blw; drawtext(m, m->layout->symbol, m->dc.norm, False); x = m->dc.x + m->dc.w; - m->dc.w = textw(m, stext); - m->dc.x = m->sw - m->dc.w; - if(m->dc.x < x) { - m->dc.x = x; - m->dc.w = m->sw - x; + if(i == selmonitor) { + m->dc.w = textw(m, stext); + m->dc.x = m->sw - m->dc.w; + if(m->dc.x < x) { + m->dc.x = x; + m->dc.w = m->sw - x; + } + drawtext(m, stext, m->dc.norm, False); } - drawtext(m, stext, m->dc.norm, False); + else + m->dc.x = m->sw; if((m->dc.w = m->dc.x - x) > bh) { m->dc.x = x; - if(sel && sel->monitor == selmonitor) { - drawtext(m, sel->name, m->dc.sel, False); - drawsquare(m, False, sel->isfloating, False, m->dc.sel); + if(c) { + drawtext(m, c->name, m->dc.sel, False); + drawsquare(m, False, c->isfloating, False, m->dc.sel); } else drawtext(m, NULL, m->dc.norm, False); @@ -679,8 +686,10 @@ enternotify(XEvent *e) { Client *c; XCrossingEvent *ev = &e->xcrossing; - if(ev->mode != NotifyNormal || ev->detail == NotifyInferior); - //return; + if(ev->mode != NotifyNormal || ev->detail == NotifyInferior) { + if(!isxinerama || ev->window != monitors[selmonitor].root) + return; + } if((c = getclient(ev->window))) focus(c); else { @@ -747,6 +756,7 @@ focus(Client *c) { } else { XSetInputFocus(dpy, m->root, RevertToPointerRoot, CurrentTime); + drawbar(); } } @@ -972,11 +982,11 @@ initfont(Monitor *m, const char *fontstr) { } Bool -isoccupied(Monitor *m, unsigned int t) { +isoccupied(unsigned int monitor, unsigned int t) { Client *c; for(c = clients; c; c = c->next) - if(c->tags[t] && c->monitor == selmonitor) + if(c->tags[t] && c->monitor == monitor) return True; return False; } @@ -997,7 +1007,7 @@ isprotodel(Client *c) { } Bool -isurgent(int monitor, unsigned int t) { +isurgent(unsigned int monitor, unsigned int t) { Client *c; for(c = clients; c; c = c->next) @@ -1010,8 +1020,10 @@ Bool isvisible(Client *c, int monitor) { unsigned int i; + if(c->monitor != monitor) + return False; for(i = 0; i < LENGTH(tags); i++) - if(c->tags[i] && monitors[c->monitor].seltags[i] && c->monitor == monitor) + if(c->tags[i] && monitors[c->monitor].seltags[i]) return True; return False; } -- 2.20.1 From 191cb9ce283090c48f17c9518a9b6a553085c8e4 Mon Sep 17 00:00:00 2001 From: Anselm R Garbe Date: Mon, 18 Feb 2008 16:47:16 +0000 Subject: [PATCH 03/16] removed Monitor->root, since we do not support classical multihead --- dwm.c | 103 ++++++++++++++++++++++++++++------------------------------ 1 file changed, 49 insertions(+), 54 deletions(-) diff --git a/dwm.c b/dwm.c index 9f1b1f4..b0c218e 100644 --- a/dwm.c +++ b/dwm.c @@ -118,7 +118,6 @@ typedef struct { typedef struct { int screen; - Window root; Window barwin; int sx, sy, sw, sh, wax, way, wah, waw; DC dc; @@ -216,6 +215,7 @@ void selectmonitor(const char *arg); /* variables */ char stext[256]; int mcount = 1; +int selmonitor = 0; int (*xerrorxlib)(Display *, XErrorEvent *); unsigned int bh, bpos; unsigned int blw = 0; @@ -248,7 +248,7 @@ Display *dpy; DC dc = {0}; Regs *regs = NULL; Monitor *monitors; -int selmonitor = 0; +Window root; /* configuration, allows nested code to access above variables */ #include "config.h" @@ -414,7 +414,7 @@ cleanup(void) { XFreeFontSet(dpy, m->dc.font.set); else XFreeFont(dpy, m->dc.font.xfont); - XUngrabKey(dpy, AnyKey, AnyModifier, m->root); + XUngrabKey(dpy, AnyKey, AnyModifier, root); XFreePixmap(dpy, m->dc.drawable); XFreeGC(dpy, m->dc.gc); XDestroyWindow(dpy, m->barwin); @@ -475,11 +475,11 @@ configurenotify(XEvent *e) { XConfigureEvent *ev = &e->xconfigure; Monitor *m = &monitors[selmonitor]; - if(ev->window == m->root && (ev->width != m->sw || ev->height != m->sh)) { + if(ev->window == root && (ev->width != m->sw || ev->height != m->sh)) { m->sw = ev->width; m->sh = ev->height; XFreePixmap(dpy, dc.drawable); - dc.drawable = XCreatePixmap(dpy, m->root, m->sw, bh, DefaultDepth(dpy, m->screen)); + dc.drawable = XCreatePixmap(dpy, root, m->sw, bh, DefaultDepth(dpy, m->screen)); XResizeWindow(dpy, m->barwin, m->sw, bh); updatebarpos(m); arrange(); @@ -687,7 +687,7 @@ enternotify(XEvent *e) { XCrossingEvent *ev = &e->xcrossing; if(ev->mode != NotifyNormal || ev->detail == NotifyInferior) { - if(!isxinerama || ev->window != monitors[selmonitor].root) + if(!isxinerama || ev->window != root) return; } if((c = getclient(ev->window))) @@ -755,7 +755,7 @@ focus(Client *c) { selmonitor = c->monitor; } else { - XSetInputFocus(dpy, m->root, RevertToPointerRoot, CurrentTime); + XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); drawbar(); } } @@ -914,20 +914,17 @@ grabkeys(void) { } XFreeModifiermap(modmap); - for(i = 0; i < mcount; i++) { - Monitor *m = &monitors[i]; - XUngrabKey(dpy, AnyKey, AnyModifier, m->root); - for(j = 0; j < LENGTH(keys); j++) { - code = XKeysymToKeycode(dpy, keys[j].keysym); - XGrabKey(dpy, code, keys[j].mod, m->root, True, - GrabModeAsync, GrabModeAsync); - XGrabKey(dpy, code, keys[j].mod | LockMask, m->root, True, - GrabModeAsync, GrabModeAsync); - XGrabKey(dpy, code, keys[j].mod | numlockmask, m->root, True, - GrabModeAsync, GrabModeAsync); - XGrabKey(dpy, code, keys[j].mod | numlockmask | LockMask, m->root, True, - GrabModeAsync, GrabModeAsync); - } + XUngrabKey(dpy, AnyKey, AnyModifier, root); + for(i = 0; i < LENGTH(keys); i++) { + code = XKeysymToKeycode(dpy, keys[i].keysym); + XGrabKey(dpy, code, keys[i].mod, root, True, + GrabModeAsync, GrabModeAsync); + XGrabKey(dpy, code, keys[i].mod | LockMask, root, True, + GrabModeAsync, GrabModeAsync); + XGrabKey(dpy, code, keys[i].mod | numlockmask, root, True, + GrabModeAsync, GrabModeAsync); + XGrabKey(dpy, code, keys[i].mod | numlockmask | LockMask, root, True, + GrabModeAsync, GrabModeAsync); } } @@ -1153,7 +1150,7 @@ monitorat() { Window win; unsigned int mask; - XQueryPointer(dpy, monitors[selmonitor].root, &win, &win, &x, &y, &i, &i, &mask); + XQueryPointer(dpy, root, &win, &win, &x, &y, &i, &i, &mask); for(i = 0; i < mcount; i++) { if((x >= monitors[i].sx && x < monitors[i].sx + monitors[i].sw) && (y >= monitors[i].sy && y < monitors[i].sy + monitors[i].sh)) { @@ -1172,10 +1169,10 @@ movemouse(Client *c) { ocx = nx = c->x; ocy = ny = c->y; - if(XGrabPointer(dpy, monitors[selmonitor].root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, + if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, None, cursor[CurMove], CurrentTime) != GrabSuccess) return; - XQueryPointer(dpy, monitors[selmonitor].root, &dummy, &dummy, &x1, &y1, &di, &di, &dui); + XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui); for(;;) { XMaskEvent(dpy, MOUSEMASK | ExposureMask | SubstructureRedirectMask, &ev); switch (ev.type) { @@ -1342,7 +1339,7 @@ resizemouse(Client *c) { ocx = c->x; ocy = c->y; - if(XGrabPointer(dpy, monitors[selmonitor].root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, + if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, None, cursor[CurResize], CurrentTime) != GrabSuccess) return; XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->border - 1, c->h + c->border - 1); @@ -1469,32 +1466,29 @@ run(void) { void scan(void) { - unsigned int i, j, num; + unsigned int i, num; Window *wins, d1, d2; XWindowAttributes wa; - for(i = 0; i < mcount; i++) { - Monitor *m = &monitors[i]; - wins = NULL; - if(XQueryTree(dpy, m->root, &d1, &d2, &wins, &num)) { - for(j = 0; j < num; j++) { - if(!XGetWindowAttributes(dpy, wins[j], &wa) - || wa.override_redirect || XGetTransientForHint(dpy, wins[j], &d1)) - continue; - if(wa.map_state == IsViewable || getstate(wins[j]) == IconicState) - manage(wins[j], &wa); - } - for(j = 0; j < num; j++) { /* now the transients */ - if(!XGetWindowAttributes(dpy, wins[j], &wa)) - continue; - if(XGetTransientForHint(dpy, wins[j], &d1) - && (wa.map_state == IsViewable || getstate(wins[j]) == IconicState)) - manage(wins[j], &wa); - } + wins = NULL; + if(XQueryTree(dpy, root, &d1, &d2, &wins, &num)) { + for(i = 0; i < num; i++) { + if(!XGetWindowAttributes(dpy, wins[i], &wa) + || wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1)) + continue; + if(wa.map_state == IsViewable || getstate(wins[i]) == IconicState) + manage(wins[i], &wa); + } + for(i = 0; i < num; i++) { /* now the transients */ + if(!XGetWindowAttributes(dpy, wins[i], &wa)) + continue; + if(XGetTransientForHint(dpy, wins[i], &d1) + && (wa.map_state == IsViewable || getstate(wins[i]) == IconicState)) + manage(wins[i], &wa); } - if(wins) - XFree(wins); } + if(wins) + XFree(wins); } void @@ -1579,12 +1573,13 @@ setup(void) { info = XineramaQueryScreens(dpy, &mcount); monitors = emallocz(mcount * sizeof(Monitor)); + root = DefaultRootWindow(dpy); + for(i = 0; i < mcount; i++) { /* init geometry */ m = &monitors[i]; m->screen = isxinerama ? 0 : i; - m->root = RootWindow(dpy, m->screen); if (mcount != 1 && isxinerama) { m->sx = info[i].x_org; @@ -1632,28 +1627,28 @@ setup(void) { wa.event_mask = ButtonPressMask | ExposureMask; /* init bars */ - m->barwin = XCreateWindow(dpy, m->root, m->sx, m->sy, m->sw, bh, 0, + m->barwin = XCreateWindow(dpy, root, m->sx, m->sy, m->sw, bh, 0, DefaultDepth(dpy, m->screen), CopyFromParent, DefaultVisual(dpy, m->screen), CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); XDefineCursor(dpy, m->barwin, cursor[CurNormal]); updatebarpos(m); XMapRaised(dpy, m->barwin); strcpy(stext, "dwm-"VERSION); - m->dc.drawable = XCreatePixmap(dpy, m->root, m->sw, bh, DefaultDepth(dpy, m->screen)); - m->dc.gc = XCreateGC(dpy, m->root, 0, 0); + m->dc.drawable = XCreatePixmap(dpy, root, m->sw, bh, DefaultDepth(dpy, m->screen)); + m->dc.gc = XCreateGC(dpy, root, 0, 0); XSetLineAttributes(dpy, m->dc.gc, 1, LineSolid, CapButt, JoinMiter); if(!m->dc.font.set) XSetFont(dpy, m->dc.gc, m->dc.font.xfont->fid); /* EWMH support per monitor */ - XChangeProperty(dpy, m->root, netatom[NetSupported], XA_ATOM, 32, + XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32, PropModeReplace, (unsigned char *) netatom, NetLast); /* select for events */ wa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask | EnterWindowMask | LeaveWindowMask | StructureNotifyMask; - XChangeWindowAttributes(dpy, m->root, CWEventMask | CWCursor, &wa); - XSelectInput(dpy, m->root, wa.event_mask); + XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); + XSelectInput(dpy, root, wa.event_mask); } if(info) XFree(info); @@ -2044,7 +2039,7 @@ void selectmonitor(const char *arg) { Monitor *m = &monitors[arg ? atoi(arg) : (monitorat()+1) % mcount]; - XWarpPointer(dpy, None, m->root, 0, 0, 0, 0, m->wax+m->waw/2, m->way+m->wah/2); + XWarpPointer(dpy, None, root, 0, 0, 0, 0, m->wax+m->waw/2, m->way+m->wah/2); focus(NULL); } -- 2.20.1 From c2737b7b9317743e3430c71bc0a9afcc6b0f70f7 Mon Sep 17 00:00:00 2001 From: Anselm R Garbe Date: Mon, 18 Feb 2008 17:08:22 +0000 Subject: [PATCH 04/16] removed Monitor->dc, unnecessary --- dwm.c | 249 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 125 insertions(+), 124 deletions(-) diff --git a/dwm.c b/dwm.c index b0c218e..11f2293 100644 --- a/dwm.c +++ b/dwm.c @@ -117,10 +117,9 @@ typedef struct { } Regs; typedef struct { - int screen; + int monitor; Window barwin; int sx, sy, sw, sh, wax, way, wah, waw; - DC dc; Bool *seltags; Bool *prevtags; Layout *layout; @@ -156,13 +155,13 @@ void focusin(XEvent *e); void focusnext(const char *arg); void focusprev(const char *arg); Client *getclient(Window w); -unsigned long getcolor(const char *colstr, int screen); +unsigned long getcolor(const char *colstr); long getstate(Window w); Bool gettextprop(Window w, Atom atom, char *text, unsigned int size); void grabbuttons(Client *c, Bool focused); void grabkeys(void); unsigned int idxoftag(const char *tag); -void initfont(Monitor*, const char *fontstr); +void initfont(const char *fontstr); Bool isoccupied(unsigned int monitor, unsigned int t); Bool isprotodel(Client *c); Bool isurgent(unsigned int monitor, unsigned int t); @@ -188,8 +187,8 @@ void setmwfact(const char *arg); void setup(void); void spawn(const char *arg); void tag(const char *arg); -unsigned int textnw(Monitor*, const char *text, unsigned int len); -unsigned int textw(Monitor*, const char *text); +unsigned int textnw(const char *text, unsigned int len); +unsigned int textw(const char *text); void tile(void); void togglebar(const char *arg); void togglefloating(const char *arg); @@ -216,6 +215,7 @@ void selectmonitor(const char *arg); char stext[256]; int mcount = 1; int selmonitor = 0; +int screen; int (*xerrorxlib)(Display *, XErrorEvent *); unsigned int bh, bpos; unsigned int blw = 0; @@ -343,7 +343,7 @@ buttonpress(XEvent *e) { if(ev->window == m->barwin) { x = 0; for(i = 0; i < LENGTH(tags); i++) { - x += textw(m, tags[i]); + x += textw(tags[i]); if(ev->x < x) { if(ev->button == Button1) { if(ev->state & MODKEY) @@ -408,22 +408,21 @@ cleanup(void) { unban(stack); unmanage(stack); } - for(i = 0; i < mcount; i++) { - Monitor *m = &monitors[i]; - if(m->dc.font.set) - XFreeFontSet(dpy, m->dc.font.set); - else - XFreeFont(dpy, m->dc.font.xfont); - XUngrabKey(dpy, AnyKey, AnyModifier, root); - XFreePixmap(dpy, m->dc.drawable); - XFreeGC(dpy, m->dc.gc); - XDestroyWindow(dpy, m->barwin); - XFreeCursor(dpy, cursor[CurNormal]); - XFreeCursor(dpy, cursor[CurResize]); - XFreeCursor(dpy, cursor[CurMove]); - XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); - XSync(dpy, False); - } + if(dc.font.set) + XFreeFontSet(dpy, dc.font.set); + else + XFreeFont(dpy, dc.font.xfont); + + XUngrabKey(dpy, AnyKey, AnyModifier, root); + XFreePixmap(dpy, dc.drawable); + XFreeGC(dpy, dc.gc); + XFreeCursor(dpy, cursor[CurNormal]); + XFreeCursor(dpy, cursor[CurResize]); + XFreeCursor(dpy, cursor[CurMove]); + for(i = 0; i < mcount; i++) + XDestroyWindow(dpy, monitors[i].barwin); + XSync(dpy, False); + XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); } void @@ -476,10 +475,11 @@ configurenotify(XEvent *e) { Monitor *m = &monitors[selmonitor]; if(ev->window == root && (ev->width != m->sw || ev->height != m->sh)) { + /* TODO -- update Xinerama dimensions here */ m->sw = ev->width; m->sh = ev->height; XFreePixmap(dpy, dc.drawable); - dc.drawable = XCreatePixmap(dpy, root, m->sw, bh, DefaultDepth(dpy, m->screen)); + dc.drawable = XCreatePixmap(dpy, root, DisplayWidth(root, screen), bh, DefaultDepth(dpy, screen)); XResizeWindow(dpy, m->barwin, m->sw, bh); updatebarpos(m); arrange(); @@ -566,47 +566,47 @@ drawbar(void) { for(i = 0; i < mcount; i++) { Monitor *m = &monitors[i]; - m->dc.x = 0; + dc.x = 0; for(c = stack; c && !isvisible(c, i); c = c->snext); fprintf(stderr, "m%d %s\n", i, c ? c->name : "NIL"); for(j = 0; j < LENGTH(tags); j++) { - m->dc.w = textw(m, tags[j]); + dc.w = textw(tags[j]); if(m->seltags[j]) { - drawtext(m, tags[j], m->dc.sel, isurgent(i, j)); + drawtext(m, tags[j], dc.sel, isurgent(i, j)); drawsquare(m, c && c->tags[j] && c->monitor == i, - isoccupied(i, j), isurgent(i, j), m->dc.sel); + isoccupied(i, j), isurgent(i, j), dc.sel); } else { - drawtext(m, tags[j], m->dc.norm, isurgent(i, j)); + drawtext(m, tags[j], dc.norm, isurgent(i, j)); drawsquare(m, c && c->tags[j] && c->monitor == i, - isoccupied(i, j), isurgent(i, j), m->dc.norm); + isoccupied(i, j), isurgent(i, j), dc.norm); } - m->dc.x += m->dc.w; + dc.x += dc.w; } - m->dc.w = blw; - drawtext(m, m->layout->symbol, m->dc.norm, False); - x = m->dc.x + m->dc.w; + dc.w = blw; + drawtext(m, m->layout->symbol, dc.norm, False); + x = dc.x + dc.w; if(i == selmonitor) { - m->dc.w = textw(m, stext); - m->dc.x = m->sw - m->dc.w; - if(m->dc.x < x) { - m->dc.x = x; - m->dc.w = m->sw - x; + dc.w = textw(stext); + dc.x = m->sw - dc.w; + if(dc.x < x) { + dc.x = x; + dc.w = m->sw - x; } - drawtext(m, stext, m->dc.norm, False); + drawtext(m, stext, dc.norm, False); } else - m->dc.x = m->sw; - if((m->dc.w = m->dc.x - x) > bh) { - m->dc.x = x; + dc.x = m->sw; + if((dc.w = dc.x - x) > bh) { + dc.x = x; if(c) { - drawtext(m, c->name, m->dc.sel, False); - drawsquare(m, False, c->isfloating, False, m->dc.sel); + drawtext(m, c->name, dc.sel, False); + drawsquare(m, False, c->isfloating, False, dc.sel); } else - drawtext(m, NULL, m->dc.norm, False); + drawtext(m, NULL, dc.norm, False); } - XCopyArea(dpy, m->dc.drawable, m->barwin, m->dc.gc, 0, 0, m->sw, bh, 0, 0); + XCopyArea(dpy, dc.drawable, m->barwin, dc.gc, 0, 0, m->sw, bh, 0, 0); XSync(dpy, False); } } @@ -615,20 +615,20 @@ void drawsquare(Monitor *m, Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]) { int x; XGCValues gcv; - XRectangle r = { m->dc.x, m->dc.y, m->dc.w, m->dc.h }; + XRectangle r = { dc.x, dc.y, dc.w, dc.h }; gcv.foreground = col[invert ? ColBG : ColFG]; - XChangeGC(dpy, m->dc.gc, GCForeground, &gcv); - x = (m->dc.font.ascent + m->dc.font.descent + 2) / 4; - r.x = m->dc.x + 1; - r.y = m->dc.y + 1; + XChangeGC(dpy, dc.gc, GCForeground, &gcv); + x = (dc.font.ascent + dc.font.descent + 2) / 4; + r.x = dc.x + 1; + r.y = dc.y + 1; if(filled) { r.width = r.height = x + 1; - XFillRectangles(dpy, m->dc.drawable, m->dc.gc, &r, 1); + XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); } else if(empty) { r.width = r.height = x; - XDrawRectangles(dpy, m->dc.drawable, m->dc.gc, &r, 1); + XDrawRectangles(dpy, dc.drawable, dc.gc, &r, 1); } } @@ -637,10 +637,10 @@ drawtext(Monitor *m, const char *text, unsigned long col[ColLast], Bool invert) int x, y, w, h; static char buf[256]; unsigned int len, olen; - XRectangle r = { m->dc.x, m->dc.y, m->dc.w, m->dc.h }; + XRectangle r = { dc.x, dc.y, dc.w, dc.h }; - XSetForeground(dpy, m->dc.gc, col[invert ? ColFG : ColBG]); - XFillRectangles(dpy, m->dc.drawable, m->dc.gc, &r, 1); + XSetForeground(dpy, dc.gc, col[invert ? ColFG : ColBG]); + XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); if(!text) return; w = 0; @@ -649,11 +649,11 @@ drawtext(Monitor *m, const char *text, unsigned long col[ColLast], Bool invert) len = sizeof buf - 1; memcpy(buf, text, len); buf[len] = 0; - h = m->dc.font.ascent + m->dc.font.descent; - y = m->dc.y + (m->dc.h / 2) - (h / 2) + m->dc.font.ascent; - x = m->dc.x + (h / 2); + h = dc.font.ascent + dc.font.descent; + y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent; + x = dc.x + (h / 2); /* shorten text if necessary */ - while(len && (w = textnw(m, buf, len)) > m->dc.w - h) + while(len && (w = textnw(buf, len)) > dc.w - h) buf[--len] = 0; if(len < olen) { if(len > 1) @@ -663,13 +663,13 @@ drawtext(Monitor *m, const char *text, unsigned long col[ColLast], Bool invert) if(len > 3) buf[len - 3] = '.'; } - if(w > m->dc.w) + if(w > dc.w) return; /* too long */ - XSetForeground(dpy, m->dc.gc, col[invert ? ColBG : ColFG]); - if(m->dc.font.set) - XmbDrawString(dpy, m->dc.drawable, m->dc.font.set, m->dc.gc, x, y, buf, len); + XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]); + if(dc.font.set) + XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len); else - XDrawString(dpy, m->dc.drawable, m->dc.gc, x, y, buf, len); + XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len); } void * @@ -740,7 +740,7 @@ focus(Client *c) { for(c = stack; c && !isvisible(c, c->monitor); c = c->snext); if(sel && sel != c) { grabbuttons(sel, False); - XSetWindowBorder(dpy, sel->win, monitors[sel->monitor].dc.norm[ColBorder]); + XSetWindowBorder(dpy, sel->win, dc.norm[ColBorder]); } if(c) { detachstack(c); @@ -750,7 +750,7 @@ focus(Client *c) { sel = c; drawbar(); if(c) { - XSetWindowBorder(dpy, c->win, m->dc.sel[ColBorder]); + XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]); XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); selmonitor = c->monitor; } @@ -809,7 +809,7 @@ getclient(Window w) { } unsigned long -getcolor(const char *colstr, int screen) { +getcolor(const char *colstr) { Colormap cmap = DefaultColormap(dpy, screen); XColor color; @@ -937,45 +937,45 @@ idxoftag(const char *tag) { } void -initfont(Monitor *m, const char *fontstr) { +initfont(const char *fontstr) { char *def, **missing; int i, n; missing = NULL; - if(m->dc.font.set) - XFreeFontSet(dpy, m->dc.font.set); - m->dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def); + if(dc.font.set) + XFreeFontSet(dpy, dc.font.set); + dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def); if(missing) { while(n--) fprintf(stderr, "dwm: missing fontset: %s\n", missing[n]); XFreeStringList(missing); } - if(m->dc.font.set) { + if(dc.font.set) { XFontSetExtents *font_extents; XFontStruct **xfonts; char **font_names; - m->dc.font.ascent = m->dc.font.descent = 0; - font_extents = XExtentsOfFontSet(m->dc.font.set); - n = XFontsOfFontSet(m->dc.font.set, &xfonts, &font_names); - for(i = 0, m->dc.font.ascent = 0, m->dc.font.descent = 0; i < n; i++) { - if(m->dc.font.ascent < (*xfonts)->ascent) - m->dc.font.ascent = (*xfonts)->ascent; - if(m->dc.font.descent < (*xfonts)->descent) - m->dc.font.descent = (*xfonts)->descent; + dc.font.ascent = dc.font.descent = 0; + font_extents = XExtentsOfFontSet(dc.font.set); + n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names); + for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) { + if(dc.font.ascent < (*xfonts)->ascent) + dc.font.ascent = (*xfonts)->ascent; + if(dc.font.descent < (*xfonts)->descent) + dc.font.descent = (*xfonts)->descent; xfonts++; } } else { - if(m->dc.font.xfont) - XFreeFont(dpy, m->dc.font.xfont); - m->dc.font.xfont = NULL; - if(!(m->dc.font.xfont = XLoadQueryFont(dpy, fontstr)) - && !(m->dc.font.xfont = XLoadQueryFont(dpy, "fixed"))) + if(dc.font.xfont) + XFreeFont(dpy, dc.font.xfont); + dc.font.xfont = NULL; + if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr)) + && !(dc.font.xfont = XLoadQueryFont(dpy, "fixed"))) eprint("error, cannot load font: '%s'\n", fontstr); - m->dc.font.ascent = m->dc.font.xfont->ascent; - m->dc.font.descent = m->dc.font.xfont->descent; + dc.font.ascent = dc.font.xfont->ascent; + dc.font.descent = dc.font.xfont->descent; } - m->dc.font.height = m->dc.font.ascent + m->dc.font.descent; + dc.font.height = dc.font.ascent + dc.font.descent; } Bool @@ -1101,7 +1101,7 @@ manage(Window w, XWindowAttributes *wa) { } wc.border_width = c->border; XConfigureWindow(dpy, w, CWBorderWidth, &wc); - XSetWindowBorder(dpy, w, m->dc.norm[ColBorder]); + XSetWindowBorder(dpy, w, dc.norm[ColBorder]); configure(c); /* propagates border_width, if size doesn't change */ updatesizehints(c); XSelectInput(dpy, w, EnterWindowMask | FocusChangeMask | PropertyChangeMask | StructureNotifyMask); @@ -1549,7 +1549,7 @@ setmwfact(const char *arg) { void setup(void) { - unsigned int i, j, k; + unsigned int i; Monitor *m; XSetWindowAttributes wa; XineramaScreenInfo *info = NULL; @@ -1573,13 +1573,34 @@ setup(void) { info = XineramaQueryScreens(dpy, &mcount); monitors = emallocz(mcount * sizeof(Monitor)); - root = DefaultRootWindow(dpy); - + screen = DefaultScreen(dpy); + root = RootWindow(dpy, screen); + + /* init appearance */ + dc.norm[ColBorder] = getcolor(NORMBORDERCOLOR); + dc.norm[ColBG] = getcolor(NORMBGCOLOR); + dc.norm[ColFG] = getcolor(NORMFGCOLOR); + dc.sel[ColBorder] = getcolor(SELBORDERCOLOR); + dc.sel[ColBG] = getcolor(SELBGCOLOR); + dc.sel[ColFG] = getcolor(SELFGCOLOR); + initfont(FONT); + dc.h = bh = dc.font.height + 2; + dc.drawable = XCreatePixmap(dpy, root, DisplayWidth(dpy, screen), bh, DefaultDepth(dpy, screen)); + dc.gc = XCreateGC(dpy, root, 0, 0); + XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter); + if(!dc.font.set) + XSetFont(dpy, dc.gc, dc.font.xfont->fid); + + for(blw = i = 0; i < LENGTH(layouts); i++) { + i = textw(layouts[i].symbol); + if(i > blw) + blw = i; + } for(i = 0; i < mcount; i++) { /* init geometry */ m = &monitors[i]; - m->screen = isxinerama ? 0 : i; + m->monitor = i; if (mcount != 1 && isxinerama) { m->sx = info[i].x_org; @@ -1591,8 +1612,8 @@ setup(void) { else { m->sx = 0; m->sy = 0; - m->sw = DisplayWidth(dpy, m->screen); - m->sh = DisplayHeight(dpy, m->screen); + m->sw = DisplayWidth(dpy, screen); + m->sh = DisplayHeight(dpy, screen); } m->seltags = emallocz(sizeof initags); @@ -1601,24 +1622,9 @@ setup(void) { memcpy(m->seltags, initags, sizeof initags); memcpy(m->prevtags, initags, sizeof initags); - /* init appearance */ - m->dc.norm[ColBorder] = getcolor(NORMBORDERCOLOR, m->screen); - m->dc.norm[ColBG] = getcolor(NORMBGCOLOR, m->screen); - m->dc.norm[ColFG] = getcolor(NORMFGCOLOR, m->screen); - m->dc.sel[ColBorder] = getcolor(SELBORDERCOLOR, m->screen); - m->dc.sel[ColBG] = getcolor(SELBGCOLOR, m->screen); - m->dc.sel[ColFG] = getcolor(SELFGCOLOR, m->screen); - initfont(m, FONT); - m->dc.h = bh = m->dc.font.height + 2; - /* init layouts */ m->mwfact = MWFACT; m->layout = &layouts[0]; - for(blw = k = 0; k < LENGTH(layouts); k++) { - j = textw(m, layouts[k].symbol); - if(j > blw) - blw = j; - } // TODO: bpos per screen? bpos = BARPOS; @@ -1628,17 +1634,12 @@ setup(void) { /* init bars */ m->barwin = XCreateWindow(dpy, root, m->sx, m->sy, m->sw, bh, 0, - DefaultDepth(dpy, m->screen), CopyFromParent, DefaultVisual(dpy, m->screen), + DefaultDepth(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen), CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); XDefineCursor(dpy, m->barwin, cursor[CurNormal]); updatebarpos(m); XMapRaised(dpy, m->barwin); strcpy(stext, "dwm-"VERSION); - m->dc.drawable = XCreatePixmap(dpy, root, m->sw, bh, DefaultDepth(dpy, m->screen)); - m->dc.gc = XCreateGC(dpy, root, 0, 0); - XSetLineAttributes(dpy, m->dc.gc, 1, LineSolid, CapButt, JoinMiter); - if(!m->dc.font.set) - XSetFont(dpy, m->dc.gc, m->dc.font.xfont->fid); /* EWMH support per monitor */ XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32, @@ -1700,19 +1701,19 @@ tag(const char *arg) { } unsigned int -textnw(Monitor *m, const char *text, unsigned int len) { +textnw(const char *text, unsigned int len) { XRectangle r; - if(m->dc.font.set) { - XmbTextExtents(m->dc.font.set, text, len, NULL, &r); + if(dc.font.set) { + XmbTextExtents(dc.font.set, text, len, NULL, &r); return r.width; } - return XTextWidth(m->dc.font.xfont, text, len); + return XTextWidth(dc.font.xfont, text, len); } unsigned int -textw(Monitor *m, const char *text) { - return textnw(m, text, strlen(text)) + m->dc.font.height; +textw(const char *text) { + return textnw(text, strlen(text)) + dc.font.height; } void -- 2.20.1 From ca3e847e459e1ba43f45513877d39d50cce7a0c5 Mon Sep 17 00:00:00 2001 From: Anselm R Garbe Date: Wed, 20 Feb 2008 08:09:26 +0000 Subject: [PATCH 05/16] applied some necessary changes --- dwm.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/dwm.c b/dwm.c index 11f2293..0a1ade2 100644 --- a/dwm.c +++ b/dwm.c @@ -117,7 +117,6 @@ typedef struct { } Regs; typedef struct { - int monitor; Window barwin; int sx, sy, sw, sh, wax, way, wah, waw; Bool *seltags; @@ -1164,11 +1163,13 @@ void movemouse(Client *c) { int x1, y1, ocx, ocy, di, nx, ny; unsigned int dui; + Monitor *m; Window dummy; XEvent ev; ocx = nx = c->x; ocy = ny = c->y; + m = &monitors[c->monitor]; if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, None, cursor[CurMove], CurrentTime) != GrabSuccess) return; @@ -1188,7 +1189,6 @@ movemouse(Client *c) { XSync(dpy, False); nx = ocx + (ev.xmotion.x - x1); ny = ocy + (ev.xmotion.y - y1); - Monitor *m = &monitors[monitorat()]; if(abs(m->wax - nx) < SNAP) nx = m->wax; else if(abs((m->wax + m->waw) - (nx + c->w + 2 * c->border)) < SNAP) @@ -1197,11 +1197,10 @@ movemouse(Client *c) { ny = m->way; else if(abs((m->way + m->wah) - (ny + c->h + 2 * c->border)) < SNAP) ny = m->way + m->wah - c->h - 2 * c->border; - if((monitors[selmonitor].layout->arrange != floating) && (abs(nx - c->x) > SNAP || abs(ny - c->y) > SNAP)) + if((m->layout->arrange != floating) && (abs(nx - c->x) > SNAP || abs(ny - c->y) > SNAP)) togglefloating(NULL); - if((monitors[selmonitor].layout->arrange == floating) || c->isfloating) + if((m->layout->arrange == floating) || c->isfloating) resize(c, nx, ny, c->w, c->h, False); - memcpy(c->tags, monitors[monitorat()].seltags, sizeof initags); break; } } @@ -1335,10 +1334,12 @@ void resizemouse(Client *c) { int ocx, ocy; int nw, nh; + Monitor *m; XEvent ev; ocx = c->x; ocy = c->y; + m = &monitors[c->monitor]; if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, None, cursor[CurResize], CurrentTime) != GrabSuccess) return; @@ -1363,9 +1364,9 @@ resizemouse(Client *c) { nw = 1; if((nh = ev.xmotion.y - ocy - 2 * c->border + 1) <= 0) nh = 1; - if((monitors[selmonitor].layout->arrange != floating) && (abs(nw - c->w) > SNAP || abs(nh - c->h) > SNAP)) + if((m->layout->arrange != floating) && (abs(nw - c->w) > SNAP || abs(nh - c->h) > SNAP)) togglefloating(NULL); - if((monitors[selmonitor].layout->arrange == floating) || c->isfloating) + if((m->layout->arrange == floating) || c->isfloating) resize(c, c->x, c->y, nw, nh, True); break; } @@ -1600,8 +1601,6 @@ setup(void) { /* init geometry */ m = &monitors[i]; - m->monitor = i; - if (mcount != 1 && isxinerama) { m->sx = info[i].x_org; m->sy = info[i].y_org; -- 2.20.1 From e0f039789643381485dab5c467f66db5162d4f63 Mon Sep 17 00:00:00 2001 From: Anselm R Garbe Date: Wed, 20 Feb 2008 08:13:41 +0000 Subject: [PATCH 06/16] resize handles offscreen issues --- dwm.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/dwm.c b/dwm.c index 0a1ade2..363c202 100644 --- a/dwm.c +++ b/dwm.c @@ -1263,9 +1263,10 @@ reapply(const char *arg) { void resize(Client *c, int x, int y, int w, int h, Bool sizehints) { + Monitor *m; XWindowChanges wc; - //Monitor scr = monitors[monitorat()]; -// c->monitor = monitorat(); + + m = &monitors[c->monitor]; if(sizehints) { /* set minimum possible */ @@ -1307,17 +1308,14 @@ resize(Client *c, int x, int y, int w, int h, Bool sizehints) { } if(w <= 0 || h <= 0) return; - /* TODO: offscreen appearance fixes */ - /* - if(x > scr.sw) - x = scr.sw - w - 2 * c->border; - if(y > scr.sh) - y = scr.sh - h - 2 * c->border; - if(x + w + 2 * c->border < scr.sx) - x = scr.sx; - if(y + h + 2 * c->border < scr.sy) - y = scr.sy; - */ + if(x > m->sw) + x = m->sw - w - 2 * c->border; + if(y > m->sh) + y = m->sh - h - 2 * c->border; + if(x + w + 2 * c->border < m->sx) + x = m->sx; + if(y + h + 2 * c->border < m->sy) + y = m->sy; if(c->x != x || c->y != y || c->w != w || c->h != h) { c->x = wc.x = x; c->y = wc.y = y; -- 2.20.1 From 4426032450777e63ac9a8967cd67382497954c51 Mon Sep 17 00:00:00 2001 From: Anselm R Garbe Date: Wed, 20 Feb 2008 13:48:52 +0000 Subject: [PATCH 07/16] applied Jukka's zoom-patch --- dwm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dwm.c b/dwm.c index 363c202..66daba3 100644 --- a/dwm.c +++ b/dwm.c @@ -2009,11 +2009,11 @@ viewprevtag(const char *arg) { void zoom(const char *arg) { - Client *c; + Client *c = sel; if(!sel || !dozoom || sel->isfloating) return; - if((c = sel) == nexttiled(clients, c->monitor)) + if(c == nexttiled(clients, c->monitor)) if(!(c = nexttiled(c->next, c->monitor))) return; detach(c); -- 2.20.1 From 2e8e5509d9cad9229d2d79a1de75038d94032cfb Mon Sep 17 00:00:00 2001 From: Anselm R Garbe Date: Thu, 21 Feb 2008 10:14:42 +0000 Subject: [PATCH 08/16] changed arrange functions to contain the Monitor as first argument --- LICENSE | 2 +- config.def.h | 2 +- dwm.c | 100 +++++++++++++++++++++++++-------------------------- 3 files changed, 51 insertions(+), 53 deletions(-) diff --git a/LICENSE b/LICENSE index 1cf40cc..1b32b82 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT/X Consortium License -© 2006-2007 Anselm R. Garbe +© 2006-2008 Anselm R. Garbe © 2006-2007 Sander van Dijk © 2006-2007 Jukka Salmi © 2007 Premysl Hruby diff --git a/config.def.h b/config.def.h index 3d8e6cb..7866968 100644 --- a/config.def.h +++ b/config.def.h @@ -3,7 +3,7 @@ /* appearance */ #define BARPOS BarTop /* BarBot, BarOff */ #define BORDERPX 1 -#define FONT "-*-terminus-medium-*-*-*-*-*-*-*-*-*-*-*" +#define FONT "-*-terminus-medium-r-normal-*-14-*-*-*-*-*-*-*" #define NORMBORDERCOLOR "#cccccc" #define NORMBGCOLOR "#cccccc" #define NORMFGCOLOR "#000000" diff --git a/dwm.c b/dwm.c index 66daba3..ff9e66a 100644 --- a/dwm.c +++ b/dwm.c @@ -99,9 +99,10 @@ typedef struct { const char *arg; } Key; +typedef struct Monitor Monitor; typedef struct { const char *symbol; - void (*arrange)(void); + void (*arrange)(Monitor *); } Layout; typedef struct { @@ -116,14 +117,16 @@ typedef struct { regex_t *tagregex; } Regs; -typedef struct { - Window barwin; +struct Monitor { + unsigned int id; int sx, sy, sw, sh, wax, way, wah, waw; + double mwfact; Bool *seltags; Bool *prevtags; Layout *layout; - double mwfact; -} Monitor; + Window barwin; +}; + /* function declarations */ void applyrules(Client *c); @@ -148,7 +151,7 @@ void *emallocz(unsigned int size); void enternotify(XEvent *e); void eprint(const char *errstr, ...); void expose(XEvent *e); -void floating(void); /* default floating layout */ +void floating(Monitor *m); /* default floating layout */ void focus(Client *c); void focusin(XEvent *e); void focusnext(const char *arg); @@ -188,7 +191,7 @@ void spawn(const char *arg); void tag(const char *arg); unsigned int textnw(const char *text, unsigned int len); unsigned int textw(const char *text); -void tile(void); +void tile(Monitor *m); void togglebar(const char *arg); void togglefloating(const char *arg); void toggletag(const char *arg); @@ -304,7 +307,7 @@ arrange(void) { else ban(c); - monitors[selmonitor].layout->arrange(); + monitors[selmonitor].layout->arrange(&monitors[selmonitor]); focus(NULL); restack(); } @@ -719,12 +722,12 @@ expose(XEvent *e) { } void -floating(void) { /* default floating layout */ +floating(Monitor *m) { /* default floating layout */ Client *c; domwfact = dozoom = False; for(c = clients; c; c = c->next) - if(isvisible(c, selmonitor)) + if(isvisible(c, m->id)) resize(c, c->x, c->y, c->w, c->h, True); } @@ -1598,6 +1601,7 @@ setup(void) { for(i = 0; i < mcount; i++) { /* init geometry */ m = &monitors[i]; + m->id = i; if (mcount != 1 && isxinerama) { m->sx = info[i].x_org; @@ -1714,56 +1718,50 @@ textw(const char *text) { } void -tile(void) { - unsigned int i, j, n, nx, ny, nw, nh, mw, th; +tile(Monitor *m) { + unsigned int i, n, nx, ny, nw, nh, mw, th; Client *c, *mc; domwfact = dozoom = True; nx = ny = nw = 0; /* gcc stupidity requires this */ - for (i = 0; i < mcount; i++) { - Monitor *m = &monitors[i]; - - for(n = 0, c = nexttiled(clients, i); c; c = nexttiled(c->next, i)) - n++; - - /* window geoms */ - mw = (n == 1) ? m->waw : m->mwfact * m->waw; - th = (n > 1) ? m->wah / (n - 1) : 0; - if(n > 1 && th < bh) - th = m->wah; - - for(j = 0, c = mc = nexttiled(clients, i); c; c = nexttiled(c->next, i)) { - if(j == 0) { /* master */ - nx = m->wax; + for(n = 0, c = nexttiled(clients, m->id); c; c = nexttiled(c->next, m->id)) + n++; + + /* window geoms */ + mw = (n == 1) ? m->waw : m->mwfact * m->waw; + th = (n > 1) ? m->wah / (n - 1) : 0; + if(n > 1 && th < bh) + th = m->wah; + + for(i = 0, c = mc = nexttiled(clients, m->id); c; c = nexttiled(c->next, m->id)) { + if(i == 0) { /* master */ + nx = m->wax; + ny = m->way; + nw = mw - 2 * c->border; + nh = m->wah - 2 * c->border; + } + else { /* tile window */ + if(i == 1) { ny = m->way; - nw = mw - 2 * c->border; - nh = m->wah - 2 * c->border; - } - else { /* tile window */ - if(j == 1) { - ny = m->way; - nx += mc->w + 2 * mc->border; - nw = m->waw - mw - 2 * c->border; - } - if(j + 1 == n) /* remainder */ - nh = (m->way + m->wah) - ny - 2 * c->border; - else - nh = th - 2 * c->border; + nx += mc->w + 2 * mc->border; + nw = m->waw - mw - 2 * c->border; } - fprintf(stderr, "tile(%d, %d, %d, %d)\n", nx, ny, nw, nh); - resize(c, nx, ny, nw, nh, RESIZEHINTS); - if((RESIZEHINTS) && ((c->h < bh) || (c->h > nh) || (c->w < bh) || (c->w > nw))) - /* client doesn't accept size constraints */ - resize(c, nx, ny, nw, nh, False); - if(n > 1 && th != m->wah) - ny = c->y + c->h + 2 * c->border; - - j++; + if(i + 1 == n) /* remainder */ + nh = (m->way + m->wah) - ny - 2 * c->border; + else + nh = th - 2 * c->border; } + resize(c, nx, ny, nw, nh, RESIZEHINTS); + if((RESIZEHINTS) && ((c->h < bh) || (c->h > nh) || (c->w < bh) || (c->w > nw))) + /* client doesn't accept size constraints */ + resize(c, nx, ny, nw, nh, False); + if(n > 1 && th != m->wah) + ny = c->y + c->h + 2 * c->border; + + i++; } - fprintf(stderr, "done\n"); } void togglebar(const char *arg) { @@ -2045,7 +2043,7 @@ selectmonitor(const char *arg) { int main(int argc, char *argv[]) { if(argc == 2 && !strcmp("-v", argv[1])) - eprint("dwm-"VERSION", © 2006-2007 Anselm R. Garbe, Sander van Dijk, " + eprint("dwm-"VERSION", © 2006-2008 Anselm R. Garbe, Sander van Dijk, " "Jukka Salmi, Premysl Hruby, Szabolcs Nagy, Christof Musik\n"); else if(argc != 1) eprint("usage: dwm [-v]\n"); -- 2.20.1 From 55edd2d6ecd66782852db665996c1fda824b5e8c Mon Sep 17 00:00:00 2001 From: Anselm R Garbe Date: Thu, 21 Feb 2008 10:31:06 +0000 Subject: [PATCH 09/16] made restack, drawbar also Monitor-related only --- dwm.c | 180 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 91 insertions(+), 89 deletions(-) diff --git a/dwm.c b/dwm.c index ff9e66a..61b1474 100644 --- a/dwm.c +++ b/dwm.c @@ -144,9 +144,9 @@ void configurerequest(XEvent *e); void destroynotify(XEvent *e); void detach(Client *c); void detachstack(Client *c); -void drawbar(void); -void drawsquare(Monitor *, Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]); -void drawtext(Monitor *, const char *text, unsigned long col[ColLast], Bool invert); +void drawbar(Monitor *m); +void drawsquare(Monitor *m, Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]); +void drawtext(Monitor *m, const char *text, unsigned long col[ColLast], Bool invert); void *emallocz(unsigned int size); void enternotify(XEvent *e); void eprint(const char *errstr, ...); @@ -158,6 +158,7 @@ void focusnext(const char *arg); void focusprev(const char *arg); Client *getclient(Window w); unsigned long getcolor(const char *colstr); +Monitor *getmonitor(Window barwin); long getstate(Window w); Bool gettextprop(Window w, Atom atom, char *text, unsigned int size); void grabbuttons(Client *c, Bool focused); @@ -180,7 +181,7 @@ void quit(const char *arg); void reapply(const char *arg); void resize(Client *c, int x, int y, int w, int h, Bool sizehints); void resizemouse(Client *c); -void restack(void); +void restack(Monitor *m); void run(void); void scan(void); void setclientstate(Client *c, long state); @@ -309,7 +310,7 @@ arrange(void) { monitors[selmonitor].layout->arrange(&monitors[selmonitor]); focus(NULL); - restack(); + restack(&monitors[selmonitor]); } void @@ -370,7 +371,7 @@ buttonpress(XEvent *e) { if(CLEANMASK(ev->state) != MODKEY) return; if(ev->button == Button1) { - restack(); + restack(&monitors[c->monitor]); movemouse(c); } else if(ev->button == Button2) { @@ -380,7 +381,7 @@ buttonpress(XEvent *e) { zoom(NULL); } else if(ev->button == Button3 && !c->isfixed) { - restack(); + restack(&monitors[c->monitor]); resizemouse(c); } } @@ -562,55 +563,51 @@ detachstack(Client *c) { } void -drawbar(void) { - int i, j, x; +drawbar(Monitor *m) { + int j, x; Client *c; - for(i = 0; i < mcount; i++) { - Monitor *m = &monitors[i]; - dc.x = 0; - for(c = stack; c && !isvisible(c, i); c = c->snext); - fprintf(stderr, "m%d %s\n", i, c ? c->name : "NIL"); - for(j = 0; j < LENGTH(tags); j++) { - dc.w = textw(tags[j]); - if(m->seltags[j]) { - drawtext(m, tags[j], dc.sel, isurgent(i, j)); - drawsquare(m, c && c->tags[j] && c->monitor == i, - isoccupied(i, j), isurgent(i, j), dc.sel); - } - else { - drawtext(m, tags[j], dc.norm, isurgent(i, j)); - drawsquare(m, c && c->tags[j] && c->monitor == i, - isoccupied(i, j), isurgent(i, j), dc.norm); - } - dc.x += dc.w; + dc.x = 0; + for(c = stack; c && !isvisible(c, m->id); c = c->snext); + for(j = 0; j < LENGTH(tags); j++) { + dc.w = textw(tags[j]); + if(m->seltags[j]) { + drawtext(m, tags[j], dc.sel, isurgent(m->id, j)); + drawsquare(m, c && c->tags[j] && c->monitor == m->id, + isoccupied(m->id, j), isurgent(m->id, j), dc.sel); } - dc.w = blw; - drawtext(m, m->layout->symbol, dc.norm, False); - x = dc.x + dc.w; - if(i == selmonitor) { - dc.w = textw(stext); - dc.x = m->sw - dc.w; - if(dc.x < x) { - dc.x = x; - dc.w = m->sw - x; - } - drawtext(m, stext, dc.norm, False); + else { + drawtext(m, tags[j], dc.norm, isurgent(m->id, j)); + drawsquare(m, c && c->tags[j] && c->monitor == m->id, + isoccupied(m->id, j), isurgent(m->id, j), dc.norm); } - else - dc.x = m->sw; - if((dc.w = dc.x - x) > bh) { + dc.x += dc.w; + } + dc.w = blw; + drawtext(m, m->layout->symbol, dc.norm, False); + x = dc.x + dc.w; + if(m->id == selmonitor) { + dc.w = textw(stext); + dc.x = m->sw - dc.w; + if(dc.x < x) { dc.x = x; - if(c) { - drawtext(m, c->name, dc.sel, False); - drawsquare(m, False, c->isfloating, False, dc.sel); - } - else - drawtext(m, NULL, dc.norm, False); + dc.w = m->sw - x; } - XCopyArea(dpy, dc.drawable, m->barwin, dc.gc, 0, 0, m->sw, bh, 0, 0); - XSync(dpy, False); + drawtext(m, stext, dc.norm, False); + } + else + dc.x = m->sw; + if((dc.w = dc.x - x) > bh) { + dc.x = x; + if(c) { + drawtext(m, c->name, dc.sel, False); + drawsquare(m, False, c->isfloating, False, dc.sel); + } + else + drawtext(m, NULL, dc.norm, False); } + XCopyArea(dpy, dc.drawable, m->barwin, dc.gc, 0, 0, m->sw, bh, 0, 0); + XSync(dpy, False); } void @@ -713,12 +710,11 @@ eprint(const char *errstr, ...) { void expose(XEvent *e) { + Monitor *m; XExposeEvent *ev = &e->xexpose; - if(ev->count == 0) { - if(ev->window == monitors[selmonitor].barwin) - drawbar(); - } + if(ev->count == 0 && (m = getmonitor(ev->window))) + drawbar(m); } void @@ -750,16 +746,14 @@ focus(Client *c) { grabbuttons(c, True); } sel = c; - drawbar(); if(c) { XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]); XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); selmonitor = c->monitor; } - else { + else XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); - drawbar(); - } + drawbar(&monitors[selmonitor]); } void @@ -781,7 +775,7 @@ focusnext(const char *arg) { for(c = clients; c && !isvisible(c, selmonitor); c = c->next); if(c) { focus(c); - restack(); + restack(&monitors[c->monitor]); } } @@ -798,7 +792,7 @@ focusprev(const char *arg) { } if(c) { focus(c); - restack(); + restack(&monitors[c->monitor]); } } @@ -820,6 +814,16 @@ getcolor(const char *colstr) { return color.pixel; } +Monitor * +getmonitor(Window barwin) { + unsigned int i; + + for(i = 0; i < mcount; i++) + if(monitors[i].barwin == barwin) + return &monitors[i]; + return NULL; +} + long getstate(Window w) { int format, status; @@ -1225,24 +1229,24 @@ propertynotify(XEvent *e) { return; /* ignore */ if((c = getclient(ev->window))) { switch (ev->atom) { - default: break; - case XA_WM_TRANSIENT_FOR: - XGetTransientForHint(dpy, c->win, &trans); - if(!c->isfloating && (c->isfloating = (getclient(trans) != NULL))) - arrange(); - break; - case XA_WM_NORMAL_HINTS: - updatesizehints(c); - break; - case XA_WM_HINTS: - updatewmhints(c); - drawbar(); - break; + default: break; + case XA_WM_TRANSIENT_FOR: + XGetTransientForHint(dpy, c->win, &trans); + if(!c->isfloating && (c->isfloating = (getclient(trans) != NULL))) + arrange(); + break; + case XA_WM_NORMAL_HINTS: + updatesizehints(c); + break; + case XA_WM_HINTS: + updatewmhints(c); + drawbar(&monitors[c->monitor]); + break; } if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) { updatetitle(c); if(c == sel) - drawbar(); + drawbar(&monitors[c->monitor]); } } } @@ -1375,31 +1379,28 @@ resizemouse(Client *c) { } void -restack(void) { - unsigned int i; +restack(Monitor *m) { Client *c; XEvent ev; XWindowChanges wc; - drawbar(); + drawbar(m); if(!sel) return; - if(sel->isfloating || (monitors[selmonitor].layout->arrange == floating)) + if(sel->isfloating || (m->layout->arrange == floating)) XRaiseWindow(dpy, sel->win); - if(monitors[selmonitor].layout->arrange != floating) { + if(m->layout->arrange != floating) { wc.stack_mode = Below; - wc.sibling = monitors[selmonitor].barwin; + wc.sibling = m->barwin; if(!sel->isfloating) { XConfigureWindow(dpy, sel->win, CWSibling | CWStackMode, &wc); wc.sibling = sel->win; } - for(i = 0; i < mcount; i++) { - for(c = nexttiled(clients, i); c; c = nexttiled(c->next, i)) { - if(c == sel) - continue; - XConfigureWindow(dpy, c->win, CWSibling | CWStackMode, &wc); - wc.sibling = c->win; - } + for(c = nexttiled(clients, m->id); c; c = nexttiled(c->next, m->id)) { + if(c == sel) + continue; + XConfigureWindow(dpy, c->win, CWSibling | CWStackMode, &wc); + wc.sibling = c->win; } } XSync(dpy, False); @@ -1456,7 +1457,7 @@ run(void) { } break; } - drawbar(); + drawbar(&monitors[selmonitor]); } while(XPending(dpy)) { XNextEvent(dpy, &ev); @@ -1522,7 +1523,7 @@ setlayout(const char *arg) { if(sel) arrange(); else - drawbar(); + drawbar(m); } void @@ -1651,6 +1652,8 @@ setup(void) { | EnterWindowMask | LeaveWindowMask | StructureNotifyMask; XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); XSelectInput(dpy, root, wa.event_mask); + + drawbar(m); } if(info) XFree(info); @@ -2054,7 +2057,6 @@ main(int argc, char *argv[]) { checkotherwm(); setup(); - drawbar(); scan(); run(); cleanup(); -- 2.20.1 From 4076e2ff60fd20caaed18209e36ee82e49d26219 Mon Sep 17 00:00:00 2001 From: Anselm R Garbe Date: Thu, 21 Feb 2008 14:33:59 +0000 Subject: [PATCH 10/16] applied Gottox' monitor.diff patch (thanks btw) --- dwm.c | 147 ++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 80 insertions(+), 67 deletions(-) diff --git a/dwm.c b/dwm.c index 61b1474..0b82158 100644 --- a/dwm.c +++ b/dwm.c @@ -60,6 +60,7 @@ enum { NetSupported, NetWMName, NetLast }; /* EWMH atoms */ enum { WMProtocols, WMDelete, WMName, WMState, WMLast };/* default atoms */ /* typedefs */ +typedef struct Monitor Monitor; typedef struct Client Client; struct Client { char name[256]; @@ -74,7 +75,7 @@ struct Client { Client *prev; Client *snext; Window win; - int monitor; + Monitor *monitor; }; typedef struct { @@ -99,7 +100,6 @@ typedef struct { const char *arg; } Key; -typedef struct Monitor Monitor; typedef struct { const char *symbol; void (*arrange)(Monitor *); @@ -165,17 +165,18 @@ void grabbuttons(Client *c, Bool focused); void grabkeys(void); unsigned int idxoftag(const char *tag); void initfont(const char *fontstr); -Bool isoccupied(unsigned int monitor, unsigned int t); +Bool isoccupied(Monitor *monitor, unsigned int t); Bool isprotodel(Client *c); -Bool isurgent(unsigned int monitor, unsigned int t); -Bool isvisible(Client *c, int monitor); +Bool isurgent(Monitor *monitor, unsigned int t); +Bool isvisible(Client *c, Monitor *m); void keypress(XEvent *e); void killclient(const char *arg); void manage(Window w, XWindowAttributes *wa); void mappingnotify(XEvent *e); void maprequest(XEvent *e); +Monitor *monitorat(void); void movemouse(Client *c); -Client *nexttiled(Client *c, int monitor); +Client *nexttiled(Client *c, Monitor *monitor); void propertynotify(XEvent *e); void quit(const char *arg); void reapply(const char *arg); @@ -210,14 +211,13 @@ int xerror(Display *dpy, XErrorEvent *ee); int xerrordummy(Display *dsply, XErrorEvent *ee); int xerrorstart(Display *dsply, XErrorEvent *ee); void zoom(const char *arg); -int monitorat(void); void movetomonitor(const char *arg); void selectmonitor(const char *arg); /* variables */ char stext[256]; int mcount = 1; -int selmonitor = 0; +Monitor *selmonitor; int screen; int (*xerrorxlib)(Display *, XErrorEvent *); unsigned int bh, bpos; @@ -277,7 +277,7 @@ applyrules(Client *c) { if(regs[i].propregex && !regexec(regs[i].propregex, buf, 1, &tmp, 0)) { if (rules[i].monitor >= 0 && rules[i].monitor < mcount) { matched_monitor = True; - c->monitor = rules[i].monitor; + c->monitor = &monitors[rules[i].monitor]; } c->isfloating = rules[i].isfloating; @@ -293,7 +293,7 @@ applyrules(Client *c) { if(ch.res_name) XFree(ch.res_name); if(!matched_tag) - memcpy(c->tags, monitors[monitorat()].seltags, sizeof initags); + memcpy(c->tags, monitorat()->seltags, sizeof initags); if (!matched_monitor) c->monitor = monitorat(); } @@ -308,9 +308,9 @@ arrange(void) { else ban(c); - monitors[selmonitor].layout->arrange(&monitors[selmonitor]); + selmonitor->layout->arrange(selmonitor); focus(NULL); - restack(&monitors[selmonitor]); + restack(selmonitor); } void @@ -331,7 +331,7 @@ void ban(Client *c) { if(c->isbanned) return; - XMoveWindow(dpy, c->win, c->x + 3 * monitors[c->monitor].sw, c->y); + XMoveWindow(dpy, c->win, c->x + 3 * c->monitor->sw, c->y); c->isbanned = True; } @@ -341,7 +341,7 @@ buttonpress(XEvent *e) { Client *c; XButtonPressedEvent *ev = &e->xbutton; - Monitor *m = &monitors[monitorat()]; + Monitor *m = monitorat(); if(ev->window == m->barwin) { x = 0; @@ -371,7 +371,7 @@ buttonpress(XEvent *e) { if(CLEANMASK(ev->state) != MODKEY) return; if(ev->button == Button1) { - restack(&monitors[c->monitor]); + restack(c->monitor); movemouse(c); } else if(ev->button == Button2) { @@ -381,7 +381,7 @@ buttonpress(XEvent *e) { zoom(NULL); } else if(ev->button == Button3 && !c->isfixed) { - restack(&monitors[c->monitor]); + restack(c->monitor); resizemouse(c); } } @@ -475,7 +475,7 @@ configure(Client *c) { void configurenotify(XEvent *e) { XConfigureEvent *ev = &e->xconfigure; - Monitor *m = &monitors[selmonitor]; + Monitor *m = selmonitor; if(ev->window == root && (ev->width != m->sw || ev->height != m->sh)) { /* TODO -- update Xinerama dimensions here */ @@ -496,7 +496,7 @@ configurerequest(XEvent *e) { XWindowChanges wc; if((c = getclient(ev->window))) { - Monitor *m = &monitors[c->monitor]; + Monitor *m = c->monitor; if(ev->value_mask & CWBorderWidth) c->border = ev->border_width; if(c->isfixed || c->isfloating || (floating == m->layout->arrange)) { @@ -568,25 +568,25 @@ drawbar(Monitor *m) { Client *c; dc.x = 0; - for(c = stack; c && !isvisible(c, m->id); c = c->snext); + for(c = stack; c && !isvisible(c, m); c = c->snext); for(j = 0; j < LENGTH(tags); j++) { dc.w = textw(tags[j]); if(m->seltags[j]) { - drawtext(m, tags[j], dc.sel, isurgent(m->id, j)); - drawsquare(m, c && c->tags[j] && c->monitor == m->id, - isoccupied(m->id, j), isurgent(m->id, j), dc.sel); + drawtext(m, tags[j], dc.sel, isurgent(m, j)); + drawsquare(m, c && c->tags[j] && c->monitor == m, + isoccupied(m, j), isurgent(m, j), dc.sel); } else { - drawtext(m, tags[j], dc.norm, isurgent(m->id, j)); - drawsquare(m, c && c->tags[j] && c->monitor == m->id, - isoccupied(m->id, j), isurgent(m->id, j), dc.norm); + drawtext(m, tags[j], dc.norm, isurgent(m, j)); + drawsquare(m, c && c->tags[j] && c->monitor == m, + isoccupied(m, j), isurgent(m, j), dc.norm); } dc.x += dc.w; } dc.w = blw; drawtext(m, m->layout->symbol, dc.norm, False); x = dc.x + dc.w; - if(m->id == selmonitor) { + if(m == selmonitor) { dc.w = textw(stext); dc.x = m->sw - dc.w; if(dc.x < x) { @@ -693,7 +693,7 @@ enternotify(XEvent *e) { focus(c); else { selmonitor = monitorat(); - fprintf(stderr, "updating selmonitor %d\n", selmonitor); + fprintf(stderr, "updating selmonitor %d\n", selmonitor - monitors); focus(NULL); } } @@ -723,17 +723,14 @@ floating(Monitor *m) { /* default floating layout */ domwfact = dozoom = False; for(c = clients; c; c = c->next) - if(isvisible(c, m->id)) + if(isvisible(c, m)) resize(c, c->x, c->y, c->w, c->h, True); } void focus(Client *c) { - Monitor *m; - if(c) selmonitor = c->monitor; - m = &monitors[selmonitor]; if(!c || (c && !isvisible(c, selmonitor))) for(c = stack; c && !isvisible(c, c->monitor); c = c->snext); if(sel && sel != c) { @@ -753,7 +750,7 @@ focus(Client *c) { } else XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); - drawbar(&monitors[selmonitor]); + drawbar(selmonitor); } void @@ -775,7 +772,7 @@ focusnext(const char *arg) { for(c = clients; c && !isvisible(c, selmonitor); c = c->next); if(c) { focus(c); - restack(&monitors[c->monitor]); + restack(c->monitor); } } @@ -792,7 +789,7 @@ focusprev(const char *arg) { } if(c) { focus(c); - restack(&monitors[c->monitor]); + restack(c->monitor); } } @@ -985,7 +982,7 @@ initfont(const char *fontstr) { } Bool -isoccupied(unsigned int monitor, unsigned int t) { +isoccupied(Monitor *monitor, unsigned int t) { Client *c; for(c = clients; c; c = c->next) @@ -1010,7 +1007,7 @@ isprotodel(Client *c) { } Bool -isurgent(unsigned int monitor, unsigned int t) { +isurgent(Monitor *monitor, unsigned int t) { Client *c; for(c = clients; c; c = c->next) @@ -1020,13 +1017,13 @@ isurgent(unsigned int monitor, unsigned int t) { } Bool -isvisible(Client *c, int monitor) { +isvisible(Client *c, Monitor *m) { unsigned int i; - if(c->monitor != monitor) + if(c->monitor != m) return False; for(i = 0; i < LENGTH(tags); i++) - if(c->tags[i] && monitors[c->monitor].seltags[i]) + if(c->tags[i] && c->monitor->seltags[i]) return True; return False; } @@ -1081,7 +1078,7 @@ manage(Window w, XWindowAttributes *wa) { applyrules(c); - m = &monitors[c->monitor]; + m = selmonitor; c->x = wa->x + m->sx; c->y = wa->y + m->sy; @@ -1150,7 +1147,7 @@ maprequest(XEvent *e) { manage(ev->window, &wa); } -int +Monitor * monitorat() { int i, x, y; Window win; @@ -1160,10 +1157,10 @@ monitorat() { for(i = 0; i < mcount; i++) { if((x >= monitors[i].sx && x < monitors[i].sx + monitors[i].sw) && (y >= monitors[i].sy && y < monitors[i].sy + monitors[i].sh)) { - return i; + return &monitors[i]; } } - return 0; + return NULL; } void @@ -1176,7 +1173,7 @@ movemouse(Client *c) { ocx = nx = c->x; ocy = ny = c->y; - m = &monitors[c->monitor]; + m = c->monitor; if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, None, cursor[CurMove], CurrentTime) != GrabSuccess) return; @@ -1214,7 +1211,7 @@ movemouse(Client *c) { } Client * -nexttiled(Client *c, int monitor) { +nexttiled(Client *c, Monitor *monitor) { for(; c && (c->isfloating || !isvisible(c, monitor)); c = c->next); return c; } @@ -1240,13 +1237,13 @@ propertynotify(XEvent *e) { break; case XA_WM_HINTS: updatewmhints(c); - drawbar(&monitors[c->monitor]); + drawbar(c->monitor); break; } if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) { updatetitle(c); if(c == sel) - drawbar(&monitors[c->monitor]); + drawbar(c->monitor); } } } @@ -1273,7 +1270,7 @@ resize(Client *c, int x, int y, int w, int h, Bool sizehints) { Monitor *m; XWindowChanges wc; - m = &monitors[c->monitor]; + m = c->monitor; if(sizehints) { /* set minimum possible */ @@ -1344,7 +1341,7 @@ resizemouse(Client *c) { ocx = c->x; ocy = c->y; - m = &monitors[c->monitor]; + m = c->monitor; if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, None, cursor[CurResize], CurrentTime) != GrabSuccess) return; @@ -1396,7 +1393,7 @@ restack(Monitor *m) { XConfigureWindow(dpy, sel->win, CWSibling | CWStackMode, &wc); wc.sibling = sel->win; } - for(c = nexttiled(clients, m->id); c; c = nexttiled(c->next, m->id)) { + for(c = nexttiled(clients, m); c; c = nexttiled(c->next, m)) { if(c == sel) continue; XConfigureWindow(dpy, c->win, CWSibling | CWStackMode, &wc); @@ -1457,7 +1454,7 @@ run(void) { } break; } - drawbar(&monitors[selmonitor]); + drawbar(selmonitor); } while(XPending(dpy)) { XNextEvent(dpy, &ev); @@ -1505,7 +1502,7 @@ setclientstate(Client *c, long state) { void setlayout(const char *arg) { unsigned int i; - Monitor *m = &monitors[monitorat()]; + Monitor *m = monitorat(); if(!arg) { m->layout++; @@ -1530,7 +1527,7 @@ void setmwfact(const char *arg) { double delta; - Monitor *m = &monitors[monitorat()]; + Monitor *m = monitorat(); if(!domwfact) return; @@ -1574,7 +1571,7 @@ setup(void) { mcount = 1; if((isxinerama = XineramaIsActive(dpy))) info = XineramaQueryScreens(dpy, &mcount); - monitors = emallocz(mcount * sizeof(Monitor)); + selmonitor = monitors = emallocz(mcount * sizeof(Monitor)); screen = DefaultScreen(dpy); root = RootWindow(dpy, screen); @@ -1665,7 +1662,7 @@ setup(void) { compileregs(); selmonitor = monitorat(); - fprintf(stderr, "selmonitor == %d\n", selmonitor); + fprintf(stderr, "selmonitor == %d\n", selmonitor - monitors); } void @@ -1729,7 +1726,7 @@ tile(Monitor *m) { nx = ny = nw = 0; /* gcc stupidity requires this */ - for(n = 0, c = nexttiled(clients, m->id); c; c = nexttiled(c->next, m->id)) + for(n = 0, c = nexttiled(clients, m); c; c = nexttiled(c->next, m)) n++; /* window geoms */ @@ -1738,7 +1735,7 @@ tile(Monitor *m) { if(n > 1 && th < bh) th = m->wah; - for(i = 0, c = mc = nexttiled(clients, m->id); c; c = nexttiled(c->next, m->id)) { + for(i = 0, c = mc = nexttiled(clients, m); c; c = nexttiled(c->next, m)) { if(i == 0) { /* master */ nx = m->wax; ny = m->way; @@ -1772,7 +1769,7 @@ togglebar(const char *arg) { bpos = (BARPOS == BarOff) ? BarTop : BARPOS; else bpos = BarOff; - updatebarpos(&monitors[monitorat()]); + updatebarpos(monitorat()); arrange(); } @@ -1804,7 +1801,7 @@ void toggleview(const char *arg) { unsigned int i, j; - Monitor *m = &monitors[monitorat()]; + Monitor *m = monitorat(); i = idxoftag(arg); m->seltags[i] = !m->seltags[i]; @@ -1984,7 +1981,7 @@ void view(const char *arg) { unsigned int i; Bool tmp[LENGTH(tags)]; - Monitor *m = &monitors[monitorat()]; + Monitor *m = monitorat(); for(i = 0; i < LENGTH(tags); i++) tmp[i] = (NULL == arg); @@ -2000,7 +1997,7 @@ void viewprevtag(const char *arg) { static Bool tmp[LENGTH(tags)]; - Monitor *m = &monitors[monitorat()]; + Monitor *m = monitorat(); memcpy(tmp, m->seltags, sizeof initags); memcpy(m->seltags, m->prevtags, sizeof initags); @@ -2025,19 +2022,35 @@ zoom(const char *arg) { void movetomonitor(const char *arg) { - if (sel) { - sel->monitor = arg ? atoi(arg) : (sel->monitor+1) % mcount; + int i; - memcpy(sel->tags, monitors[sel->monitor].seltags, sizeof initags); - resize(sel, monitors[sel->monitor].wax, monitors[sel->monitor].way, sel->w, sel->h, True); - arrange(); + if (sel) + return; + if(arg) + i = atoi(arg); + else { + for(i = 0; &monitors[i] != sel->monitor && i < mcount; i++); + i++; } + sel->monitor = &monitors[i % mcount]; + + memcpy(sel->tags, sel->monitor->seltags, sizeof initags); + resize(sel, sel->monitor->wax, sel->monitor->way, sel->w, sel->h, True); + arrange(); } void selectmonitor(const char *arg) { - Monitor *m = &monitors[arg ? atoi(arg) : (monitorat()+1) % mcount]; + int i; + Monitor *m; + if(arg) + i = atoi(arg); + else { + for(i = 0; &monitors[i] != sel->monitor && i < mcount; i++); + i++; + } + m = &monitors[i % mcount]; XWarpPointer(dpy, None, root, 0, 0, 0, 0, m->wax+m->waw/2, m->way+m->wah/2); focus(NULL); } -- 2.20.1 From 9cb9c32ee7d76554cfc44ad8801d70cef9fe25e9 Mon Sep 17 00:00:00 2001 From: Anselm R Garbe Date: Thu, 21 Feb 2008 19:19:46 +0000 Subject: [PATCH 11/16] minor --- dwm.c | 1 - 1 file changed, 1 deletion(-) diff --git a/dwm.c b/dwm.c index 0b82158..e0802ad 100644 --- a/dwm.c +++ b/dwm.c @@ -1568,7 +1568,6 @@ setup(void) { cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur); // init screens/monitors first - mcount = 1; if((isxinerama = XineramaIsActive(dpy))) info = XineramaQueryScreens(dpy, &mcount); selmonitor = monitors = emallocz(mcount * sizeof(Monitor)); -- 2.20.1 From dd218235369d12ad9d71269db11db05c464a09e0 Mon Sep 17 00:00:00 2001 From: Anselm R Garbe Date: Fri, 22 Feb 2008 10:03:42 +0000 Subject: [PATCH 12/16] made arrange() Monitor-dependent as well, fixed the movemouse/resizemouse issues --- dwm.c | 52 ++++++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/dwm.c b/dwm.c index e0802ad..4d5a9b9 100644 --- a/dwm.c +++ b/dwm.c @@ -130,7 +130,7 @@ struct Monitor { /* function declarations */ void applyrules(Client *c); -void arrange(void); +void arrange(Monitor *m); void attach(Client *c); void attachstack(Client *c); void ban(Client *c); @@ -299,7 +299,8 @@ applyrules(Client *c) { } void -arrange(void) { +arrange(Monitor *m) { + unsigned int i; Client *c; for(c = clients; c; c = c->next) @@ -308,9 +309,13 @@ arrange(void) { else ban(c); - selmonitor->layout->arrange(selmonitor); + if(m) + m->layout->arrange(m); + else + for(i = 0; i < mcount; i++) + m->layout->arrange(&monitors[i]); focus(NULL); - restack(selmonitor); + restack(m); } void @@ -485,7 +490,7 @@ configurenotify(XEvent *e) { dc.drawable = XCreatePixmap(dpy, root, DisplayWidth(root, screen), bh, DefaultDepth(dpy, screen)); XResizeWindow(dpy, m->barwin, m->sw, bh); updatebarpos(m); - arrange(); + arrange(m); } } @@ -1078,7 +1083,7 @@ manage(Window w, XWindowAttributes *wa) { applyrules(c); - m = selmonitor; + m = c->monitor; c->x = wa->x + m->sx; c->y = wa->y + m->sy; @@ -1122,7 +1127,7 @@ manage(Window w, XWindowAttributes *wa) { ban(c); XMapWindow(dpy, c->win); setclientstate(c, NormalState); - arrange(); + arrange(m); } void @@ -1201,7 +1206,7 @@ movemouse(Client *c) { ny = m->way; else if(abs((m->way + m->wah) - (ny + c->h + 2 * c->border)) < SNAP) ny = m->way + m->wah - c->h - 2 * c->border; - if((m->layout->arrange != floating) && (abs(nx - c->x) > SNAP || abs(ny - c->y) > SNAP)) + if(!c->isfloating && (m->layout->arrange != floating) && (abs(nx - c->x) > SNAP || abs(ny - c->y) > SNAP)) togglefloating(NULL); if((m->layout->arrange == floating) || c->isfloating) resize(c, nx, ny, c->w, c->h, False); @@ -1230,7 +1235,7 @@ propertynotify(XEvent *e) { case XA_WM_TRANSIENT_FOR: XGetTransientForHint(dpy, c->win, &trans); if(!c->isfloating && (c->isfloating = (getclient(trans) != NULL))) - arrange(); + arrange(c->monitor); break; case XA_WM_NORMAL_HINTS: updatesizehints(c); @@ -1262,7 +1267,7 @@ reapply(const char *arg) { memcpy(c->tags, zerotags, sizeof zerotags); applyrules(c); } - arrange(); + arrange(NULL); } void @@ -1366,7 +1371,7 @@ resizemouse(Client *c) { nw = 1; if((nh = ev.xmotion.y - ocy - 2 * c->border + 1) <= 0) nh = 1; - if((m->layout->arrange != floating) && (abs(nw - c->w) > SNAP || abs(nh - c->h) > SNAP)) + if(!c->isfloating && (m->layout->arrange != floating) && (abs(nw - c->w) > SNAP || abs(nh - c->h) > SNAP)) togglefloating(NULL); if((m->layout->arrange == floating) || c->isfloating) resize(c, c->x, c->y, nw, nh, True); @@ -1518,7 +1523,7 @@ setlayout(const char *arg) { m->layout = &layouts[i]; } if(sel) - arrange(); + arrange(m); else drawbar(m); } @@ -1544,7 +1549,7 @@ setmwfact(const char *arg) { else if(m->mwfact > 0.9) m->mwfact = 0.9; } - arrange(); + arrange(m); } void @@ -1697,7 +1702,7 @@ tag(const char *arg) { for(i = 0; i < LENGTH(tags); i++) sel->tags[i] = (NULL == arg); sel->tags[idxoftag(arg)] = True; - arrange(); + arrange(sel->monitor); } unsigned int @@ -1769,7 +1774,7 @@ togglebar(const char *arg) { else bpos = BarOff; updatebarpos(monitorat()); - arrange(); + arrange(monitorat()); } void @@ -1779,7 +1784,7 @@ togglefloating(const char *arg) { sel->isfloating = !sel->isfloating; if(sel->isfloating) resize(sel, sel->x, sel->y, sel->w, sel->h, True); - arrange(); + arrange(sel->monitor); } void @@ -1793,13 +1798,12 @@ toggletag(const char *arg) { for(j = 0; j < LENGTH(tags) && !sel->tags[j]; j++); if(j == LENGTH(tags)) sel->tags[i] = True; /* at least one tag must be enabled */ - arrange(); + arrange(sel->monitor); } void toggleview(const char *arg) { unsigned int i, j; - Monitor *m = monitorat(); i = idxoftag(arg); @@ -1807,7 +1811,7 @@ toggleview(const char *arg) { for(j = 0; j < LENGTH(tags) && !m->seltags[j]; j++); if(j == LENGTH(tags)) m->seltags[i] = True; /* at least one tag must be viewed */ - arrange(); + arrange(m); } void @@ -1838,7 +1842,7 @@ unmanage(Client *c) { XSync(dpy, False); XSetErrorHandler(xerror); XUngrabServer(dpy); - arrange(); + arrange(NULL); } void @@ -1988,7 +1992,7 @@ view(const char *arg) { if(memcmp(m->seltags, tmp, sizeof initags) != 0) { memcpy(m->prevtags, m->seltags, sizeof initags); memcpy(m->seltags, tmp, sizeof initags); - arrange(); + arrange(m); } } @@ -2001,7 +2005,7 @@ viewprevtag(const char *arg) { memcpy(tmp, m->seltags, sizeof initags); memcpy(m->seltags, m->prevtags, sizeof initags); memcpy(m->prevtags, tmp, sizeof initags); - arrange(); + arrange(m); } void @@ -2016,7 +2020,7 @@ zoom(const char *arg) { detach(c); attach(c); focus(c); - arrange(); + arrange(c->monitor); } void @@ -2035,7 +2039,7 @@ movetomonitor(const char *arg) { memcpy(sel->tags, sel->monitor->seltags, sizeof initags); resize(sel, sel->monitor->wax, sel->monitor->way, sel->w, sel->h, True); - arrange(); + arrange(sel->monitor); } void -- 2.20.1 From 8e0f8ffcc63f27bd2e2c666b4e889a3056b3b70b Mon Sep 17 00:00:00 2001 From: Anselm R Garbe Date: Fri, 22 Feb 2008 10:15:59 +0000 Subject: [PATCH 13/16] crash fix --- dwm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dwm.c b/dwm.c index 4d5a9b9..de20b36 100644 --- a/dwm.c +++ b/dwm.c @@ -313,7 +313,7 @@ arrange(Monitor *m) { m->layout->arrange(m); else for(i = 0; i < mcount; i++) - m->layout->arrange(&monitors[i]); + monitors[i].layout->arrange(&monitors[i]); focus(NULL); restack(m); } -- 2.20.1 From de5b294edce70dae164855fb06e0472441ae28ee Mon Sep 17 00:00:00 2001 From: Anselm R Garbe Date: Fri, 22 Feb 2008 10:34:12 +0000 Subject: [PATCH 14/16] some other fixes, resize contains a minor bug --- dwm.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/dwm.c b/dwm.c index de20b36..7684646 100644 --- a/dwm.c +++ b/dwm.c @@ -1276,7 +1276,6 @@ resize(Client *c, int x, int y, int w, int h, Bool sizehints) { XWindowChanges wc; m = c->monitor; - if(sizehints) { /* set minimum possible */ if (w < 1) @@ -1325,6 +1324,7 @@ resize(Client *c, int x, int y, int w, int h, Bool sizehints) { x = m->sx; if(y + h + 2 * c->border < m->sy) y = m->sy; + fprintf(stderr, "resize %d %d %d %d (%d %d %d %d)\n", x, y , w, h, m->sx, m->sy, m->sw, m->sh); if(c->x != x || c->y != y || c->w != w || c->h != h) { c->x = wc.x = x; c->y = wc.y = y; @@ -1605,7 +1605,7 @@ setup(void) { m = &monitors[i]; m->id = i; - if (mcount != 1 && isxinerama) { + if(mcount != 1 && isxinerama) { m->sx = info[i].x_org; m->sy = info[i].y_org; m->sw = info[i].width; @@ -1727,9 +1727,9 @@ tile(Monitor *m) { Client *c, *mc; domwfact = dozoom = True; - - nx = ny = nw = 0; /* gcc stupidity requires this */ - + nx = m->wax; + ny = m->way; + nw = 0; for(n = 0, c = nexttiled(clients, m); c; c = nexttiled(c->next, m)) n++; @@ -1757,16 +1757,17 @@ tile(Monitor *m) { else nh = th - 2 * c->border; } + fprintf(stderr, "tile %d %d %d %d\n", nx, ny, nw, nh); resize(c, nx, ny, nw, nh, RESIZEHINTS); if((RESIZEHINTS) && ((c->h < bh) || (c->h > nh) || (c->w < bh) || (c->w > nw))) /* client doesn't accept size constraints */ resize(c, nx, ny, nw, nh, False); if(n > 1 && th != m->wah) ny = c->y + c->h + 2 * c->border; - i++; } } + void togglebar(const char *arg) { if(bpos == BarOff) @@ -1824,6 +1825,7 @@ unban(Client *c) { void unmanage(Client *c) { + Monitor *m = c->monitor; XWindowChanges wc; wc.border_width = c->oldborder; @@ -1842,7 +1844,7 @@ unmanage(Client *c) { XSync(dpy, False); XSetErrorHandler(xerror); XUngrabServer(dpy); - arrange(NULL); + arrange(m); } void -- 2.20.1 From c43d7b7587c9639a303b02ff7a44bf18a54f06cb Mon Sep 17 00:00:00 2001 From: Anselm R Garbe Date: Fri, 22 Feb 2008 15:26:27 +0000 Subject: [PATCH 15/16] added Gottox to Copyright holders after all his contributions, applied his last patch --- LICENSE | 5 +++-- dwm.c | 5 +---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/LICENSE b/LICENSE index 1b32b82..3fbaaf1 100644 --- a/LICENSE +++ b/LICENSE @@ -1,11 +1,12 @@ MIT/X Consortium License -© 2006-2008 Anselm R. Garbe +© 2006-2008 Anselm R Garbe © 2006-2007 Sander van Dijk © 2006-2007 Jukka Salmi © 2007 Premysl Hruby © 2007 Szabolcs Nagy -© 2007 Christof Musik +© 2007 Christof Musik +© 2008 Enno Gottox Boland Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), diff --git a/dwm.c b/dwm.c index 7684646..8e7a86a 100644 --- a/dwm.c +++ b/dwm.c @@ -118,7 +118,6 @@ typedef struct { } Regs; struct Monitor { - unsigned int id; int sx, sy, sw, sh, wax, way, wah, waw; double mwfact; Bool *seltags; @@ -1603,7 +1602,6 @@ setup(void) { for(i = 0; i < mcount; i++) { /* init geometry */ m = &monitors[i]; - m->id = i; if(mcount != 1 && isxinerama) { m->sx = info[i].x_org; @@ -2064,8 +2062,7 @@ selectmonitor(const char *arg) { int main(int argc, char *argv[]) { if(argc == 2 && !strcmp("-v", argv[1])) - eprint("dwm-"VERSION", © 2006-2008 Anselm R. Garbe, Sander van Dijk, " - "Jukka Salmi, Premysl Hruby, Szabolcs Nagy, Christof Musik\n"); + eprint("dwm-"VERSION", © 2006-2008 dwm engineers, see LICENSE for details\n"); else if(argc != 1) eprint("usage: dwm [-v]\n"); -- 2.20.1 From d6e24f7116768427a2bb7a2b04f5295b9b5fb327 Mon Sep 17 00:00:00 2001 From: Anselm R Garbe Date: Fri, 22 Feb 2008 15:27:50 +0000 Subject: [PATCH 16/16] well typo fix --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 3fbaaf1..f93acc4 100644 --- a/LICENSE +++ b/LICENSE @@ -6,7 +6,7 @@ MIT/X Consortium License © 2007 Premysl Hruby © 2007 Szabolcs Nagy © 2007 Christof Musik -© 2008 Enno Gottox Boland +© 2007-2008 Enno Gottox Boland Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), -- 2.20.1