1 /* See LICENSE file for copyright and license details. */
24 static Regs *regs = NULL;
25 static unsigned int nrules = 0;
36 nrules = sizeof rule / sizeof rule[0];
37 regs = emallocz(nrules * sizeof(Regs));
38 for(i = 0; i < nrules; i++) {
40 reg = emallocz(sizeof(regex_t));
41 if(regcomp(reg, rule[i].prop, REG_EXTENDED))
44 regs[i].propregex = reg;
47 reg = emallocz(sizeof(regex_t));
48 if(regcomp(reg, rule[i].tags, REG_EXTENDED))
51 regs[i].tagregex = reg;
57 isvisible(Client *c) {
60 for(i = 0; i < ntags; i++)
61 if(c->tags[i] && seltag[i])
67 settags(Client *c, Client *trans) {
71 Bool matched = trans != NULL;
72 XClassHint ch = { 0 };
75 for(i = 0; i < ntags; i++)
76 c->tags[i] = trans->tags[i];
78 XGetClassHint(dpy, c->win, &ch);
79 snprintf(prop, sizeof prop, "%s:%s:%s",
80 ch.res_class ? ch.res_class : "",
81 ch.res_name ? ch.res_name : "", c->name);
82 for(i = 0; i < nrules; i++)
83 if(regs[i].propregex && !regexec(regs[i].propregex, prop, 1, &tmp, 0)) {
84 c->isfloating = rule[i].isfloating;
85 for(j = 0; regs[i].tagregex && j < ntags; j++) {
86 if(!regexec(regs[i].tagregex, tags[j], 1, &tmp, 0)) {
98 for(i = 0; i < ntags; i++)
99 c->tags[i] = seltag[i];
103 tag(const char *arg) {
108 for(i = 0; i < ntags; i++)
109 sel->tags[i] = arg == NULL;
110 i = arg ? atoi(arg) : 0;
111 if(i >= 0 && i < ntags)
117 toggletag(const char *arg) {
122 i = arg ? atoi(arg) : 0;
123 sel->tags[i] = !sel->tags[i];
124 for(j = 0; j < ntags && !sel->tags[j]; j++);
131 toggleview(const char *arg) {
134 i = arg ? atoi(arg) : 0;
135 seltag[i] = !seltag[i];
136 for(j = 0; j < ntags && !seltag[j]; j++);
138 seltag[i] = True; /* cannot toggle last view */
143 view(const char *arg) {
146 for(i = 0; i < ntags; i++)
147 seltag[i] = arg == NULL;
148 i = arg ? atoi(arg) : 0;
149 if(i >= 0 && i < ntags)