1 /* See LICENSE file for copyright and license details. */
26 static Regs *regs = NULL;
27 static unsigned int nrules = 0;
28 static char prop[512];
31 idxoftag(const char *tag) {
34 for(i = 0; i < ntags; i++)
43 applyrules(Client *c) {
47 XClassHint ch = { 0 };
50 XGetClassHint(dpy, c->win, &ch);
51 snprintf(prop, sizeof prop, "%s:%s:%s",
52 ch.res_class ? ch.res_class : "",
53 ch.res_name ? ch.res_name : "", c->name);
54 for(i = 0; i < nrules; i++)
55 if(regs[i].propregex && !regexec(regs[i].propregex, prop, 1, &tmp, 0)) {
56 c->isfloating = rules[i].isfloating;
57 for(j = 0; regs[i].tagregex && j < ntags; j++) {
58 if(!regexec(regs[i].tagregex, tags[j], 1, &tmp, 0)) {
69 for(i = 0; i < ntags; i++)
70 c->tags[i] = seltags[i];
80 nrules = sizeof rules / sizeof rules[0];
81 regs = emallocz(nrules * sizeof(Regs));
82 for(i = 0; i < nrules; i++) {
84 reg = emallocz(sizeof(regex_t));
85 if(regcomp(reg, rules[i].prop, REG_EXTENDED))
88 regs[i].propregex = reg;
91 reg = emallocz(sizeof(regex_t));
92 if(regcomp(reg, rules[i].tags, REG_EXTENDED))
95 regs[i].tagregex = reg;
101 isvisible(Client *c) {
104 for(i = 0; i < ntags; i++)
105 if(c->tags[i] && seltags[i])
111 tag(const char *arg) {
116 for(i = 0; i < ntags; i++)
117 sel->tags[i] = arg == NULL;
119 if(i >= 0 && i < ntags)
126 togglefloating(const char *arg) {
127 if(!sel || isfloating())
129 sel->isfloating = !sel->isfloating;
130 if(sel->isfloating) {
131 resize(sel, sel->x, sel->y, sel->w, sel->h, True);
138 toggletag(const char *arg) {
144 sel->tags[i] = !sel->tags[i];
145 for(j = 0; j < ntags && !sel->tags[j]; j++);
153 toggleview(const char *arg) {
157 seltags[i] = !seltags[i];
158 for(j = 0; j < ntags && !seltags[j]; j++);
160 seltags[i] = True; /* cannot toggle last view */
165 view(const char *arg) {
168 for(i = 0; i < ntags; i++)
169 seltags[i] = arg == NULL;
171 if(i >= 0 && i < ntags)