Mercurial > aewl
changeset 767:706991d15451
removed rexexp for old strstr matching; simplifications
author | meillo@marmaro.de |
---|---|
date | Fri, 05 Dec 2008 20:50:31 +0100 |
parents | 3f7c68a720b5 |
children | a1c6805aa018 |
files | aewl.c config.h |
diffstat | 2 files changed, 34 insertions(+), 63 deletions(-) [+] |
line wrap: on
line diff
--- 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 <errno.h> #include <locale.h> -#include <regex.h> #include <stdio.h> #include <stdarg.h> #include <stdlib.h> @@ -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; - - if(rreg) - return; - 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; - } - } -} - -void -settag(Client *c, Client *trans) { - char prop[512]; - unsigned int i; - regmatch_t tmp; - Bool matched = (trans != NULL); XClassHint ch = { 0 }; - if(matched) { + if(trans) { 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; + return; + } + c->tag = seltag; /* default */ + XGetClassHint(dpy, c->win, &ch); + len = sizeof rule / sizeof rule[0]; + for(i = 0; i < len; i++) { + 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; } - if(ch.res_class) - XFree(ch.res_class); - if(ch.res_name) - XFree(ch.res_name); + break; + } } - 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);
--- 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 }, \ };