JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
removed the string-based setgeom approach, introduced a new Geom type instead and...
[dwm.git] / dwm.c
diff --git a/dwm.c b/dwm.c
index a54329a..f83e800 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);
@@ -99,7 +112,9 @@ typedef struct {
 } Layout; 
 
 typedef struct {
-       const char *prop;
+       const char *class;
+       const char *instance;
+       const char *title;
        const char *tag;
        Bool isfloating;
 } Rule;
@@ -161,7 +176,7 @@ void restack(void);
 void run(void);
 void scan(void);
 void setclientstate(Client *c, long state);
-void setdefaultgeoms(void);
+void setgeom(const char *arg);
 void setlayout(const char *arg);
 void setup(void);
 void spawn(const char *arg);
@@ -222,9 +237,9 @@ Client *stack = NULL;
 Cursor cursor[CurLast];
 Display *dpy;
 DC dc = {0};
+Geom *geom = NULL;
 Layout *lt = NULL;
 Window root, barwin;
-void (*setgeoms)(void) = setdefaultgeoms;
 
 /* configuration, allows nested code to access above variables */
 #include "config.h"
@@ -244,9 +259,9 @@ applyrules(Client *c) {
        XGetClassHint(dpy, c->win, &ch);
        for(i = 0; i < LENGTH(rules); i++) {
                r = &rules[i];
-               if(strstr(c->name, r->prop)
-               || (ch.res_class && strstr(ch.res_class, r->prop))
-               || (ch.res_name && strstr(ch.res_name, r->prop)))
+               if(strstr(c->name, r->title)
+               || (ch.res_class && r->class && strstr(ch.res_class, r->class))
+               || (ch.res_name && r->instance && strstr(ch.res_name, r->instance)))
                {
                        c->isfloating = r->isfloating;
                        if(r->tag) {
@@ -408,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
@@ -1051,7 +1063,7 @@ maprequest(XEvent *e) {
 }
 
 void
-monocle(void) { 
+monocle(void) {
        Client *c;
 
        for(c = clients; c; c = c->next)
@@ -1390,43 +1402,18 @@ setclientstate(Client *c, long state) {
 }
 
 void
-setdefaultgeoms(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
@@ -1463,8 +1450,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);