JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
fixed Gottox' mail address
[dwm.git] / dwm.c
diff --git a/dwm.c b/dwm.c
index e0802ad..0e47626 100644 (file)
--- 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;
@@ -130,7 +129,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 +298,8 @@ applyrules(Client *c) {
 }
 
 void
-arrange(void) {
+arrange(Monitor *m) {
+       unsigned int i;
        Client *c;
 
        for(c = clients; c; c = c->next)
@@ -308,9 +308,13 @@ arrange(void) {
                else
                        ban(c);
 
-       selmonitor->layout->arrange(selmonitor);
+       if(m)
+               m->layout->arrange(m);
+       else
+               for(i = 0; i < mcount; i++)
+                       monitors[i].layout->arrange(&monitors[i]);
        focus(NULL);
-       restack(selmonitor);
+       restack(m);
 }
 
 void
@@ -485,7 +489,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 +1082,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 +1126,7 @@ manage(Window w, XWindowAttributes *wa) {
        ban(c);
        XMapWindow(dpy, c->win);
        setclientstate(c, NormalState);
-       arrange();
+       arrange(m);
 }
 
 void
@@ -1201,7 +1205,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 +1234,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 +1266,7 @@ reapply(const char *arg) {
                memcpy(c->tags, zerotags, sizeof zerotags);
                applyrules(c);
        }
-       arrange();
+       arrange(NULL);
 }
 
 void
@@ -1271,7 +1275,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)
@@ -1320,6 +1323,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;
@@ -1366,7 +1370,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 +1522,7 @@ setlayout(const char *arg) {
                m->layout = &layouts[i];
        }
        if(sel)
-               arrange();
+               arrange(m);
        else
                drawbar(m);
 }
@@ -1544,7 +1548,7 @@ setmwfact(const char *arg) {
                else if(m->mwfact > 0.9)
                        m->mwfact = 0.9;
        }
-       arrange();
+       arrange(m);
 }
 
 void
@@ -1598,9 +1602,8 @@ setup(void) {
        for(i = 0; i < mcount; i++) {
                /* init geometry */
                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;
@@ -1697,7 +1700,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
@@ -1722,9 +1725,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++;
 
@@ -1752,16 +1755,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)
@@ -1769,7 +1773,7 @@ togglebar(const char *arg) {
        else
                bpos = BarOff;
        updatebarpos(monitorat());
-       arrange();
+       arrange(monitorat());
 }
 
 void
@@ -1779,7 +1783,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 +1797,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 +1810,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
@@ -1820,6 +1823,7 @@ unban(Client *c) {
 
 void
 unmanage(Client *c) {
+       Monitor *m = c->monitor;
        XWindowChanges wc;
 
        wc.border_width = c->oldborder;
@@ -1838,7 +1842,7 @@ unmanage(Client *c) {
        XSync(dpy, False);
        XSetErrorHandler(xerror);
        XUngrabServer(dpy);
-       arrange();
+       arrange(m);
 }
 
 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
@@ -2057,9 +2061,9 @@ selectmonitor(const char *arg) {
 
 int
 main(int argc, char *argv[]) {
+       fprintf(stderr, "%u\n", sizeof("jsjsjsjsjssjsj"));
        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");