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];
39 nrules = sizeof rule / sizeof rule[0];
40 regs = emallocz(nrules * sizeof(Regs));
41 for(i = 0; i < nrules; i++) {
43 reg = emallocz(sizeof(regex_t));
44 if(regcomp(reg, rule[i].prop, REG_EXTENDED))
47 regs[i].propregex = reg;
50 reg = emallocz(sizeof(regex_t));
51 if(regcomp(reg, rule[i].tags, REG_EXTENDED))
54 regs[i].tagregex = reg;
60 isvisible(Client *c) {
63 for(i = 0; i < ntags; i++)
64 if(c->tags[i] && seltag[i])
70 settags(Client *c, Client *trans) {
73 Bool matched = trans != NULL;
74 XClassHint ch = { 0 };
78 for(i = 0; i < ntags; i++)
79 c->tags[i] = trans->tags[i];
83 /* check if window has set a property */
85 XGetTextProperty(dpy, c->win, &name, dwmtags);
86 if(name.nitems && name.encoding == XA_STRING) {
87 strncpy(prop, (char *)name.value, sizeof prop - 1);
88 prop[sizeof prop - 1] = '\0';
90 for(i = 0; i < ntags && i < sizeof prop - 1 && prop[i] != '\0'; i++)
91 if((c->tags[i] = prop[i] == '+'))
97 XGetClassHint(dpy, c->win, &ch);
98 snprintf(prop, sizeof prop, "%s:%s:%s",
99 ch.res_class ? ch.res_class : "",
100 ch.res_name ? ch.res_name : "", c->name);
101 for(i = 0; i < nrules; i++)
102 if(regs[i].propregex && !regexec(regs[i].propregex, prop, 1, &tmp, 0)) {
103 c->isfloating = rule[i].isfloating;
104 for(j = 0; regs[i].tagregex && j < ntags; j++) {
105 if(!regexec(regs[i].tagregex, tags[j], 1, &tmp, 0)) {
117 for(i = 0; i < ntags; i++)
118 c->tags[i] = seltag[i];
122 tag(const char *arg) {
127 for(i = 0; i < ntags; i++)
128 sel->tags[i] = arg == NULL;
129 i = arg ? atoi(arg) : 0;
130 if(i >= 0 && i < ntags)
133 for(i = 0; i < ntags && i < sizeof prop - 1; i++)
134 prop[i] = sel->tags[i] ? '+' : '-';
136 XChangeProperty(dpy, sel->win, dwmtags, XA_STRING, 8, PropModeReplace, (unsigned char *)prop, i);
142 toggletag(const char *arg) {
147 i = arg ? atoi(arg) : 0;
148 sel->tags[i] = !sel->tags[i];
149 for(j = 0; j < ntags && !sel->tags[j]; j++);
156 toggleview(const char *arg) {
159 i = arg ? atoi(arg) : 0;
160 seltag[i] = !seltag[i];
161 for(j = 0; j < ntags && !seltag[j]; j++);
163 seltag[i] = True; /* cannot toggle last view */
168 view(const char *arg) {
171 for(i = 0; i < ntags; i++)
172 seltag[i] = arg == NULL;
173 i = arg ? atoi(arg) : 0;
174 if(i >= 0 && i < ntags)