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 persistconfig(Client *c) {
34 for(i = 0; i < ntags && i < sizeof prop - 1; i++)
35 prop[i] = c->tags[i] ? '1' : '0';
36 if(i < sizeof prop - 1)
37 prop[i++] = c->isfloating ? '1' : '0';
39 XChangeProperty(dpy, c->win, dwmconfig, XA_STRING, 8,
40 PropModeReplace, (unsigned char *)prop, i);
44 idxoftag(const char *tag) {
47 for(i = 0; i < ntags; i++)
62 nrules = sizeof rule / sizeof rule[0];
63 regs = emallocz(nrules * sizeof(Regs));
64 for(i = 0; i < nrules; i++) {
66 reg = emallocz(sizeof(regex_t));
67 if(regcomp(reg, rule[i].prop, REG_EXTENDED))
70 regs[i].propregex = reg;
73 reg = emallocz(sizeof(regex_t));
74 if(regcomp(reg, rule[i].tags, REG_EXTENDED))
77 regs[i].tagregex = reg;
83 isvisible(Client *c) {
86 for(i = 0; i < ntags; i++)
87 if(c->tags[i] && seltag[i])
93 settags(Client *c, Client *trans) {
96 Bool matched = trans != NULL;
97 XClassHint ch = { 0 };
101 for(i = 0; i < ntags; i++)
102 c->tags[i] = trans->tags[i];
105 /* check if window has set a property */
107 XGetTextProperty(dpy, c->win, &name, dwmconfig);
108 if(name.nitems && name.encoding == XA_STRING) {
109 strncpy(prop, (char *)name.value, sizeof prop - 1);
110 prop[sizeof prop - 1] = '\0';
112 for(i = 0; i < ntags && i < sizeof prop - 1 && prop[i] != '\0'; i++)
113 if((c->tags[i] = prop[i] == '1'))
115 if(i < sizeof prop - 1 && prop[i] != '\0')
116 c->isfloating = prop[i] == '1';
121 XGetClassHint(dpy, c->win, &ch);
122 snprintf(prop, sizeof prop, "%s:%s:%s",
123 ch.res_class ? ch.res_class : "",
124 ch.res_name ? ch.res_name : "", c->name);
125 for(i = 0; i < nrules; i++)
126 if(regs[i].propregex && !regexec(regs[i].propregex, prop, 1, &tmp, 0)) {
127 c->isfloating = rule[i].isfloating;
128 for(j = 0; regs[i].tagregex && j < ntags; j++) {
129 if(!regexec(regs[i].tagregex, tags[j], 1, &tmp, 0)) {
141 for(i = 0; i < ntags; i++)
142 c->tags[i] = seltag[i];
147 tag(const char *arg) {
152 for(i = 0; i < ntags; i++)
153 sel->tags[i] = arg == NULL;
155 if(i >= 0 && i < ntags)
162 togglefloating(const char *arg) {
163 if(!sel || isfloating())
165 sel->isfloating = !sel->isfloating;
166 if(sel->isfloating) {
167 resize(sel, sel->x, sel->y, sel->w, sel->h, True);
174 toggletag(const char *arg) {
180 sel->tags[i] = !sel->tags[i];
181 for(j = 0; j < ntags && !sel->tags[j]; j++);
189 toggleview(const char *arg) {
193 seltag[i] = !seltag[i];
194 for(j = 0; j < ntags && !seltag[j]; j++);
196 seltag[i] = True; /* cannot toggle last view */
201 view(const char *arg) {
204 for(i = 0; i < ntags; i++)
205 seltag[i] = arg == NULL;
207 if(i >= 0 && i < ntags)