JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
removed Layout->updategeom, unnecessary
[dwm.git] / dwm.c
diff --git a/dwm.c b/dwm.c
index 908c464..0e4703e 100644 (file)
--- a/dwm.c
+++ b/dwm.c
@@ -52,6 +52,7 @@
 #define MAXTAGLEN       16
 #define MOUSEMASK       (BUTTONMASK|PointerMotionMask)
 #define TAGMASK         ((int)((1LL << LENGTH(tags)) - 1))
+#define TEXTW(x)        (textnw(x, strlen(x)) + dc.font.height)
 #define VISIBLE(x)      ((x)->tags & tagset[seltags])
 
 /* enums */
@@ -71,7 +72,7 @@ struct Client {
        int minax, maxax, minay, maxay;
        long flags;
        int bw, oldbw;
-       Bool isbanned, isfixed, isfloating, isurgent;
+       Bool isbanned, isfixed, isfloating, ismax, isurgent;
        uint tags;
        Client *next;
        Client *prev;
@@ -104,7 +105,6 @@ typedef struct {
 typedef struct {
        const char *symbol;
        void (*arrange)(void);
-       void (*updategeom)(void);
 } Layout;
 
 typedef struct {
@@ -120,7 +120,6 @@ void applyrules(Client *c);
 void arrange(void);
 void attach(Client *c);
 void attachstack(Client *c);
-void ban(Client *c);
 void buttonpress(XEvent *e);
 void checkotherwm(void);
 void cleanup(void);
@@ -170,21 +169,19 @@ void setup(void);
 void spawn(const void *arg);
 void tag(const void *arg);
 uint textnw(const char *text, uint len);
-uint textw(const char *text);
 void tile(void);
 void tileresize(Client *c, int x, int y, int w, int h);
 void togglebar(const void *arg);
 void togglefloating(const void *arg);
 void togglelayout(const void *arg);
+void togglemax(const void *arg);
 void toggletag(const void *arg);
 void toggleview(const void *arg);
-void unban(Client *c);
 void unmanage(Client *c);
 void unmapnotify(XEvent *e);
 void updatebar(void);
 void updategeom(void);
 void updatesizehints(Client *c);
-void updatetilegeom(void);
 void updatetitle(Client *c);
 void updatewmhints(Client *c);
 void view(const void *arg);
@@ -198,7 +195,6 @@ void zoom(const void *arg);
 char stext[256];
 int screen, sx, sy, sw, sh;
 int bx, by, bw, bh, blw, wx, wy, ww, wh;
-int mx, my, mw, mh, tx, ty, tw, th;
 uint seltags = 0;
 int (*xerrorxlib)(Display *, XErrorEvent *);
 uint numlockmask = 0;
@@ -217,6 +213,7 @@ void (*handler[LASTEvent]) (XEvent *) = {
        [UnmapNotify] = unmapnotify
 };
 Atom wmatom[WMLast], netatom[NetLast];
+Bool domax = False;
 Bool otherwm, readin;
 Bool running = True;
 uint tagset[] = {1, 1}; /* after start, first tag is selected */
@@ -268,15 +265,16 @@ arrange(void) {
 
        for(c = clients; c; c = c->next)
                if(VISIBLE(c)) {
-                       unban(c);
                        if(!lt->arrange || c->isfloating)
                                resize(c, c->x, c->y, c->w, c->h, True);
                }
-               else
-                       ban(c);
+               else if(!c->isbanned) {
+                       XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
+                       c->isbanned = True;
+               }
 
        focus(NULL);
-       if(lt->arrange)
+       if(lt->arrange && !domax)
                lt->arrange();
        restack();
 }
@@ -296,14 +294,6 @@ attachstack(Client *c) {
 }
 
 void
-ban(Client *c) {
-       if(c->isbanned)
-               return;
-       XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
-       c->isbanned = True;
-}
-
-void
 buttonpress(XEvent *e) {
        uint i, x, mask;
        Client *c;
@@ -312,7 +302,7 @@ buttonpress(XEvent *e) {
        if(ev->window == barwin) {
                x = 0;
                for(i = 0; i < LENGTH(tags); i++) {
-                       x += textw(tags[i]);
+                       x += TEXTW(tags[i]);
                        if(ev->x < x) {
                                mask = 1 << i;
                                if(ev->button == Button1) {
@@ -330,23 +320,23 @@ buttonpress(XEvent *e) {
                                return;
                        }
                }
-               if((ev->x < x + blw) && ev->button == Button1) 
-                       togglelayout(NULL);
+               if(ev->x < x + blw) {
+                       if(ev->button == Button1) 
+                               togglelayout(NULL);
+                       else if(ev->button == Button3) 
+                               togglemax(NULL);
+               }
        }
        else if((c = getclient(ev->window))) {
                focus(c);
-               if(CLEANMASK(ev->state) != MODKEY)
+               if(CLEANMASK(ev->state) != MODKEY || domax)
                        return;
-               if(ev->button == Button1) {
-                       restack();
+               if(ev->button == Button1)
                        movemouse(c);
-               }
                else if(ev->button == Button2)
                        togglefloating(NULL);
-               else if(ev->button == Button3 && !c->isfixed) {
-                       restack();
+               else if(ev->button == Button3 && !c->isfixed)
                        resizemouse(c);
-               }
        }
 }
 
@@ -369,10 +359,9 @@ checkotherwm(void) {
 void
 cleanup(void) {
        close(STDIN_FILENO);
-       while(stack) {
-               unban(stack);
+       view(NULL);
+       while(stack)
                unmanage(stack);
-       }
        if(dc.font.set)
                XFreeFontSet(dpy, dc.font.set);
        else
@@ -499,7 +488,7 @@ drawbar(void) {
        dc.x = 0;
        for(c = stack; c && !VISIBLE(c); c = c->snext);
        for(i = 0; i < LENGTH(tags); i++) {
-               dc.w = textw(tags[i]);
+               dc.w = TEXTW(tags[i]);
                if(tagset[seltags] & 1 << i) {
                        drawtext(tags[i], dc.sel, isurgent(i));
                        drawsquare(c && c->tags & 1 << i, isoccupied(i), isurgent(i), dc.sel);
@@ -512,12 +501,12 @@ drawbar(void) {
        }
        if(blw > 0) {
                dc.w = blw;
-               drawtext(lt->symbol, dc.norm, False);
+               drawtext(lt->symbol, dc.norm, domax);
                x = dc.x + dc.w;
        }
        else
                x = dc.x;
-       dc.w = textw(stext);
+       dc.w = TEXTW(stext);
        dc.x = bw - dc.w;
        if(dc.x < x) {
                dc.x = x;
@@ -641,6 +630,10 @@ focus(Client *c) {
        }
        sel = c;
        if(c) {
+               if(domax) {
+                       XMoveResizeWindow(dpy, c->win, wx, wy, ww - 2 * c->bw, wh - 2 * c->bw);
+                       c->ismax = True;
+               }
                XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]);
                XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
        }
@@ -960,7 +953,6 @@ manage(Window w, XWindowAttributes *wa) {
        attach(c);
        attachstack(c);
        XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); /* some windows require this */
-       ban(c);
        XMapWindow(dpy, c->win);
        setclientstate(c, NormalState);
        arrange();
@@ -995,6 +987,7 @@ movemouse(Client *c) {
        Window dummy;
        XEvent ev;
 
+       restack();
        ocx = nx = c->x;
        ocy = ny = c->y;
        if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
@@ -1130,7 +1123,8 @@ resize(Client *c, int x, int y, int w, int h, Bool sizehints) {
                x = sx;
        if(y + h + 2 * c->bw < sy)
                y = sy;
-       if(c->x != x || c->y != y || c->w != w || c->h != h) {
+       if(c->x != x || c->y != y || c->w != w || c->h != h || c->isbanned || c->ismax) {
+               c->isbanned = c->ismax = False;
                c->x = wc.x = x;
                c->y = wc.y = y;
                c->w = wc.width = w;
@@ -1149,6 +1143,7 @@ resizemouse(Client *c) {
        int nw, nh;
        XEvent ev;
 
+       restack();
        ocx = c->x;
        ocy = c->y;
        if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
@@ -1196,9 +1191,9 @@ restack(void) {
        drawbar();
        if(!sel)
                return;
-       if(sel->isfloating || !lt->arrange)
+       if(domax || sel->isfloating || !lt->arrange)
                XRaiseWindow(dpy, sel->win);
-       if(lt->arrange) {
+       if(!domax && lt->arrange) {
                wc.stack_mode = Below;
                wc.sibling = barwin;
                for(c = stack; c; c = c->snext)
@@ -1317,7 +1312,6 @@ setmfact(const void *arg) {
        if(d < 0.1 || d > 0.9)
                return;
        mfact = d;
-       updatetilegeom();
        arrange();
 }
 
@@ -1367,7 +1361,7 @@ setup(void) {
 
        /* init bar */
        for(blw = i = 0; LENGTH(layouts) > 1 && i < LENGTH(layouts); i++) {
-               w = textw(layouts[i].symbol);
+               w = TEXTW(layouts[i].symbol);
                blw = MAX(blw, w);
        }
 
@@ -1439,14 +1433,9 @@ textnw(const char *text, uint len) {
        return XTextWidth(dc.font.xfont, text, len);
 }
 
-uint
-textw(const char *text) {
-       return textnw(text, strlen(text)) + dc.font.height;
-}
-
 void
 tile(void) {
-       int x, y, h, w;
+       int x, y, h, w, mx, my, mw, mh, tx, ty, tw, th;
        uint i, n;
        Client *c;
 
@@ -1454,6 +1443,18 @@ tile(void) {
        if(n == 0)
                return;
 
+       /* master area geometry */
+       mx = wx;
+       my = wy;
+       mw = mfact * ww;
+       mh = wh;
+
+       /* tile area geometry */
+       tx = mx + mw;
+       ty = wy;
+       tw = ww - mw;
+       th = wh;
+
        /* master */
        c = nexttiled(clients);
 
@@ -1532,6 +1533,12 @@ togglelayout(const void *arg) {
 }
 
 void
+togglemax(const void *arg) {
+       domax = !domax;
+       arrange();
+}
+
+void
 toggletag(const void *arg) {
        if(sel && (sel->tags ^ ((*(int *)arg) & TAGMASK))) {
                sel->tags ^= (*(int *)arg) & TAGMASK;
@@ -1548,14 +1555,6 @@ toggleview(const void *arg) {
 }
 
 void
-unban(Client *c) {
-       if(!c->isbanned)
-               return;
-       XMoveWindow(dpy, c->win, c->x, c->y);
-       c->isbanned = False;
-}
-
-void
 unmanage(Client *c) {
        XWindowChanges wc;
 
@@ -1622,11 +1621,6 @@ updategeom(void) {
        bx = wx;
        by = showbar ? (topbar ? wy - bh : wy + wh) : -bh;
        bw = ww;
-
-       /* update layout geometries */
-       for(i = 0; i < LENGTH(layouts); i++)
-               if(layouts[i].updategeom)
-                       layouts[i].updategeom();
 }
 
 void
@@ -1682,21 +1676,6 @@ updatesizehints(Client *c) {
 }
 
 void
-updatetilegeom(void) {
-       /* master area geometry */
-       mx = wx;
-       my = wy;
-       mw = mfact * ww;
-       mh = wh;
-
-       /* tile area geometry */
-       tx = mx + mw;
-       ty = wy;
-       tw = ww - mw;
-       th = wh;
-}
-
-void
 updatetitle(Client *c) {
        if(!gettextprop(c->win, netatom[NetWMName], c->name, sizeof c->name))
                gettextprop(c->win, wmatom[WMName], c->name, sizeof c->name);