JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
removed Geom stuff, introduced updategeom() again, still view is somewhat broken?
[dwm.git] / dwm.c
diff --git a/dwm.c b/dwm.c
index 997a220..6ef2ab2 100644 (file)
--- a/dwm.c
+++ b/dwm.c
 #include <X11/Xutil.h>
 
 /* macros */
-#define MAX(a, b) ((a)>(b)?(a):(b))
-#define MIN(a, b) ((a)<(b)?(a):(b))
-#define BUTTONMASK             (ButtonPressMask|ButtonReleaseMask)
-#define CLEANMASK(mask)                (mask & ~(numlockmask|LockMask))
-#define LENGTH(x)              (sizeof x / sizeof x[0])
-#define MAXTAGLEN              16
-#define MOUSEMASK              (BUTTONMASK|PointerMotionMask)
-#define DEFGEOM(GEONAME,BX,BY,BW,WX,WY,WW,WH,MX,MY,MW,MH,TX,TY,TW,TH,MOX,MOY,MOW,MOH) \
-void GEONAME(void) { \
-       bx = (BX); by = (BY); bw = (BW); \
-       wx = (WX); wy = (WY); ww = (WW); wh = (WH); \
-       mx = (MX); my = (MY); mw = (MW); mh = (MH); \
-       tx = (TX); ty = (TY); tw = (TW); th = (TH); \
-       mox = (MOX); moy = (MOY); mow = (MOW); moh = (MOH); \
-}
+#define MAX(a, b)      ((a) > (b) ? (a) : (b))
+#define MIN(a, b)      ((a) < (b) ? (a) : (b))
+#define BUTTONMASK     (ButtonPressMask|ButtonReleaseMask)
+#define CLEANMASK(mask)        (mask & ~(numlockmask|LockMask))
+#define LENGTH(x)      (sizeof x / sizeof x[0])
+#define MAXTAGLEN      16
+#define MOUSEMASK      (BUTTONMASK|PointerMotionMask)
 
 /* enums */
 enum { CurNormal, CurResize, CurMove, CurLast };       /* cursor */
