# HG changeset patch # User meillo@marmaro.de # Date 1228506631 -3600 # Node ID 706991d154519ac684338e3dfc4f852cef976b45 # Parent 3f7c68a720b526775dbaab9a4131e0694c379bd6 removed rexexp for old strstr matching; simplifications diff -r 3f7c68a720b5 -r 706991d15451 aewl.c --- a/aewl.c Fri Dec 05 19:43:56 2008 +0100 +++ b/aewl.c Fri Dec 05 20:50:31 2008 +0100 @@ -44,7 +44,6 @@ #include "config.h" #include #include -#include #include #include #include @@ -103,15 +102,13 @@ }; typedef struct { - const char *clpattern; + const char* class; + const char* instance; + const char* title; int tag; Bool isfloat; } Rule; -typedef struct { - regex_t *clregex; -} RReg; - typedef struct { unsigned long mod; @@ -151,7 +148,6 @@ static int (*xerrorxlib)(Display *, XErrorEvent *); static Bool otherwm, readin; -static RReg *rreg = NULL; static unsigned int len = 0; @@ -184,7 +180,6 @@ int xerror(Display *dsply, XErrorEvent *ee); /* dwm's X error handler */ /* tag.c */ -void initrregs(void); /* initialize regexps of rules defined in config.h */ Client *getnext(Client *c); /* returns next visible client */ void settag(Client *c, Client *trans); /* sets tag of c */ @@ -567,60 +562,36 @@ } void -initrregs(void) { +settag(Client *c, Client *trans) { unsigned int i; - regex_t *reg; + XClassHint ch = { 0 }; - if(rreg) + if(trans) { + c->tag = trans->tag; return; + } + c->tag = seltag; /* default */ + XGetClassHint(dpy, c->win, &ch); len = sizeof rule / sizeof rule[0]; - rreg = emallocz(len * sizeof(RReg)); for(i = 0; i < len; i++) { - if(rule[i].clpattern) { - reg = emallocz(sizeof(regex_t)); - if(regcomp(reg, rule[i].clpattern, REG_EXTENDED)) - free(reg); - else - rreg[i].clregex = reg; + if((rule[i].title && strstr(c->name, rule[i].title)) + || (ch.res_class && rule[i].class && strstr(ch.res_class, rule[i].class)) + || (ch.res_name && rule[i].instance && strstr(ch.res_name, rule[i].instance))) { + c->isfloat = rule[i].isfloat; + if (rule[i].tag < 0) { + c->tag = seltag; + } else if (rule[i].tag) { + c->tag = True; + } else { + c->tag = False; + } + break; } } -} - -void -settag(Client *c, Client *trans) { - char prop[512]; - unsigned int i; - regmatch_t tmp; - Bool matched = (trans != NULL); - XClassHint ch = { 0 }; - - if(matched) { - c->tag = trans->tag; - } else { - XGetClassHint(dpy, c->win, &ch); - snprintf(prop, sizeof prop, "%s:%s:%s", - ch.res_class ? ch.res_class : "", - ch.res_name ? ch.res_name : "", c->name); - for(i = 0; i < len && !matched; i++) - if(rreg[i].clregex && !regexec(rreg[i].clregex, prop, 1, &tmp, 0)) { - c->isfloat = rule[i].isfloat; - if (rule[i].tag < 0) { - c->tag = seltag; - } else if (rule[i].tag) { - c->tag = True; - } else { - c->tag = False; - } - matched = True; - } - if(ch.res_class) - XFree(ch.res_class); - if(ch.res_name) - XFree(ch.res_name); - } - if(!matched) { - c->tag = seltag; - } + if(ch.res_class) + XFree(ch.res_class); + if(ch.res_name) + XFree(ch.res_name); } void @@ -1592,7 +1563,6 @@ wa.cursor = cursor[CurNormal]; XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); grabkeys(); - initrregs(); seltag = True; /* style */ dc.norm[ColBG] = getcolor(NORMBGCOLOR); diff -r 3f7c68a720b5 -r 706991d15451 config.h --- a/config.h Fri Dec 05 19:43:56 2008 +0100 +++ b/config.h Fri Dec 05 20:50:31 2008 +0100 @@ -43,10 +43,11 @@ * xprop | awk -F '"' '/^WM_CLASS/ { printf("%s:%s:",$4,$2) }; /^WM_NAME/ { printf("%s\n",$2) }' */ #define RULES \ static Rule rule[] = { \ - /* class:instance:title regex, tag (1=tag/0=untag/-1=curr), isfloat */ \ - { "URxvt.*", 0, False }, \ - { "MPlayer.*", -1, True }, \ - { "qiv.*", -1, False }, \ - { "Gimp.*", 1, True }, \ - { ".*", 1, False }, \ + /* class, instance, title, tag (1=tag/0=untag/-1=curr), isfloat */ \ + { "URxvt", NULL, NULL, 0, False }, \ + { "urxvt", NULL, NULL, 0, False }, \ + { "MPlayer", NULL, NULL, -1, True }, \ + { NULL, "qiv", NULL, -1, False }, \ + { "Gimp", NULL, NULL, 1, True }, \ + { "", "", "", 1, False }, \ };