const char *arg;
} Key;
+typedef struct Monitor Monitor;
typedef struct {
const char *symbol;
- void (*arrange)(void);
+ void (*arrange)(Monitor *);
} Layout;
typedef struct {
regex_t *tagregex;
} Regs;
-typedef struct {
- int monitor;
- 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);
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, ...);
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);
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);
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);
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);
else
ban(c);
- monitors[selmonitor].layout->arrange();
+ monitors[selmonitor].layout->arrange(&monitors[selmonitor]);
focus(NULL);
- restack();
+ restack(&monitors[selmonitor]);
}
void
if(CLEANMASK(ev->state) != MODKEY)
return;
if(ev->button == Button1) {
- restack();
+ restack(&monitors[c->monitor]);
movemouse(c);
}
else if(ev->button == Button2) {
zoom(NULL);
}
else if(ev->button == Button3 && !c->isfixed) {
- restack();
+ restack(&monitors[c->monitor]);
resizemouse(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
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
-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);
}
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
for(c = clients; c && !isvisible(c, selmonitor); c = c->next);
if(c) {
focus(c);
- restack();
+ restack(&monitors[c->monitor]);
}
}
}
if(c) {
focus(c);
- restack();
+ restack(&monitors[c->monitor]);
}
}
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;
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;
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)
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;
}
}
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]);
}
}
}
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 */
}
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;
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;
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;
}
}
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);
}
break;
}
- drawbar();
+ drawbar(&monitors[selmonitor]);
}
while(XPending(dpy)) {
XNextEvent(dpy, &ev);
if(sel)
arrange();
else
- drawbar();
+ drawbar(m);
}
void
for(i = 0; i < mcount; i++) {
/* init geometry */
m = &monitors[i];
-
- m->monitor = i;
+ m->id = i;
if (mcount != 1 && isxinerama) {
m->sx = info[i].x_org;
| EnterWindowMask | LeaveWindowMask | StructureNotifyMask;
XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
XSelectInput(dpy, root, wa.event_mask);
+
+ drawbar(m);
}
if(info)
XFree(info);
}
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;
+ nx += mc->w + 2 * mc->border;
+ nw = m->waw - mw - 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;
- }
- 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) {
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);
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");
checkotherwm();
setup();
- drawbar();
scan();
run();
cleanup();