@@ -97,11 +89,6 @@ typedef struct {
 } DC; /* draw context */
 
 typedef struct {
-       const char *symbol;
-       void (*apply)(void);
-} Geom;
-
-typedef struct {
        unsigned long mod;
        KeySym keysym;
        void (*func)(const char *arg);
@@ -160,7 +147,7 @@ void initfont(const char *fontstr);
 Bool isoccupied(unsigned int t);
 Bool isprotodel(Client *c);
 Bool isurgent(unsigned int t);
-Bool isvisible(Client *c);
+Bool isvisible(Client *c, Bool *cmp);
 void keypress(XEvent *e);
 void killclient(const char *arg);
 void manage(Window w, XWindowAttributes *wa);
@@ -178,7 +165,6 @@ void restack(void);
 void run(void);
 void scan(void);
 void setclientstate(Client *c, long state);
-void setgeom(const char *arg);
 void setlayout(const char *arg);
 void setmfact(const char *arg);
 void setup(void);
@@ -198,7 +184,8 @@ void toggleview(const char *arg);
 void unban(Client *c);
 void unmanage(Client *c);
 void unmapnotify(XEvent *e);
-void updatebarpos(void);
+void updatebar(void);
+void updategeom(void);
 void updatesizehints(Client *c);
 void updatetitle(Client *c);
 void updatewmhints(Client *c);
@@ -213,7 +200,7 @@ void zoom(const char *arg);
 char stext[256];
 int screen, sx, sy, sw, sh;
 int (*xerrorxlib)(Display *, XErrorEvent *);
-int bx, by, bw, bh, blw, bgw, mx, my, mw, mh, mox, moy, mow, moh, tx, ty, tw, th, wx, wy, ww, wh;
+int bx, by, bw, bh, blw, mx, my, mw, mh, tx, ty, tw, th, wx, wy, ww, wh;
 int seltags = 0;
 double mfact;
 unsigned int numlockmask = 0;
@@ -241,8 +228,6 @@ Client *stack = NULL;
 Cursor cursor[CurLast];
 Display *dpy;
 DC dc = {0};
-Geom geoms[];
-Geom *geom = geoms;
 Layout layouts[];
 Layout *lt = layouts;
 Window root, barwin;
@@ -287,7 +272,7 @@ arrange(void) {
        Client *c;
 
        for(c = clients; c; c = c->next)
-               if(isvisible(c)) {
+               if(isvisible(c, NULL)) {
                        unban(c);
                        if(lt->isfloating || c->isfloating)
                                resize(c, c->fx, c->fy, c->fw, c->fh, True);
@@ -330,14 +315,10 @@ buttonpress(XEvent *e) {
        XButtonPressedEvent *ev = &e->xbutton;
 
        if(ev->window == barwin) {
-               if((ev->x < bgw) && ev->button == Button1) {
-                       setgeom(NULL);
-                       return;
-               }
-               x = bgw;
+               x = 0;
                for(i = 0; i < LENGTH(tags); i++) {
                        x += textw(tags[i]);
-                       if(ev->x >= bgw && ev->x < x) {
+                       if(ev->x < x) {
                                if(ev->button == Button1) {
                                        if(ev->state & MODKEY)
                                                tag(tags[i]);
@@ -440,7 +421,9 @@ configurenotify(XEvent *e) {
        if(ev->window == root && (ev->width != sw || ev->height != sh)) {
                sw = ev->width;
                sh = ev->height;
-               setgeom(geom->symbol);
+               updategeom();
+               updatebar();
+               arrange();
        }
 }
 
@@ -469,7 +452,7 @@ configurerequest(XEvent *e) {
                        if((ev->value_mask & (CWX|CWY))
                        && !(ev->value_mask & (CWWidth|CWHeight)))
                                configure(c);
-                       if(isvisible(c))
+                       if(isvisible(c, NULL))
                                XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
                }
                else
@@ -531,12 +514,7 @@ drawbar(void) {
        Client *c;
 
        dc.x = 0;
-       if(bgw > 0) {
-               dc.w = bgw;
-               drawtext(geom->symbol, dc.norm, False);
-               dc.x += bgw;
-       }
-       for(c = stack; c && !isvisible(c); c = c->snext);
+       for(c = stack; c && !isvisible(c, NULL); c = c->snext);
        for(i = 0; i < LENGTH(tags); i++) {
                dc.w = textw(tags[i]);
                if(tagset[seltags][i]) {
@@ -676,8 +654,8 @@ expose(XEvent *e) {
 
 void
 focus(Client *c) {
-       if(!c || (c && !isvisible(c)))
-               for(c = stack; c && !isvisible(c); c = c->snext);
+       if(!c || (c && !isvisible(c, NULL)))
+               for(c = stack; c && !isvisible(c, NULL); c = c->snext);
        if(sel && sel != c) {
                grabbuttons(sel, False);
                XSetWindowBorder(dpy, sel->win, dc.norm[ColBorder]);
@@ -711,9 +689,9 @@ focusnext(const char *arg) {
 
        if(!sel)
                return;
-       for(c = sel->next; c && !isvisible(c); c = c->next);
+       for(c = sel->next; c && !isvisible(c, arg ? sel->tags : NULL); c = c->next);
        if(!c)
-               for(c = clients; c && !isvisible(c); c = c->next);
+               for(c = clients; c && !isvisible(c, arg ? sel->tags : NULL); c = c->next);
        if(c) {
                focus(c);
                restack();
@@ -726,10 +704,10 @@ focusprev(const char *arg) {
 
        if(!sel)
                return;
-       for(c = sel->prev; c && !isvisible(c); c = c->prev);
+       for(c = sel->prev; c && !isvisible(c, arg ? sel->tags : NULL); c = c->prev);
        if(!c) {
                for(c = clients; c && c->next; c = c->next);
-               for(; c && !isvisible(c); c = c->prev);
+               for(; c && !isvisible(c, arg ? sel->tags : NULL); c = c->prev);
        }
        if(c) {
                focus(c);
@@ -930,11 +908,13 @@ isurgent(unsigned int t) {
 }
 
 Bool
-isvisible(Client *c) {
+isvisible(Client *c, Bool *cmp) {
        unsigned int i;
 
+       if(!cmp)
+               cmp = tagset[seltags];
        for(i = 0; i < LENGTH(tags); i++)
-               if(c->tags[i] && tagset[seltags][i])
+               if(c->tags[i] && cmp[i])
                        return True;
        return False;
 }
@@ -1061,8 +1041,8 @@ monocle(void) {
        Client *c;
 
        for(c = clients; c; c = c->next)
-               if((lt->isfloating || !c->isfloating) &&  isvisible(c))
-                       resize(c, mox, moy, mow - 2 * c->bw, moh - 2 * c->bw, RESIZEHINTS);
+               if((lt->isfloating || !c->isfloating) &&  isvisible(c, NULL))
+                       resize(c, wx, wy, ww - 2 * c->bw, wh - 2 * c->bw, RESIZEHINTS);
 }
 
 void
@@ -1115,7 +1095,7 @@ movemouse(Client *c) {
 
 Client *
 nexttiled(Client *c) {
-       for(; c && (c->isfloating || !isvisible(c)); c = c->next);
+       for(; c && (c->isfloating || !isvisible(c, NULL)); c = c->next);
        return c;
 }
 
@@ -1292,7 +1272,7 @@ restack(void) {
                wc.stack_mode = Below;
                wc.sibling = barwin;
                for(c = stack; c; c = c->snext)
-                       if(!c->isfloating && isvisible(c)) {
+                       if(!c->isfloating && isvisible(c, NULL)) {
                                XConfigureWindow(dpy, c->win, CWSibling|CWStackMode, &wc);
                                wc.sibling = c->win;
                        }
@@ -1397,27 +1377,6 @@ setclientstate(Client *c, long state) {
 }
 
 void
-setgeom(const char *arg) {
-       unsigned int i;
-
-       if(!arg) {
-               if(++geom == &geoms[LENGTH(geoms)])
-                       geom = &geoms[0];
-       }
-       else {
-               for(i = 0; i < LENGTH(geoms); i++)
-                       if(!strcmp(geoms[i].symbol, arg))
-                               break;
-               if(i == LENGTH(geoms))
-                       return;
-               geom = &geoms[i];
-       }
-       geom->apply();
-       updatebarpos();
-       arrange();
-}
-
-void
 setlayout(const char *arg) {
        unsigned int i;
 
@@ -1455,7 +1414,8 @@ setmfact(const char *arg) {
                        return;
                mfact = d;
        }
-       setgeom(geom->symbol);
+       updategeom();
+       arrange();
 }
 
 void
@@ -1467,15 +1427,14 @@ setup(void) {
        screen = DefaultScreen(dpy);
        root = RootWindow(dpy, screen);
        initfont(FONT);
-
-       /* apply default geometry */
        sx = 0;
        sy = 0;
        sw = DisplayWidth(dpy, screen);
        sh = DisplayHeight(dpy, screen);
        bh = dc.font.height + 2;
-       mfact = MFACT;
-       geom->apply();
+
+       /* update geometry */
+       updategeom();
 
        /* init atoms */
        wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
@@ -1515,10 +1474,6 @@ setup(void) {
                w = textw(layouts[i].symbol);
                blw = MAX(blw, w);
        }
-       for(bgw = i = 0; LENGTH(geoms) > 1 && i < LENGTH(geoms); i++) {
-               w = textw(geoms[i].symbol);
-               bgw = MAX(bgw, w);
-       }
 
        wa.override_redirect = 1;
        wa.background_pixmap = ParentRelative;
@@ -1631,7 +1586,7 @@ tilemaster(unsigned int n) {
        Client *c = nexttiled(clients);
 
        if(n == 1)
-               tileresize(c, mox, moy, mow - 2 * c->bw, moh - 2 * c->bw);
+               tileresize(c, wx, wy, ww - 2 * c->bw, wh - 2 * c->bw);
        else
                tileresize(c, mx, my, mw - 2 * c->bw, mh - 2 * c->bw);
        return c;
@@ -1749,7 +1704,7 @@ unmapnotify(XEvent *e) {
 }
 
 void
-updatebarpos(void) {
+updatebar(void) {
 
        if(dc.drawable != 0)
                XFreePixmap(dpy, dc.drawable);
@@ -1758,6 +1713,34 @@ updatebarpos(void) {
 }
 
 void
+updategeom(void) {
+
+       /* bar geometry */
+       bx = 0;
+       by = 0;
+       bw = sw;
+
+       /* window area geometry */
+       wx = sx;
+       wy = sy;
+       ww = sw;
+       sh = sh - bh;
+
+       /* master area geometry */
+       mfact = MFACT;
+       mx = wx;
+       my = wy;
+       mw = mfact * ww;
+       mh = wh;
+
+       /* tile area geometry */
+       tx = mx + mw;
+       ty = wy;
+       tw = ww - mw;
+       th = wh;
+}
+
+void
 updatesizehints(Client *c) {
        long msize;
        XSizeHints size;
@@ -1910,4 +1893,3 @@ main(int argc, char *argv[]) {
        XCloseDisplay(dpy);
        return 0;
 }
-