X-Git-Url: https://jasonwoof.com/gitweb/?p=dwm.git;a=blobdiff_plain;f=dwm.c;h=ff9e66ab5983bd3704b9a84f683b91470ed8ee1b;hp=11f229382b4e7f5dda78914a78597753de07384a;hb=2e8e5509d9cad9229d2d79a1de75038d94032cfb;hpb=c2737b7b9317743e3430c71bc0a9afcc6b0f70f7 diff --git a/dwm.c b/dwm.c index 11f2293..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,15 +117,16 @@ 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); @@ -149,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); @@ -189,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); @@ -305,7 +307,7 @@ arrange(void) { else ban(c); - monitors[selmonitor].layout->arrange(); + monitors[selmonitor].layout->arrange(&monitors[selmonitor]); focus(NULL); restack(); } @@ -720,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); } @@ -1164,11 +1166,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 +1192,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 +1200,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; } } @@ -1264,9 +1266,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 */ @@ -1308,17 +1311,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; @@ -1335,10 +1335,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 +1365,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; } @@ -1599,8 +1601,7 @@ setup(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; @@ -1717,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) { @@ -2012,11 +2007,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); @@ -2048,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");