dwm-meillo
changeset 191:56fee1dc9d53
switched to regexp matching for Rules
author | arg@10ksloc.org |
---|---|
date | Fri, 04 Aug 2006 14:40:32 +0200 |
parents | 713dcc7d2c42 |
children | 30b321919a93 |
files | config.arg.h config.default.h config.mk dwm.h main.c tag.c |
diffstat | 6 files changed, 65 insertions(+), 31 deletions(-) [+] |
line diff
1.1 --- a/config.arg.h Fri Aug 04 13:42:40 2006 +0200 1.2 +++ b/config.arg.h Fri Aug 04 14:40:32 2006 +0200 1.3 @@ -52,11 +52,10 @@ 1.4 }; 1.5 1.6 #define RULES \ 1.7 - const unsigned int two[] = { 2 }; \ 1.8 static Rule rule[] = { \ 1.9 - /* class:instance tags isfloat */ \ 1.10 - { "Firefox.*", two, False }, \ 1.11 - { "Gimp.*", NULL, True}, \ 1.12 - { "MPlayer.*", NULL, True}, \ 1.13 - { "Acroread.*", NULL, True}, \ 1.14 + /* class:instance regex tags regex isfloat */ \ 1.15 + { "Firefox.*", "net", False }, \ 1.16 + { "Gimp.*", NULL, True}, \ 1.17 + { "MPlayer.*", NULL, True}, \ 1.18 + { "Acroread.*", NULL, True}, \ 1.19 };
2.1 --- a/config.default.h Fri Aug 04 13:42:40 2006 +0200 2.2 +++ b/config.default.h Fri Aug 04 14:40:32 2006 +0200 2.3 @@ -47,9 +47,8 @@ 2.4 }; 2.5 2.6 #define RULES \ 2.7 - const unsigned int two[] = { 2 }; \ 2.8 static Rule rule[] = { \ 2.9 - /* class:instance tags isfloat */ \ 2.10 - { "Firefox.*", two, False }, \ 2.11 - { "Gimp.*", NULL, True}, \ 2.12 + /* class:instance regex tags regex isfloat */ \ 2.13 + { "Firefox.*", "2", False }, \ 2.14 + { "Gimp.*", NULL, True}, \ 2.15 };
3.1 --- a/config.mk Fri Aug 04 13:42:40 2006 +0200 3.2 +++ b/config.mk Fri Aug 04 14:40:32 2006 +0200 3.3 @@ -15,10 +15,10 @@ 3.4 LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 3.5 3.6 # flags 3.7 -CFLAGS = -O3 ${INCS} -DVERSION=\"${VERSION}\" 3.8 -LDFLAGS = ${LIBS} 3.9 -#CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\" 3.10 -#LDFLAGS = -g ${LIBS} 3.11 +#CFLAGS = -O3 ${INCS} -DVERSION=\"${VERSION}\" 3.12 +#LDFLAGS = ${LIBS} 3.13 +CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\" 3.14 +LDFLAGS = -g ${LIBS} 3.15 3.16 # compiler 3.17 CC = cc
4.1 --- a/dwm.h Fri Aug 04 13:42:40 2006 +0200 4.2 +++ b/dwm.h Fri Aug 04 14:40:32 2006 +0200 4.3 @@ -121,6 +121,7 @@ 4.4 extern void appendtag(Arg *arg); 4.5 extern void dofloat(Arg *arg); 4.6 extern void dotile(Arg *arg); 4.7 +extern void initrregs(); 4.8 extern Client *getnext(Client *c); 4.9 extern Client *getprev(Client *c); 4.10 extern void replacetag(Arg *arg);
5.1 --- a/main.c Fri Aug 04 13:42:40 2006 +0200 5.2 +++ b/main.c Fri Aug 04 14:40:32 2006 +0200 5.3 @@ -210,6 +210,7 @@ 5.4 cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur); 5.5 5.6 grabkeys(); 5.7 + initrregs(); 5.8 5.9 for(ntags = 0; tags[ntags]; ntags++); 5.10
6.1 --- a/tag.c Fri Aug 04 13:42:40 2006 +0200 6.2 +++ b/tag.c Fri Aug 04 14:40:32 2006 +0200 6.3 @@ -5,21 +5,31 @@ 6.4 #include "dwm.h" 6.5 #include <regex.h> 6.6 #include <stdio.h> 6.7 +#include <stdlib.h> 6.8 #include <string.h> 6.9 #include <sys/types.h> 6.10 #include <X11/Xutil.h> 6.11 6.12 -/* static */ 6.13 6.14 typedef struct { 6.15 - const char *pattern; 6.16 - const unsigned int *tags; 6.17 + const char *clpattern; 6.18 + const char *tpattern; 6.19 Bool isfloat; 6.20 } Rule; 6.21 6.22 +typedef struct { 6.23 + regex_t *clregex; 6.24 + regex_t *tregex; 6.25 +} RReg; 6.26 + 6.27 +/* static */ 6.28 + 6.29 TAGS 6.30 RULES 6.31 6.32 +static RReg *rreg = NULL; 6.33 +static unsigned int len = 0; 6.34 + 6.35 void (*arrange)(Arg *) = DEFMODE; 6.36 6.37 /* extern */ 6.38 @@ -138,6 +148,35 @@ 6.39 } 6.40 6.41 void 6.42 +initrregs() 6.43 +{ 6.44 + unsigned int i; 6.45 + regex_t *reg; 6.46 + 6.47 + if(rreg) 6.48 + return; 6.49 + len = sizeof(rule) / sizeof(rule[0]); 6.50 + rreg = emallocz(len * sizeof(RReg)); 6.51 + 6.52 + for(i = 0; i < len; i++) { 6.53 + if(rule[i].clpattern) { 6.54 + reg = emallocz(sizeof(regex_t)); 6.55 + if(regcomp(reg, rule[i].clpattern, 0)) 6.56 + free(reg); 6.57 + else 6.58 + rreg[i].clregex = reg; 6.59 + } 6.60 + if(rule[i].tpattern) { 6.61 + reg = emallocz(sizeof(regex_t)); 6.62 + if(regcomp(reg, rule[i].tpattern, 0)) 6.63 + free(reg); 6.64 + else 6.65 + rreg[i].tregex = reg; 6.66 + } 6.67 + } 6.68 +} 6.69 + 6.70 +void 6.71 replacetag(Arg *arg) 6.72 { 6.73 int i; 6.74 @@ -154,9 +193,7 @@ 6.75 settags(Client *c) 6.76 { 6.77 char classinst[256]; 6.78 - static unsigned int len = sizeof(rule) / sizeof(rule[0]); 6.79 - unsigned int i, j, n; 6.80 - regex_t regex; 6.81 + unsigned int i, j; 6.82 regmatch_t tmp; 6.83 Bool matched = False; 6.84 XClassHint ch; 6.85 @@ -165,19 +202,16 @@ 6.86 snprintf(classinst, sizeof(classinst), "%s:%s", 6.87 ch.res_class ? ch.res_class : "", 6.88 ch.res_name ? ch.res_name : ""); 6.89 - for(i = 0; !matched && i < len; i++) { 6.90 - if(!regcomp(®ex, rule[i].pattern, 0)) { 6.91 - if(!regexec(®ex, classinst, 1, &tmp, 0)) { 6.92 - n = rule[i].tags ? 6.93 - sizeof(rule[i].tags) / sizeof(rule[i].tags[0]) : 0; 6.94 - matched = n != 0; 6.95 - for(j = 0; j < n; j++) 6.96 - c->tags[rule[i].tags[j]] = True; 6.97 - c->isfloat = rule[i].isfloat; 6.98 + for(i = 0; !matched && i < len; i++) 6.99 + if(rreg[i].clregex && !regexec(rreg[i].clregex, classinst, 1, &tmp, 0)) { 6.100 + c->isfloat = rule[i].isfloat; 6.101 + for(j = 0; rreg[i].tregex && j < ntags; j++) { 6.102 + if(!regexec(rreg[i].tregex, tags[j], 1, &tmp, 0)) { 6.103 + matched = True; 6.104 + c->tags[j] = True; 6.105 + } 6.106 } 6.107 - regfree(®ex); 6.108 } 6.109 - } 6.110 if(ch.res_class) 6.111 XFree(ch.res_class); 6.112 if(ch.res_name)