implemented regexp matching for rules
bcaf6a7a
4 file(s) · +40 −32
| 247 | 247 | GrabModeAsync, GrabModeSync, None, None); |
|
| 248 | 248 | ||
| 249 | 249 | if(!c->isfloat) |
|
| 250 | - | c->isfloat = trans |
|
| 251 | - | || ((c->maxw == c->minw) && (c->maxh == c->minh)); |
|
| 250 | + | c->isfloat = trans || (c->maxw && c->minw && |
|
| 251 | + | (c->maxw == c->minw) && (c->maxh == c->minh)); |
|
| 252 | + | ||
| 252 | 253 | ||
| 253 | 254 | setgeom(c); |
|
| 254 | 255 | settitle(c); |
| 30 | 30 | typedef enum Corner Corner; |
|
| 31 | 31 | typedef struct DC DC; |
|
| 32 | 32 | typedef struct Fnt Fnt; |
|
| 33 | - | typedef struct Key Key; |
|
| 34 | - | typedef struct Rule Rule; |
|
| 35 | 33 | ||
| 36 | 34 | union Arg { |
|
| 37 | 35 | const char **argv; |
|
| 84 | 82 | Window title; |
|
| 85 | 83 | }; |
|
| 86 | 84 | ||
| 87 | - | struct Rule { |
|
| 88 | - | const char *class; |
|
| 89 | - | const char *instance; |
|
| 90 | - | char *tags[TLast]; |
|
| 91 | - | Bool isfloat; |
|
| 92 | - | }; |
|
| 93 | - | ||
| 94 | - | struct Key { |
|
| 95 | - | unsigned long mod; |
|
| 96 | - | KeySym keysym; |
|
| 97 | - | void (*func)(Arg *arg); |
|
| 98 | - | Arg arg; |
|
| 99 | - | }; |
|
| 100 | - | ||
| 101 | 85 | extern char *tags[TLast], stext[1024]; |
|
| 102 | 86 | extern int tsel, screen, sx, sy, sw, sh, bx, by, bw, bh, mw; |
|
| 103 | 87 | extern void (*handler[LASTEvent])(XEvent *); |
|
| 108 | 92 | extern Cursor cursor[CurLast]; |
|
| 109 | 93 | extern DC dc; |
|
| 110 | 94 | extern Display *dpy; |
|
| 111 | - | extern Key key[]; |
|
| 112 | 95 | extern Window root, barwin; |
|
| 113 | 96 | ||
| 114 | 97 | /* client.c */ |
|
| 12 | 12 | #define MouseMask (ButtonMask | PointerMotionMask) |
|
| 13 | 13 | ||
| 14 | 14 | /* CUSTOMIZE */ |
|
| 15 | + | ||
| 16 | + | typedef struct { |
|
| 17 | + | unsigned long mod; |
|
| 18 | + | KeySym keysym; |
|
| 19 | + | void (*func)(Arg *arg); |
|
| 20 | + | Arg arg; |
|
| 21 | + | } Key; |
|
| 22 | + | ||
| 15 | 23 | const char *browse[] = { "firefox", NULL }; |
|
| 16 | 24 | const char *gimp[] = { "gimp", NULL }; |
|
| 17 | 25 | const char *term[] = { |
|
| 20 | 28 | }; |
|
| 21 | 29 | const char *xlock[] = { "xlock", NULL }; |
|
| 22 | 30 | ||
| 23 | - | Key key[] = { |
|
| 31 | + | static Key key[] = { |
|
| 24 | 32 | /* modifier key function arguments */ |
|
| 25 | 33 | { ControlMask, XK_0, appendtag, { .i = Tscratch } }, |
|
| 26 | 34 | { ControlMask, XK_1, appendtag, { .i = Tdev } }, |
|
| 4 | 4 | */ |
|
| 5 | 5 | #include "dwm.h" |
|
| 6 | 6 | ||
| 7 | + | #include <regex.h> |
|
| 8 | + | #include <stdio.h> |
|
| 7 | 9 | #include <string.h> |
|
| 10 | + | #include <sys/types.h> |
|
| 8 | 11 | #include <X11/Xutil.h> |
|
| 9 | 12 | ||
| 10 | 13 | /* static */ |
|
| 11 | 14 | ||
| 15 | + | typedef struct { |
|
| 16 | + | const char *pattern; |
|
| 17 | + | char *tags[TLast]; |
|
| 18 | + | Bool isfloat; |
|
| 19 | + | } Rule; |
|
| 20 | + | ||
| 12 | 21 | /* CUSTOMIZE */ |
|
| 13 | 22 | static Rule rule[] = { |
|
| 14 | - | /* class instance tags isfloat */ |
|
| 15 | - | { "Firefox-bin", "firefox-bin", { [Twww] = "www" }, False }, |
|
| 23 | + | /* class instance tags isfloat */ |
|
| 24 | + | { "Firefox.*", { [Twww] = "www" }, False }, |
|
| 25 | + | { "Gimp.*", { 0 }, True}, |
|
| 16 | 26 | }; |
|
| 17 | 27 | ||
| 18 | 28 | /* extern */ |
|
| 164 | 174 | void |
|
| 165 | 175 | settags(Client *c) |
|
| 166 | 176 | { |
|
| 167 | - | XClassHint ch; |
|
| 177 | + | char classinst[256]; |
|
| 168 | 178 | static unsigned int len = rule ? sizeof(rule) / sizeof(rule[0]) : 0; |
|
| 169 | 179 | unsigned int i, j; |
|
| 180 | + | regex_t regex; |
|
| 181 | + | regmatch_t tmp; |
|
| 170 | 182 | Bool matched = False; |
|
| 183 | + | XClassHint ch; |
|
| 171 | 184 | ||
| 172 | 185 | if(!len) { |
|
| 173 | 186 | c->tags[tsel] = tags[tsel]; |
|
| 175 | 188 | } |
|
| 176 | 189 | ||
| 177 | 190 | if(XGetClassHint(dpy, c->win, &ch)) { |
|
| 178 | - | if(ch.res_class && ch.res_name) { |
|
| 179 | - | for(i = 0; i < len; i++) |
|
| 180 | - | if(!strncmp(rule[i].class, ch.res_class, sizeof(rule[i].class)) |
|
| 181 | - | && !strncmp(rule[i].instance, ch.res_name, sizeof(rule[i].instance))) |
|
| 182 | - | { |
|
| 183 | - | for(j = 0; j < TLast; j++) |
|
| 191 | + | snprintf(classinst, sizeof(classinst), "%s:%s", |
|
| 192 | + | ch.res_class ? ch.res_class : "", |
|
| 193 | + | ch.res_name ? ch.res_name : ""); |
|
| 194 | + | for(i = 0; !matched && i < len; i++) { |
|
| 195 | + | if(!regcomp(®ex, rule[i].pattern, 0)) { |
|
| 196 | + | if(!regexec(®ex, classinst, 1, &tmp, 0)) { |
|
| 197 | + | for(j = 0; j < TLast; j++) { |
|
| 198 | + | if(rule[i].tags[j]) |
|
| 199 | + | matched = True; |
|
| 184 | 200 | c->tags[j] = rule[i].tags[j]; |
|
| 201 | + | } |
|
| 185 | 202 | c->isfloat = rule[i].isfloat; |
|
| 186 | - | matched = True; |
|
| 187 | - | break; |
|
| 188 | 203 | } |
|
| 204 | + | regfree(®ex); |
|
| 205 | + | } |
|
| 189 | 206 | } |
|
| 190 | 207 | if(ch.res_class) |
|
| 191 | 208 | XFree(ch.res_class); |
|
| 192 | 209 | if(ch.res_name) |
|
| 193 | 210 | XFree(ch.res_name); |
|
| 194 | 211 | } |
|
| 195 | - | ||
| 196 | 212 | if(!matched) |
|
| 197 | 213 | c->tags[tsel] = tags[tsel]; |
|
| 198 | 214 | } |
|