JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
new colorscheme (16-bit compliant)
[dwm.git] / tile.c
diff --git a/tile.c b/tile.c
index 8075e55..56a06d3 100644 (file)
--- a/tile.c
+++ b/tile.c
-/* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
- * See LICENSE file for license details.
- */
+/* See LICENSE file for copyright and license details. */
 #include "dwm.h"
-
-unsigned int master = MASTER;
-unsigned int nmaster = NMASTER;
+#include <stdio.h>
 
 /* static */
 
-static void
-togglemax(Client *c) {
-       XEvent ev;
+static double mwfact = MWFACT;
+
+/* extern */
 
-       if(c->isfixed)
+void
+setmwfact(const char *arg) {
+       double delta;
+
+       if(!isarrange(tile))
                return;
-       if((c->ismax = !c->ismax)) {
-               c->rx = c->x;
-               c->ry = c->y;
-               c->rw = c->w;
-               c->rh = c->h;
-               resize(c, wax, way, waw - 2 * BORDERPX, wah - 2 * BORDERPX, True);
+       /* arg handling, manipulate mwfact */
+       if(arg == NULL)
+               mwfact = MWFACT;
+       else if(1 == sscanf(arg, "%lf", &delta)) {
+               if(arg[0] != '+' && arg[0] != '-')
+                       mwfact = delta;
+               else
+                       mwfact += delta;
+               if(mwfact < 0.1)
+                       mwfact = 0.1;
+               else if(mwfact > 0.9)
+                       mwfact = 0.9;
        }
-       else
-               resize(c, c->rx, c->ry, c->rw, c->rh, True);
-       while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
+       arrange();
 }
 
-/* extern */
-
 void
-dotile(void) {
-       unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th;
+tile(void) {
+       unsigned int i, n, nx, ny, nw, nh, mw, th;
        Client *c;
 
-       for(n = 0, c = nextmanaged(clients); c; c = nextmanaged(c->next))
+       for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
                n++;
+
        /* window geoms */
-       mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1);
-       mw = (n > nmaster) ? (waw * master) / 1000 : waw;
-       th = (n > nmaster) ? wah / (n - nmaster) : 0;
-       tw = waw - mw;
+       mw = (n == 1) ? waw : mwfact * waw;
+       th = (n > 1) ? wah / (n - 1) : 0;
+       if(n > 1 && th < bh)
+               th = wah;
 
-       for(i = 0, c = clients; c; c = c->next)
-               if(isvisible(c)) {
-                       if(c->isbanned)
-                               XMoveWindow(dpy, c->win, c->x, c->y);
-                       c->isbanned = False;
-                       if(c->isfloat)
-                               continue;
-                       c->ismax = False;
-                       nx = wax;
-                       ny = way;
-                       if(i < nmaster) {
-                               ny += i * mh;
-                               nw = mw - 2 * BORDERPX;
-                               nh = mh - 2 * BORDERPX;
-                       }
-                       else {  /* tile window */
+       nx = wax;
+       ny = way;
+       for(i = 0, c = nexttiled(clients); c; c = nexttiled(c->next), i++) {
+               c->ismax = False;
+               if(i == 0) { /* master */
+                       nw = mw - 2 * c->border;
+                       nh = wah - 2 * c->border;
+               }
+               else {  /* tile window */
+                       if(i == 1) {
+                               ny = way;
                                nx += mw;
-                               nw = tw - 2 * BORDERPX;
-                               if(th > 2 * BORDERPX) {
-                                       ny += (i - nmaster) * th;
-                                       nh = th - 2 * BORDERPX;
-                               }
-                               else /* fallback if th <= 2 * BORDERPX */
-                                       nh = wah - 2 * BORDERPX;
                        }
-                       resize(c, nx, ny, nw, nh, False);
-                       i++;
+                       nw = waw - mw - 2 * c->border;
+                       if(i + 1 == n) /* remainder */
+                               nh = (way + wah) - ny - 2 * c->border;
+                       else
+                               nh = th - 2 * c->border;
                }
-               else {
-                       c->isbanned = True;
-                       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);
+               resize(c, nx, ny, nw, nh, RESIZEHINTS);
+               if(n > 1 && th != wah)
+                       ny += nh + 2 * c->border;
        }
-       restack();
 }
 
 void
-incnmaster(Arg *arg) {
-       if((arrange == dofloat) || (nmaster + arg->i < 1)
-       || (wah / (nmaster + arg->i) <= 2 * BORDERPX))
-               return;
-       nmaster += arg->i;
-       if(sel)
-               arrange();
-       else
-               drawstatus();
-}
-
-void
-resizemaster(Arg *arg) {
-       if(arrange != dotile)
-               return;
-       if(arg->i == 0)
-               master = MASTER;
-       else {
-               if(waw * (master + arg->i) / 1000 >= waw - 2 * BORDERPX
-               || waw * (master + arg->i) / 1000 <= 2 * BORDERPX)
-                       return;
-               master += arg->i;
-       }
-       arrange();
-}
-
-void
-zoom(Arg *arg) {
-       unsigned int n;
+zoom(const char *arg) {
        Client *c;
 
-       if(!sel)
-               return;
-       if(sel->isfloat || (arrange == dofloat)) {
-               togglemax(sel);
+       if(!sel || !isarrange(tile) || sel->isfloating)
                return;
-       }
-       for(n = 0, c = nextmanaged(clients); c; c = nextmanaged(c->next))
-               n++;
-
-       if((c = sel) == nextmanaged(clients))
-               if(!(c = nextmanaged(c->next)))
+       if((c = sel) == nexttiled(clients))
+               if(!(c = nexttiled(c->next)))
                        return;
        detach(c);
        attach(c);