JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
geoms are now drawed in the status bar
[dwm.git] / dwm.c
diff --git a/dwm.c b/dwm.c
index 3f896dc..6b46911 100644 (file)
--- a/dwm.c
+++ b/dwm.c
 #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); \
+}
 
 /* enums */
 enum { CurNormal, CurResize, CurMove, CurLast };       /* cursor */
@@ -86,6 +94,11 @@ 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);
@@ -163,7 +176,7 @@ void restack(void);
 void run(void);
 void scan(void);
 void setclientstate(Client *c, long state);
-void setdefgeoms(void);
+void setgeom(const char *arg);
 void setlayout(const char *arg);
 void setup(void);
 void spawn(const char *arg);
@@ -197,7 +210,7 @@ void zoom(const char *arg);
 char stext[256], buf[256];
 int screen, sx, sy, sw, sh;
 int (*xerrorxlib)(Display *, XErrorEvent *);
-int bx, by, bw, bh, blw, mx, my, mw, mh, mox, moy, mow, moh, tx, ty, tw, th, wx, wy, ww, wh;
+int bx, by, bw, bh, blw, bgw, mx, my, mw, mh, mox, moy, mow, moh, tx, ty, tw, th, wx, wy, ww, wh;
 unsigned int numlockmask = 0;
 void (*handler[LASTEvent]) (XEvent *) = {
        [ButtonPress] = buttonpress,
@@ -224,6 +237,7 @@ Client *stack = NULL;
 Cursor cursor[CurLast];
 Display *dpy;
 DC dc = {0};
+Geom *geom = NULL;
 Layout *lt = NULL;
 Window root, barwin;
 
@@ -308,10 +322,10 @@ buttonpress(XEvent *e) {
        XButtonPressedEvent *ev = &e->xbutton;
 
        if(ev->window == barwin) {
-               x = 0;
+               x = bgw;
                for(i = 0; i < LENGTH(tags); i++) {
                        x += textw(tags[i]);
-                       if(ev->x < x) {
+                       if(ev->x > bgw && ev->x < x) {
                                if(ev->button == Button1) {
                                        if(ev->state & MODKEY)
                                                tag(tags[i]);
@@ -409,11 +423,8 @@ void
 configurenotify(XEvent *e) {
        XConfigureEvent *ev = &e->xconfigure;
 
-       if(ev->window == root && (ev->width != sw || ev->height != sh)) {
-               setgeoms();
-               updatebarpos();
-               arrange();
-       }
+       if(ev->window == root && (ev->width != sw || ev->height != sh))
+               setgeom(NULL);
 }
 
 void
@@ -503,6 +514,9 @@ drawbar(void) {
        Client *c;
 
        dc.x = 0;
+       dc.w = bgw;
+       drawtext(geom->symbol, dc.norm, False);
+       dc.x += bgw;
        for(c = stack; c && !isvisible(c); c = c->snext);
        for(i = 0; i < LENGTH(tags); i++) {
                dc.w = textw(tags[i]);
@@ -843,7 +857,7 @@ unsigned int
 idxoftag(const char *t) {
        unsigned int i;
 
-       for(i = 0; (i < LENGTH(tags)) && (tags[i] != t); i++);
+       for(i = 0; (i < LENGTH(tags)) && strcmp(tags[i], t); i++);
        return (i < LENGTH(tags)) ? i : 0;
 }
 
@@ -1391,43 +1405,18 @@ setclientstate(Client *c, long state) {
 }
 
 void
-setdefgeoms(void) {
-
-       /* screen dimensions */
-       sx = 0;
-       sy = 0;
-       sw = DisplayWidth(dpy, screen);
-       sh = DisplayHeight(dpy, screen);
-
-       /* bar position */
-       bx = sx;
-       by = sy;
-       bw = sw;
-       bh = dc.font.height + 2;
-
-       /* window area */
-       wx = sx;
-       wy = sy + bh;
-       ww = sw;
-       wh = sh - bh;
-
-       /* master area */
-       mx = wx;
-       my = wy;
-       mw = ((float)sw) * 0.55;
-       mh = wh;
-
-       /* tile area */
-       tx = mx + mw;
-       ty = wy;
-       tw = ww - mw;
-       th = wh;
+setgeom(const char *arg) {
+       unsigned int i;
 
-       /* monocle area */
-       mox = wx;
-       moy = wy;
-       mow = ww;
-       moh = wh;
+       for(i = 0; arg && i < LENGTH(geoms); i++)
+               if(!strcmp(geoms[i].symbol, arg))
+                       break;
+       if(i == LENGTH(geoms))
+               return;
+       geom = &geoms[i];
+       geom->apply();
+       updatebarpos();
+       arrange();
 }
 
 void
@@ -1464,8 +1453,14 @@ setup(void) {
        root = RootWindow(dpy, screen);
        initfont(FONT);
 
-       /* apply default geometries */
-       setgeoms();
+       /* apply default geometry */
+       sx = 0;
+       sy = 0;
+       sw = DisplayWidth(dpy, screen);
+       sh = DisplayHeight(dpy, screen);
+       bh = dc.font.height + 2;
+       geom = &geoms[0];
+       geom->apply();
 
        /* init atoms */
        wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
@@ -1509,6 +1504,11 @@ setup(void) {
                if(i > blw)
                        blw = i;
        }
+       for(bgw = i = 0; i < LENGTH(geoms); i++) {
+               i = textw(geoms[i].symbol);
+               if(i > bgw)
+                       bgw = i;
+       }
 
        wa.override_redirect = 1;
        wa.background_pixmap = ParentRelative;