1 /* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
2 * See LICENSE file for license details.
10 #include <X11/Xutil.h>
14 const char *clpattern;
29 static RReg *rreg = NULL;
30 static unsigned int len = 0;
35 compileregexps(void) {
41 len = sizeof rule / sizeof rule[0];
42 rreg = emallocz(len * sizeof(RReg));
43 for(i = 0; i < len; i++) {
44 if(rule[i].clpattern) {
45 reg = emallocz(sizeof(regex_t));
46 if(regcomp(reg, rule[i].clpattern, REG_EXTENDED))
49 rreg[i].clregex = reg;
51 if(rule[i].tpattern) {
52 reg = emallocz(sizeof(regex_t));
53 if(regcomp(reg, rule[i].tpattern, REG_EXTENDED))
62 settags(Client *c, Client *trans) {
66 Bool matched = trans != NULL;
67 XClassHint ch = { 0 };
70 for(i = 0; i < ntags; i++)
71 c->tags[i] = trans->tags[i];
73 XGetClassHint(dpy, c->win, &ch);
74 snprintf(prop, sizeof prop, "%s:%s:%s",
75 ch.res_class ? ch.res_class : "",
76 ch.res_name ? ch.res_name : "", c->name);
77 for(i = 0; i < len; i++)
78 if(rreg[i].clregex && !regexec(rreg[i].clregex, prop, 1, &tmp, 0)) {
79 c->isfloat = rule[i].isfloat;
80 for(j = 0; rreg[i].tregex && j < ntags; j++) {
81 if(!regexec(rreg[i].tregex, tags[j], 1, &tmp, 0)) {
93 for(i = 0; i < ntags; i++)
94 c->tags[i] = seltag[i];
103 for(i = 0; i < ntags; i++)
104 sel->tags[i] = (arg->i == -1) ? True : False;
105 if(arg->i >= 0 && arg->i < ntags)
106 sel->tags[arg->i] = True;
111 toggletag(Arg *arg) {
116 sel->tags[arg->i] = !sel->tags[arg->i];
117 for(i = 0; i < ntags && !sel->tags[i]; i++);
119 sel->tags[arg->i] = True;