1 /* See LICENSE file for copyright and license details. */
24 static Regs *regs = NULL;
25 static unsigned int nrules = 0;
26 static char prop[512];
29 idxoftag(const char *tag) {
32 for(i = 0; i < ntags; i++)
41 applyrules(Client *c) {
45 XClassHint ch = { 0 };
48 XGetClassHint(dpy, c->win, &ch);
49 snprintf(prop, sizeof prop, "%s:%s:%s",
50 ch.res_class ? ch.res_class : "",
51 ch.res_name ? ch.res_name : "", c->name);
52 for(i = 0; i < nrules; i++)
53 if(regs[i].propregex && !regexec(regs[i].propregex, prop, 1, &tmp, 0)) {
54 c->isfloating = rules[i].isfloating;
55 for(j = 0; regs[i].tagregex && j < ntags; j++) {
56 if(!regexec(regs[i].tagregex, tags[j], 1, &tmp, 0)) {
67 for(i = 0; i < ntags; i++)
68 c->tags[i] = seltags[i];
78 nrules = sizeof rules / sizeof rules[0];
79 regs = emallocz(nrules * sizeof(Regs));
80 for(i = 0; i < nrules; i++) {
82 reg = emallocz(sizeof(regex_t));
83 if(regcomp(reg, rules[i].prop, REG_EXTENDED))
86 regs[i].propregex = reg;
89 reg = emallocz(sizeof(regex_t));
90 if(regcomp(reg, rules[i].tags, REG_EXTENDED))
93 regs[i].tagregex = reg;
99 isvisible(Client *c) {
102 for(i = 0; i < ntags; i++)
103 if(c->tags[i] && seltags[i])
109 tag(const char *arg) {
114 for(i = 0; i < ntags; i++)
115 sel->tags[i] = arg == NULL;
117 if(i >= 0 && i < ntags)
124 togglefloating(const char *arg) {
125 if(!sel || isfloating())
127 sel->isfloating = !sel->isfloating;
128 if(sel->isfloating) {
129 resize(sel, sel->x, sel->y, sel->w, sel->h, True);
136 toggletag(const char *arg) {
142 sel->tags[i] = !sel->tags[i];
143 for(j = 0; j < ntags && !sel->tags[j]; j++);
151 toggleview(const char *arg) {
155 seltags[i] = !seltags[i];
156 for(j = 0; j < ntags && !seltags[j]; j++);
158 seltags[i] = True; /* cannot toggle last view */
164 view(const char *arg) {
167 for(i = 0; i < ntags; i++)
168 seltags[i] = arg == NULL;
170 if(i >= 0 && i < ntags)