JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
prepared yet another hotfix release
[dwm.git] / view.c
diff --git a/view.c b/view.c
index b4de573..de3328e 100644 (file)
--- a/view.c
+++ b/view.c
@@ -2,6 +2,7 @@
  * See LICENSE file for license details.
  */
 #include "dwm.h"
+#include <stdio.h>
 
 /* static */
 
@@ -11,40 +12,6 @@ nexttiled(Client *c) {
        return c;
 }
 
-static Bool
-ismaster(Client *c) {
-       Client *cl;
-       unsigned int i;
-
-       for(cl = nexttiled(clients), i = 0; cl && cl != c; cl = nexttiled(cl->next), i++);
-       return i < nmaster;
-}
-
-static void
-pop(Client *c) {
-       detach(c);
-       if(clients)
-               clients->prev = c;
-       c->next = clients;
-       clients = c;
-}
-
-static void
-swap(Client *c1, Client *c2) {
-       Client tmp = *c1;
-       Client *cp = c1->prev;
-       Client *cn = c1->next;
-
-       *c1 = *c2;
-       c1->prev = cp;
-       c1->next = cn;
-       cp = c2->prev;
-       cn = c2->next;
-       *c2 = tmp;
-       c2->prev = cp;
-       c2->next = cn;
-}
-
 static void
 togglemax(Client *c) {
        XEvent ev;
@@ -64,19 +31,10 @@ togglemax(Client *c) {
                c->w = c->rw;
                c->h = c->rh;
        }
-       resize(c, True, TopLeft);
+       resize(c, True);
        while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
 }
 
-static Client *
-topofstack() {
-       Client *c;
-       unsigned int i;
-
-       for(c = nexttiled(clients), i = 0; c && i < nmaster; c = nexttiled(c->next), i++);
-       return (i < nmaster) ? NULL : c;
-}
-
 /* extern */
 
 void (*arrange)(void) = DEFMODE;
@@ -98,10 +56,10 @@ dofloat(void) {
 
        for(c = clients; c; c = c->next) {
                if(isvisible(c)) {
-                       resize(c, True, TopLeft);
+                       resize(c, True);
                }
                else
-                       ban(c);
+                       XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
        }
        if(!sel || !isvisible(sel)) {
                for(c = stack; c && !isvisible(c); c = c->snext);
@@ -118,15 +76,15 @@ dotile(void) {
        for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
                n++;
        /* window geoms */
-       mw = (n > nmaster) ? (waw * master) / 1000 : waw;
        mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1);
-       tw = waw - mw;
+       mw = (n > nmaster) ? (waw * master) / 1000 : waw;
        th = (n > nmaster) ? wah / (n - nmaster) : 0;
+       tw = waw - mw;
 
        for(i = 0, c = clients; c; c = c->next)
                if(isvisible(c)) {
                        if(c->isfloat) {
-                               resize(c, True, TopLeft);
+                               resize(c, True);
                                continue;
                        }
                        c->ismax = False;
@@ -140,19 +98,18 @@ dotile(void) {
                        else {  /* tile window */
                                c->x += mw;
                                c->w = tw - 2 * BORDERPX;
-                               if(th > bh) {
+                               if(th - 2 * BORDERPX > bh) {
                                        c->y += (i - nmaster) * th;
                                        c->h = th - 2 * BORDERPX;
                                }
-                               else /* fallback if th < bh */
+                               else /* fallback if th - 2 * BORDERPX < bh */
                                        c->h = wah - 2 * BORDERPX;
                        }
-                       resize(c, False, TopLeft);
+                       resize(c, False);
                        i++;
                }
                else
-                       ban(c);
-
+                       XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
        if(!sel || !isvisible(sel)) {
                for(c = stack; c && !isvisible(c); c = c->snext);
                focus(c);
@@ -192,10 +149,14 @@ focusprev(Arg *arg) {
 
 void
 incnmaster(Arg *arg) {
-       if(nmaster + arg->i < 1)
+       if((arrange == dofloat) || (nmaster + arg->i < 1)
+               || (wah / (nmaster + arg->i) - 2 * BORDERPX < bh))
                return;
        nmaster += arg->i;
-       arrange();
+       if(sel)
+               arrange();
+       else
+               drawstatus();
 }
 
 Bool
@@ -213,7 +174,8 @@ resizemaster(Arg *arg) {
        if(arg->i == 0)
                master = MASTER;
        else {
-               if(master + arg->i > 950 || master + arg->i < 50)
+               if(waw * (master + arg->i) / 1000 > waw - bh - 2 * BORDERPX
+                       || waw * (master + arg->i) / 1000 < bh + 2 * BORDERPX)
                        return;
                master += arg->i;
        }
@@ -225,27 +187,20 @@ restack(void) {
        Client *c;
        XEvent ev;
 
-       if(!sel) {
-               drawstatus();
+       drawstatus();
+       if(!sel)
                return;
-       }
-       if(sel->isfloat || arrange == dofloat) {
+       if(sel->isfloat || arrange == dofloat)
                XRaiseWindow(dpy, sel->win);
-               XRaiseWindow(dpy, sel->twin);
-       }
        if(arrange != dofloat) {
-               if(!sel->isfloat) {
-                       XLowerWindow(dpy, sel->twin);
+               if(!sel->isfloat)
                        XLowerWindow(dpy, sel->win);
-               }
                for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
                        if(c == sel)
                                continue;
-                       XLowerWindow(dpy, c->twin);
                        XLowerWindow(dpy, c->win);
                }
        }
-       drawall();
        XSync(dpy, False);
        while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
 }
@@ -303,18 +258,14 @@ zoom(Arg *arg) {
        for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
                n++;
 
-       c = sel;
-       if(n <= nmaster || (arrange == dofloat))
-               pop(c);
-       else if(ismaster(sel)) {
-               if(!(c = topofstack()))
+       if((c = sel) == nexttiled(clients))
+               if(!(c = nexttiled(c->next)))
                        return;
-               swap(c, sel);
-               c = sel;
-       }
-       else
-               pop(c);
-
+       detach(c);
+       if(clients)
+               clients->prev = c;
+       c->next = clients;
+       clients = c;
        focus(c);
        arrange();
 }