1 /* © 2004-2007 Anselm R. Garbe <garbeam at gmail dot com>
2 * See LICENSE file for license details. */
25 static Regs *regs = NULL;
26 static unsigned int nrules = 0;
37 nrules = sizeof rule / sizeof rule[0];
38 regs = emallocz(nrules * sizeof(Regs));
39 for(i = 0; i < nrules; i++) {
41 reg = emallocz(sizeof(regex_t));
42 if(regcomp(reg, rule[i].prop, REG_EXTENDED))
45 regs[i].propregex = reg;
48 reg = emallocz(sizeof(regex_t));
49 if(regcomp(reg, rule[i].tags, REG_EXTENDED))
52 regs[i].tagregex = reg;
58 isvisible(Client *c) {
61 for(i = 0; i < ntags; i++)
62 if(c->tags[i] && seltag[i])
68 settags(Client *c, Client *trans) {
72 Bool matched = trans != NULL;
73 XClassHint ch = { 0 };
76 for(i = 0; i < ntags; i++)
77 c->tags[i] = trans->tags[i];
79 XGetClassHint(dpy, c->win, &ch);
80 snprintf(prop, sizeof prop, "%s:%s:%s",
81 ch.res_class ? ch.res_class : "",
82 ch.res_name ? ch.res_name : "", c->name);
83 for(i = 0; i < nrules; i++)
84 if(regs[i].propregex && !regexec(regs[i].propregex, prop, 1, &tmp, 0)) {
85 c->isfloating = rule[i].isfloating;
86 for(j = 0; regs[i].tagregex && j < ntags; j++) {
87 if(!regexec(regs[i].tagregex, tags[j], 1, &tmp, 0)) {
99 for(i = 0; i < ntags; i++)
100 c->tags[i] = seltag[i];
104 tag(const char *arg) {
109 for(i = 0; i < ntags; i++)
110 sel->tags[i] = arg == NULL;
111 i = arg ? atoi(arg) : 0;
112 if(i >= 0 && i < ntags)
118 toggletag(const char *arg) {
123 i = arg ? atoi(arg) : 0;
124 sel->tags[i] = !sel->tags[i];
125 for(j = 0; j < ntags && !sel->tags[j]; j++);
132 toggleview(const char *arg) {
135 i = arg ? atoi(arg) : 0;
136 seltag[i] = !seltag[i];
137 for(j = 0; j < ntags && !seltag[j]; j++);
139 seltag[i] = True; /* cannot toggle last view */
144 view(const char *arg) {
147 for(i = 0; i < ntags; i++)
148 seltag[i] = arg == NULL;
149 i = arg ? atoi(arg) : 0;
150 if(i >= 0 && i < ntags)