t* dwm + patches URI git clone git://git.codevoid.de/dwm-sdk DIR Log DIR Files DIR Refs DIR README DIR LICENSE --- DIR commit 985e3305249987739867f33879ddbb8bc3028e00 DIR parent 5f19423c7bd2aa1ebb3010af15bebffbc3a9cbc3 URI Author: anselm@anselm1 <unknown> Date: Fri, 21 Dec 2007 12:54:45 +0000 merged Christof Musik's Xinerama support patches, though this needs some polishing! Diffstat: M config.mk | 2 +- M dwm.c | 756 ++++++++++++++++++------------- 2 files changed, 454 insertions(+), 304 deletions(-) --- DIR diff --git a/config.mk b/config.mk t@@ -12,7 +12,7 @@ X11LIB = /usr/X11R6/lib # includes and libs INCS = -I. -I/usr/include -I${X11INC} -LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 +LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lXinerama # flags CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\" DIR diff --git a/dwm.c b/dwm.c t@@ -40,6 +40,9 @@ #include <X11/Xlib.h> #include <X11/Xproto.h> #include <X11/Xutil.h> +//#ifdef XINERAMA +#include <X11/extensions/Xinerama.h> +//#endif /* macros */ #define BUTTONMASK (ButtonPressMask | ButtonReleaseMask) t@@ -71,6 +74,7 @@ struct Client { Client *prev; Client *snext; Window win; + int monitor; }; typedef struct { t@@ -104,6 +108,7 @@ typedef struct { const char *prop; const char *tags; Bool isfloating; + int monitor; } Rule; typedef struct { t@@ -111,6 +116,17 @@ typedef struct { regex_t *tagregex; } Regs; +typedef struct { + int id; + Window barwin; + int sx, sy, sw, sh, wax, way, wah, waw; + DC dc; + Bool *seltags; + Bool *prevtags; + Layout *layout; + double mwfact; +} Monitor; + /* function declarations */ void applyrules(Client *c); void arrange(void); t@@ -128,8 +144,8 @@ void destroynotify(XEvent *e); void detach(Client *c); void detachstack(Client *c); void drawbar(void); -void drawsquare(Bool filled, Bool empty, unsigned long col[ColLast]); -void drawtext(const char *text, unsigned long col[ColLast]); +void drawsquare(Monitor *, Bool filled, Bool empty, unsigned long col[ColLast]); +void drawtext(Monitor *, const char *text, unsigned long col[ColLast]); void *emallocz(unsigned int size); void enternotify(XEvent *e); void eprint(const char *errstr, ...); t@@ -146,10 +162,10 @@ 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(const char *fontstr); -Bool isoccupied(unsigned int t); +void initfont(Monitor*, const char *fontstr); +Bool isoccupied(Monitor *m, unsigned int t); Bool isprotodel(Client *c); -Bool isvisible(Client *c); +Bool isvisible(Client *c, Monitor *m); void keypress(XEvent *e); void killclient(const char *arg); void leavenotify(XEvent *e); t@@ -158,7 +174,7 @@ void mappingnotify(XEvent *e); void maprequest(XEvent *e); void maximize(const char *arg); void movemouse(Client *c); -Client *nexttiled(Client *c); +Client *nexttiled(Client *c, Monitor *m); void propertynotify(XEvent *e); void quit(const char *arg); void reapply(const char *arg); t@@ -173,8 +189,8 @@ void setmwfact(const char *arg); void setup(void); 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); +unsigned int textnw(Monitor*, const char *text, unsigned int len); +unsigned int textw(Monitor*, const char *text); void tile(void); void togglebar(const char *arg); void togglefloating(const char *arg); t@@ -183,7 +199,7 @@ void toggleview(const char *arg); void unban(Client *c); void unmanage(Client *c); void unmapnotify(XEvent *e); -void updatebarpos(void); +void updatebarpos(Monitor *s); void updatesizehints(Client *c); void updatetitle(Client *c); void view(const char *arg); t@@ -192,11 +208,15 @@ 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(int, int); +void movetomonitor(const char *arg); +void selectmonitor(const char *arg); /* variables */ char stext[256]; -double mwfact; -int screen, sx, sy, sw, sh, wax, way, waw, wah; +int mcount, screen; +//double mwfact; +//int screen, sx, sy, sw, sh, wax, way, waw, wah; int (*xerrorxlib)(Display *, XErrorEvent *); unsigned int bh, bpos; unsigned int blw = 0; t@@ -221,21 +241,24 @@ Bool domwfact = True; Bool dozoom = True; Bool otherwm, readin; Bool running = True; -Bool selscreen = True; +//Bool selscreen = True; Client *clients = NULL; Client *sel = NULL; Client *stack = NULL; Cursor cursor[CurLast]; Display *dpy; DC dc = {0}; -Layout *layout = NULL; -Window barwin, root; +Window root; +//Layout *layout = NULL; +//Window barwin, root; Regs *regs = NULL; +Monitor *monitors; +int selmonitor = 0; /* configuration, allows nested code to access above variables */ #include "config.h" -Bool prevtags[LENGTH(tags)]; +//Bool prevtags[LENGTH(tags)]; /* function implementations */ void t@@ -243,7 +266,8 @@ applyrules(Client *c) { static char buf[512]; unsigned int i, j; regmatch_t tmp; - Bool matched = False; + Bool matched_tag = False; + Bool matched_monitor = False; XClassHint ch = { 0 }; /* rule matching */ t@@ -253,10 +277,15 @@ applyrules(Client *c) { ch.res_name ? ch.res_name : "", c->name); for(i = 0; i < LENGTH(rules); i++) 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->isfloating = rules[i].isfloating; for(j = 0; regs[i].tagregex && j < LENGTH(tags); j++) { if(!regexec(regs[i].tagregex, tags[j], 1, &tmp, 0)) { - matched = True; + matched_tag = True; c->tags[j] = True; } } t@@ -265,8 +294,10 @@ applyrules(Client *c) { XFree(ch.res_class); if(ch.res_name) XFree(ch.res_name); - if(!matched) - memcpy(c->tags, seltags, sizeof seltags); + if(!matched_tag) + memcpy(c->tags, monitors[monitorat(-1, -1)].seltags, sizeof seltags); + if (!matched_monitor) + c->monitor = monitorat(-1, -1); } void t@@ -274,11 +305,12 @@ arrange(void) { Client *c; for(c = clients; c; c = c->next) - if(isvisible(c)) + if(isvisible(c, &monitors[c->monitor])) unban(c); else ban(c); - layout->arrange(); + + monitors[selmonitor].layout->arrange(); focus(NULL); restack(); } t@@ -301,7 +333,7 @@ void ban(Client *c) { if(c->isbanned) return; - XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y); + XMoveWindow(dpy, c->win, c->x + 3 * monitors[c->monitor].sw, c->y); c->isbanned = True; } t@@ -311,10 +343,12 @@ buttonpress(XEvent *e) { Client *c; XButtonPressedEvent *ev = &e->xbutton; - if(ev->window == barwin) { + Monitor s = monitors[monitorat(-1, -1)]; + + if(ev->window == s.barwin) { x = 0; for(i = 0; i < LENGTH(tags); i++) { - x += textw(tags[i]); + x += textw(&s, tags[i]); if(ev->x < x) { if(ev->button == Button1) { if(ev->state & MODKEY) t@@ -339,20 +373,20 @@ buttonpress(XEvent *e) { if(CLEANMASK(ev->state) != MODKEY) return; if(ev->button == Button1) { - if((layout->arrange == floating) || c->isfloating) + if((s.layout->arrange == floating) || c->isfloating) restack(); else togglefloating(NULL); movemouse(c); } else if(ev->button == Button2) { - if((floating != layout->arrange) && c->isfloating) + if((floating != s.layout->arrange) && c->isfloating) togglefloating(NULL); else zoom(NULL); } else if(ev->button == Button3 && !c->isfixed) { - if((floating == layout->arrange) || c->isfloating) + if((floating == s.layout->arrange) || c->isfloating) restack(); else togglefloating(NULL); t@@ -379,24 +413,28 @@ checkotherwm(void) { void cleanup(void) { + unsigned int i; close(STDIN_FILENO); while(stack) { unban(stack); unmanage(stack); } - 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); - XDestroyWindow(dpy, barwin); - XFreeCursor(dpy, cursor[CurNormal]); - XFreeCursor(dpy, cursor[CurResize]); - XFreeCursor(dpy, cursor[CurMove]); - XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); - XSync(dpy, False); + 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); + } } void t@@ -446,14 +484,15 @@ configure(Client *c) { void configurenotify(XEvent *e) { XConfigureEvent *ev = &e->xconfigure; + Monitor *m = &monitors[selmonitor]; - if(ev->window == root && (ev->width != sw || ev->height != sh)) { - sw = ev->width; - sh = ev->height; + 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, root, sw, bh, DefaultDepth(dpy, screen)); - XResizeWindow(dpy, barwin, sw, bh); - updatebarpos(); + dc.drawable = XCreatePixmap(dpy, root, m->sw, bh, DefaultDepth(dpy, screen)); + XResizeWindow(dpy, m->barwin, m->sw, bh); + updatebarpos(m); arrange(); } } t@@ -465,25 +504,26 @@ configurerequest(XEvent *e) { XWindowChanges wc; if((c = getclient(ev->window))) { + Monitor *m = &monitors[c->monitor]; if(ev->value_mask & CWBorderWidth) c->border = ev->border_width; - if(c->isfixed || c->isfloating || (floating == layout->arrange)) { + if(c->isfixed || c->isfloating || (floating == m->layout->arrange)) { if(ev->value_mask & CWX) - c->x = ev->x; + c->x = m->sx+ev->x; if(ev->value_mask & CWY) - c->y = ev->y; + c->y = m->sy+ev->y; if(ev->value_mask & CWWidth) c->w = ev->width; if(ev->value_mask & CWHeight) c->h = ev->height; - if((c->x + c->w) > sw && c->isfloating) - c->x = sw / 2 - c->w / 2; /* center in x direction */ - if((c->y + c->h) > sh && c->isfloating) - c->y = sh / 2 - c->h / 2; /* center in y direction */ + if((c->x - m->sx + c->w) > m->sw && c->isfloating) + c->x = m->sx + (m->sw / 2 - c->w / 2); /* center in x direction */ + if((c->y - m->sy + c->h) > m->sh && c->isfloating) + c->y = m->sy + (m->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(c, &monitors[monitorat(-1,-1)])) XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); } else t@@ -532,74 +572,77 @@ detachstack(Client *c) { void drawbar(void) { - int i, x; - - dc.x = dc.y = 0; - for(i = 0; i < LENGTH(tags); i++) { - dc.w = textw(tags[i]); - if(seltags[i]) { - drawtext(tags[i], dc.sel); - drawsquare(sel && sel->tags[i], isoccupied(i), dc.sel); + int i, x, s; + + for(s = 0; s < mcount; ++s) { + Monitor *m = &monitors[s]; + m->dc.x = 0; + for(i = 0; i < LENGTH(tags); i++) { + m->dc.w = textw(m, tags[i]); + if(m->seltags[i]) { + drawtext(m, tags[i], m->dc.sel); + drawsquare(m, sel && sel->tags[i] && sel->monitor == m->id, isoccupied(m, i), m->dc.sel); + } + else { + drawtext(m, tags[i], m->dc.norm); + drawsquare(m, sel && sel->tags[i] && sel->monitor == m->id, isoccupied(m, i), m->dc.norm); + } + m->dc.x += m->dc.w; } - else { - drawtext(tags[i], dc.norm); - drawsquare(sel && sel->tags[i], isoccupied(i), dc.norm); + m->dc.w = blw; + drawtext(m, m->layout->symbol, m->dc.norm); + 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; } - dc.x += dc.w; - } - dc.w = blw; - drawtext(layout->symbol, dc.norm); - x = dc.x + dc.w; - dc.w = textw(stext); - dc.x = sw - dc.w; - if(dc.x < x) { - dc.x = x; - dc.w = sw - x; - } - drawtext(stext, dc.norm); - if((dc.w = dc.x - x) > bh) { - dc.x = x; - if(sel) { - drawtext(sel->name, dc.sel); - drawsquare(False, sel->isfloating, dc.sel); + drawtext(m, stext, m->dc.norm); + if((m->dc.w = m->dc.x - x) > bh) { + m->dc.x = x; + if(sel && sel->monitor == m->id) { + drawtext(m, sel->name, m->dc.sel); + drawsquare(m, False, sel->isfloating, m->dc.sel); + } + else + drawtext(m, NULL, m->dc.norm); } - else - drawtext(NULL, dc.norm); + XCopyArea(dpy, m->dc.drawable, m->barwin, m->dc.gc, 0, 0, m->sw, bh, 0, 0); + XSync(dpy, False); } - XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, sw, bh, 0, 0); - XSync(dpy, False); } void -drawsquare(Bool filled, Bool empty, unsigned long col[ColLast]) { +drawsquare(Monitor *m, Bool filled, Bool empty, unsigned long col[ColLast]) { int x; XGCValues gcv; - XRectangle r = { dc.x, dc.y, dc.w, dc.h }; + XRectangle r = { m->dc.x, m->dc.y, m->dc.w, m->dc.h }; gcv.foreground = col[ColFG]; - 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; + 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; if(filled) { r.width = r.height = x + 1; - XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); + XFillRectangles(dpy, m->dc.drawable, m->dc.gc, &r, 1); } else if(empty) { r.width = r.height = x; - XDrawRectangles(dpy, dc.drawable, dc.gc, &r, 1); + XDrawRectangles(dpy, m->dc.drawable, m->dc.gc, &r, 1); } } void -drawtext(const char *text, unsigned long col[ColLast]) { +drawtext(Monitor *m, const char *text, unsigned long col[ColLast]) { int x, y, w, h; static char buf[256]; unsigned int len, olen; - XRectangle r = { dc.x, dc.y, dc.w, dc.h }; + XRectangle r = { m->dc.x, m->dc.y, m->dc.w, m->dc.h }; - XSetForeground(dpy, dc.gc, col[ColBG]); - XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); + XSetForeground(dpy, m->dc.gc, col[ColBG]); + XFillRectangles(dpy, m->dc.drawable, m->dc.gc, &r, 1); if(!text) return; w = 0; t@@ -608,11 +651,11 @@ drawtext(const char *text, unsigned long col[ColLast]) { len = sizeof buf - 1; memcpy(buf, text, len); buf[len] = 0; - h = dc.font.ascent + dc.font.descent; - y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent; - x = dc.x + (h / 2); + 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); /* shorten text if necessary */ - while(len && (w = textnw(buf, len)) > dc.w - h) + while(len && (w = textnw(m, buf, len)) > m->dc.w - h) buf[--len] = 0; if(len < olen) { if(len > 1) t@@ -622,13 +665,13 @@ drawtext(const char *text, unsigned long col[ColLast]) { if(len > 3) buf[len - 3] = '.'; } - if(w > dc.w) + if(w > m->dc.w) return; /* too long */ - XSetForeground(dpy, dc.gc, col[ColFG]); - if(dc.font.set) - XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len); + XSetForeground(dpy, m->dc.gc, col[ColFG]); + if(m->dc.font.set) + XmbDrawString(dpy, m->dc.drawable, m->dc.font.set, m->dc.gc, x, y, buf, len); else - XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len); + XDrawString(dpy, m->dc.drawable, m->dc.gc, x, y, buf, len); } void * t@@ -650,7 +693,7 @@ enternotify(XEvent *e) { if((c = getclient(ev->window))) focus(c); else if(ev->window == root) { - selscreen = True; + selmonitor = True; focus(NULL); } } t@@ -670,7 +713,7 @@ expose(XEvent *e) { XExposeEvent *ev = &e->xexpose; if(ev->count == 0) { - if(ev->window == barwin) + if(ev->window == monitors[selmonitor].barwin) drawbar(); } } t@@ -681,17 +724,18 @@ floating(void) { /* default floating layout */ domwfact = dozoom = False; for(c = clients; c; c = c->next) - if(isvisible(c)) + if(isvisible(c, &monitors[selmonitor])) resize(c, c->x, c->y, c->w, c->h, True); } void focus(Client *c) { - if((!c && selscreen) || (c && !isvisible(c))) - for(c = stack; c && !isvisible(c); c = c->snext); + Monitor *m = &monitors[monitorat(-1, -1)]; + if(!c || (c && !isvisible(c, m))) + for(c = stack; c && !isvisible(c, m); c = c->snext); if(sel && sel != c) { grabbuttons(sel, False); - XSetWindowBorder(dpy, sel->win, dc.norm[ColBorder]); + XSetWindowBorder(dpy, sel->win, monitors[sel->monitor].dc.norm[ColBorder]); } if(c) { detachstack(c); t@@ -700,14 +744,15 @@ focus(Client *c) { } sel = c; drawbar(); - if(!selscreen) - return; if(c) { - XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]); + XSetWindowBorder(dpy, c->win, monitors[c->monitor].dc.sel[ColBorder]); XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); + selmonitor = monitorat(c->x, c->y); } - else + else { XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); + selmonitor = monitorat(-1, -1); + } } void t@@ -721,12 +766,13 @@ focusin(XEvent *e) { /* there are some broken focus acquiring clients */ void focusnext(const char *arg) { Client *c; + Monitor *m = &monitors[selmonitor]; if(!sel) return; - for(c = sel->next; c && !isvisible(c); c = c->next); + for(c = sel->next; c && !isvisible(c, m); c = c->next); if(!c) - for(c = clients; c && !isvisible(c); c = c->next); + for(c = clients; c && !isvisible(c, m); c = c->next); if(c) { focus(c); restack(); t@@ -736,13 +782,14 @@ focusnext(const char *arg) { void focusprev(const char *arg) { Client *c; + Monitor *m = &monitors[selmonitor]; if(!sel) return; - for(c = sel->prev; c && !isvisible(c); c = c->prev); + for(c = sel->prev; c && !isvisible(c, m); c = c->prev); if(!c) { for(c = clients; c && c->next; c = c->next); - for(; c && !isvisible(c); c = c->prev); + for(; c && !isvisible(c, m); c = c->prev); } if(c) { focus(c); t@@ -877,53 +924,53 @@ idxoftag(const char *tag) { } void -initfont(const char *fontstr) { +initfont(Monitor *m, const char *fontstr) { char *def, **missing; int i, n; missing = NULL; - if(dc.font.set) - XFreeFontSet(dpy, dc.font.set); - dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def); + if(m->dc.font.set) + XFreeFontSet(dpy, m->dc.font.set); + m->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(dc.font.set) { + if(m->dc.font.set) { XFontSetExtents *font_extents; XFontStruct **xfonts; char **font_names; - 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; + 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; xfonts++; } } else { - 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"))) + 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"))) eprint("error, cannot load font: '%s'\n", fontstr); - dc.font.ascent = dc.font.xfont->ascent; - dc.font.descent = dc.font.xfont->descent; + m->dc.font.ascent = m->dc.font.xfont->ascent; + m->dc.font.descent = m->dc.font.xfont->descent; } - dc.font.height = dc.font.ascent + dc.font.descent; + m->dc.font.height = m->dc.font.ascent + m->dc.font.descent; } Bool -isoccupied(unsigned int t) { +isoccupied(Monitor *m, unsigned int t) { Client *c; for(c = clients; c; c = c->next) - if(c->tags[t]) + if(c->tags[t] && c->monitor == m->id) return True; return False; } t@@ -944,11 +991,11 @@ isprotodel(Client *c) { } Bool -isvisible(Client *c) { +isvisible(Client *c, Monitor *m) { unsigned int i; for(i = 0; i < LENGTH(tags); i++) - if(c->tags[i] && seltags[i]) + if(c->tags[i] && monitors[c->monitor].seltags[i] && m->id == c->monitor) return True; return False; } t@@ -994,7 +1041,7 @@ leavenotify(XEvent *e) { XCrossingEvent *ev = &e->xcrossing; if((ev->window == root) && !ev->same_screen) { - selscreen = False; + selmonitor = False; focus(NULL); } } t@@ -1009,30 +1056,40 @@ manage(Window w, XWindowAttributes *wa) { c = emallocz(sizeof(Client)); c->tags = emallocz(sizeof seltags); c->win = w; - c->x = wa->x; - c->y = wa->y; + + applyrules(c); + Monitor *m = &monitors[c->monitor]; + + c->x = wa->x+m->sx; + c->y = wa->y+m->sy; c->w = wa->width; c->h = wa->height; c->oldborder = wa->border_width; - if(c->w == sw && c->h == sh) { - c->x = sx; - c->y = sy; + + if (monitorat(c->x, c->y) != c->monitor) { + c->x = m->sx; + c->y = m->sy; + } + + if(c->w == m->sw && c->h == m->sh) { + c->x = m->sx; + c->y = m->sy; c->border = wa->border_width; } else { - if(c->x + c->w + 2 * c->border > wax + waw) - c->x = wax + waw - c->w - 2 * c->border; - if(c->y + c->h + 2 * c->border > way + wah) - c->y = way + wah - c->h - 2 * c->border; - if(c->x < wax) - c->x = wax; - if(c->y < way) - c->y = way; + if(c->x + c->w + 2 * c->border > m->wax + m->waw) + c->x = m->wax + m->waw - c->w - 2 * c->border; + if(c->y + c->h + 2 * c->border > m->way + m->wah) + c->y = m->way + m->wah - c->h - 2 * c->border; + if(c->x < m->wax) + c->x = m->wax; + if(c->y < m->way) + c->y = m->way; c->border = BORDERPX; } wc.border_width = c->border; XConfigureWindow(dpy, w, CWBorderWidth, &wc); - XSetWindowBorder(dpy, w, dc.norm[ColBorder]); + XSetWindowBorder(dpy, w, m->dc.norm[ColBorder]); configure(c); /* propagates border_width, if size doesn't change */ updatesizehints(c); XSelectInput(dpy, w, EnterWindowMask | FocusChangeMask | PropertyChangeMask | StructureNotifyMask); t@@ -1042,7 +1099,6 @@ manage(Window w, XWindowAttributes *wa) { for(t = clients; t && t->win != trans; t = t->next); if(t) memcpy(c->tags, t->tags, sizeof seltags); - applyrules(c); if(!c->isfloating) c->isfloating = (rettrans == Success) || c->isfixed; attach(c); t@@ -1078,9 +1134,11 @@ maprequest(XEvent *e) { void maximize(const char *arg) { +/* if(!sel || (!sel->isfloating && layout->arrange != floating)) return; resize(sel, wax, way, waw - 2 * sel->border, wah - 2 * sel->border, True); +*/ } void t@@ -1111,23 +1169,25 @@ movemouse(Client *c) { XSync(dpy, False); nx = ocx + (ev.xmotion.x - x1); ny = ocy + (ev.xmotion.y - y1); - if(abs(wax + nx) < SNAP) - nx = wax; - else if(abs((wax + waw) - (nx + c->w + 2 * c->border)) < SNAP) - nx = wax + waw - c->w - 2 * c->border; - if(abs(way - ny) < SNAP) - ny = way; - else if(abs((way + wah) - (ny + c->h + 2 * c->border)) < SNAP) - ny = way + wah - c->h - 2 * c->border; + Monitor *m = &monitors[monitorat(nx, ny)]; + if(abs(m->wax - nx) < SNAP) + nx = m->wax; + else if(abs((m->wax + m->waw) - (nx + c->w + 2 * c->border)) < SNAP) + nx = m->wax + m->waw - c->w - 2 * c->border; + if(abs(m->way - ny) < SNAP) + 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; resize(c, nx, ny, c->w, c->h, False); + memcpy(c->tags, monitors[monitorat(nx, ny)].seltags, sizeof seltags); break; } } } Client * -nexttiled(Client *c) { - for(; c && (c->isfloating || !isvisible(c)); c = c->next); +nexttiled(Client *c, Monitor *m) { + for(; c && (c->isfloating || !isvisible(c, m)); c = c->next); return c; } t@@ -1179,6 +1239,8 @@ reapply(const char *arg) { void resize(Client *c, int x, int y, int w, int h, Bool sizehints) { XWindowChanges wc; + Monitor scr = monitors[monitorat(x, y)]; + c->monitor = scr.id; if(sizehints) {