X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=dwm.c;h=f83e800a7d86d8e2f7a6ef0332ba1e35a1676636;hb=aa2395b6a81475b44dd74618fb7f0b40305e10bb;hp=0894c651c9b36615e0e858df585b132df40d9f1f;hpb=831428b00cf0bb6c7830c2178c8d13213f29b2db;p=dwm.git diff --git a/dwm.c b/dwm.c index 0894c65..f83e800 100644 --- a/dwm.c +++ b/dwm.c @@ -46,6 +46,14 @@ #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); @@ -96,11 +109,12 @@ typedef struct { const char *symbol; void (*arrange)(void); Bool isfloating; -} Layout; /* TODO: layout should keep an auxilliary pointer to its Geometry, - instead of having all those layout specific vars globally */ +} Layout; typedef struct { - const char *prop; + const char *class; + const char *instance; + const char *title; const char *tag; Bool isfloating; } Rule; @@ -162,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); @@ -223,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" @@ -245,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) { @@ -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 @@ -1052,7 +1063,7 @@ maprequest(XEvent *e) { } void -monocle(void) { +monocle(void) { Client *c; for(c = clients; c; c = c->next) @@ -1391,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 @@ -1464,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);