summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--config.arg.h11
-rw-r--r--config.default.h7
-rw-r--r--config.mk8
-rw-r--r--dwm.h1
-rw-r--r--main.c1
-rw-r--r--tag.c68
6 files changed, 65 insertions, 31 deletions
diff --git a/config.arg.h b/config.arg.h
index 4297376..d391f9e 100644
--- a/config.arg.h
+++ b/config.arg.h
@@ -52,11 +52,10 @@ static Key key[] = { \
52}; 52};
53 53
54#define RULES \ 54#define RULES \
55 const unsigned int two[] = { 2 }; \
56static Rule rule[] = { \ 55static Rule rule[] = { \
57 /* class:instance tags isfloat */ \ 56 /* class:instance regex tags regex isfloat */ \
58 { "Firefox.*", two, False }, \ 57 { "Firefox.*", "net", False }, \
59 { "Gimp.*", NULL, True}, \ 58 { "Gimp.*", NULL, True}, \
60 { "MPlayer.*", NULL, True}, \ 59 { "MPlayer.*", NULL, True}, \
61 { "Acroread.*", NULL, True}, \ 60 { "Acroread.*", NULL, True}, \
62}; 61};
diff --git a/config.default.h b/config.default.h
index f3fd7b7..3847ff8 100644
--- a/config.default.h
+++ b/config.default.h
@@ -47,9 +47,8 @@ static Key key[] = { \
47}; 47};
48 48
49#define RULES \ 49#define RULES \
50 const unsigned int two[] = { 2 }; \
51static Rule rule[] = { \ 50static Rule rule[] = { \
52 /* class:instance tags isfloat */ \ 51 /* class:instance regex tags regex isfloat */ \
53 { "Firefox.*", two, False }, \ 52 { "Firefox.*", "2", False }, \
54 { "Gimp.*", NULL, True}, \ 53 { "Gimp.*", NULL, True}, \
55}; 54};
diff --git a/config.mk b/config.mk
index 4657aff..92e244e 100644
--- a/config.mk
+++ b/config.mk
@@ -15,10 +15,10 @@ INCS = -I/usr/lib -I${X11INC}
15LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 15LIBS = -L/usr/lib -lc -L${X11LIB} -lX11
16 16
17# flags 17# flags
18CFLAGS = -O3 ${INCS} -DVERSION=\"${VERSION}\" 18#CFLAGS = -O3 ${INCS} -DVERSION=\"${VERSION}\"
19LDFLAGS = ${LIBS} 19#LDFLAGS = ${LIBS}
20#CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\" 20CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\"
21#LDFLAGS = -g ${LIBS} 21LDFLAGS = -g ${LIBS}
22 22
23# compiler 23# compiler
24CC = cc 24CC = cc
diff --git a/dwm.h b/dwm.h
index 939b546..57d628a 100644
--- a/dwm.h
+++ b/dwm.h
@@ -121,6 +121,7 @@ extern int xerror(Display *dsply, XErrorEvent *ee);
121extern void appendtag(Arg *arg); 121extern void appendtag(Arg *arg);
122extern void dofloat(Arg *arg); 122extern void dofloat(Arg *arg);
123extern void dotile(Arg *arg); 123extern void dotile(Arg *arg);
124extern void initrregs();
124extern Client *getnext(Client *c); 125extern Client *getnext(Client *c);
125extern Client *getprev(Client *c); 126extern Client *getprev(Client *c);
126extern void replacetag(Arg *arg); 127extern void replacetag(Arg *arg);
diff --git a/main.c b/main.c
index 9ea09bf..633966b 100644
--- a/main.c
+++ b/main.c
@@ -210,6 +210,7 @@ main(int argc, char *argv[])
210 cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur); 210 cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
211 211
212 grabkeys(); 212 grabkeys();
213 initrregs();
213 214
214 for(ntags = 0; tags[ntags]; ntags++); 215 for(ntags = 0; tags[ntags]; ntags++);
215 216
diff --git a/tag.c b/tag.c
index b20e71e..015a06a 100644
--- a/tag.c
+++ b/tag.c
@@ -5,21 +5,31 @@
5#include "dwm.h" 5#include "dwm.h"
6#include <regex.h> 6#include <regex.h>
7#include <stdio.h> 7#include <stdio.h>
8#include <stdlib.h>
8#include <string.h> 9#include <string.h>
9#include <sys/types.h> 10#include <sys/types.h>
10#include <X11/Xutil.h> 11#include <X11/Xutil.h>
11 12
12/* static */
13 13
14typedef struct { 14typedef struct {
15 const char *pattern; 15 const char *clpattern;
16 const unsigned int *tags; 16 const char *tpattern;
17 Bool isfloat; 17 Bool isfloat;
18} Rule; 18} Rule;
19 19
20typedef struct {
21 regex_t *clregex;
22 regex_t *tregex;
23} RReg;
24
25/* static */
26
20TAGS 27TAGS
21RULES 28RULES
22 29
30static RReg *rreg = NULL;
31static unsigned int len = 0;
32
23void (*arrange)(Arg *) = DEFMODE; 33void (*arrange)(Arg *) = DEFMODE;
24 34
25/* extern */ 35/* extern */
@@ -138,6 +148,35 @@ getprev(Client *c)
138} 148}
139 149
140void 150void
151initrregs()
152{
153 unsigned int i;
154 regex_t *reg;
155
156 if(rreg)
157 return;
158 len = sizeof(rule) / sizeof(rule[0]);
159 rreg = emallocz(len * sizeof(RReg));
160
161 for(i = 0; i < len; i++) {
162 if(rule[i].clpattern) {
163 reg = emallocz(sizeof(regex_t));
164 if(regcomp(reg, rule[i].clpattern, 0))
165 free(reg);
166 else
167 rreg[i].clregex = reg;
168 }
169 if(rule[i].tpattern) {
170 reg = emallocz(sizeof(regex_t));
171 if(regcomp(reg, rule[i].tpattern, 0))
172 free(reg);
173 else
174 rreg[i].tregex = reg;
175 }
176 }
177}
178
179void
141replacetag(Arg *arg) 180replacetag(Arg *arg)
142{ 181{
143 int i; 182 int i;
@@ -154,9 +193,7 @@ void
154settags(Client *c) 193settags(Client *c)
155{ 194{
156 char classinst[256]; 195 char classinst[256];
157 static unsigned int len = sizeof(rule) / sizeof(rule[0]); 196 unsigned int i, j;
158 unsigned int i, j, n;
159 regex_t regex;
160 regmatch_t tmp; 197 regmatch_t tmp;
161 Bool matched = False; 198 Bool matched = False;
162 XClassHint ch; 199 XClassHint ch;
@@ -165,19 +202,16 @@ settags(Client *c)
165 snprintf(classinst, sizeof(classinst), "%s:%s", 202 snprintf(classinst, sizeof(classinst), "%s:%s",
166 ch.res_class ? ch.res_class : "", 203 ch.res_class ? ch.res_class : "",
167 ch.res_name ? ch.res_name : ""); 204 ch.res_name ? ch.res_name : "");
168 for(i = 0; !matched && i < len; i++) { 205 for(i = 0; !matched && i < len; i++)
169 if(!regcomp(&regex, rule[i].pattern, 0)) { 206 if(rreg[i].clregex && !regexec(rreg[i].clregex, classinst, 1, &tmp, 0)) {
170 if(!regexec(&regex, classinst, 1, &tmp, 0)) { 207 c->isfloat = rule[i].isfloat;
171 n = rule[i].tags ? 208 for(j = 0; rreg[i].tregex && j < ntags; j++) {
172 sizeof(rule[i].tags) / sizeof(rule[i].tags[0]) : 0; 209 if(!regexec(rreg[i].tregex, tags[j], 1, &tmp, 0)) {
173 matched = n != 0; 210 matched = True;
174 for(j = 0; j < n; j++) 211 c->tags[j] = True;
175 c->tags[rule[i].tags[j]] = True; 212 }
176 c->isfloat = rule[i].isfloat;
177 } 213 }
178 regfree(&regex);
179 } 214 }
180 }
181 if(ch.res_class) 215 if(ch.res_class)
182 XFree(ch.res_class); 216 XFree(ch.res_class);
183 if(ch.res_name) 217 if(ch.res_name)