2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
10 #include <sys/types.h>
11 #include <X11/Xutil.h>
15 const char *clpattern;
30 static RReg *rreg = NULL;
31 static unsigned int len = 0;
33 void (*arrange)(Arg *) = DEFMODE;
42 for(c = clients; c; c = c->next) {
45 resize(c, True, TopLeft);
50 if((sel = getnext(clients))) {
55 XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
65 for(n = 0, c = clients; c; c = c->next)
66 if(isvisible(c) && !c->isfloat)
70 h = (sh - bh) / (n - 1);
74 for(i = 0, c = clients; c; c = c->next) {
78 resize(c, True, TopLeft);
95 c->y = sy + (i - 1) * h + bh;
102 else { /* fallback if h < bh */
108 resize(c, False, TopLeft);
114 if((sel = getnext(clients)))
117 XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
124 for(; c && !isvisible(c); c = c->next);
131 for(; c && !isvisible(c); c = c->prev);
143 len = sizeof(rule) / sizeof(rule[0]);
144 rreg = emallocz(len * sizeof(RReg));
146 for(i = 0; i < len; i++) {
147 if(rule[i].clpattern) {
148 reg = emallocz(sizeof(regex_t));
149 if(regcomp(reg, rule[i].clpattern, 0))
152 rreg[i].clregex = reg;
154 if(rule[i].tpattern) {
155 reg = emallocz(sizeof(regex_t));
156 if(regcomp(reg, rule[i].tpattern, 0))
159 rreg[i].tregex = reg;
169 for(i = 0; i < ntags; i++)
170 if(c->tags[i] && seltag[i])
178 static unsigned int nwins = 0;
179 static Window *wins = NULL;
180 unsigned int f, fi, m, mi, n;
184 for(f = 0, m = 0, c = clients; c; c = c->next)
186 if(c->isfloat || arrange == dofloat)
191 if(!(n = 2 * (f + m))) {
197 wins = erealloc(wins, nwins * sizeof(Window));
202 if(sel->isfloat || arrange == dofloat) {
203 wins[fi++] = sel->title;
204 wins[fi++] = sel->win;
207 wins[mi++] = sel->title;
208 wins[mi++] = sel->win;
210 for(c = clients; c; c = c->next)
211 if(isvisible(c) && c != sel) {
212 if(c->isfloat || arrange == dofloat) {
213 wins[fi++] = c->title;
217 wins[mi++] = c->title;
221 XRestackWindows(dpy, wins, n);
224 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
233 Bool matched = False;
236 if(XGetClassHint(dpy, c->win, &ch)) {
237 snprintf(classinst, sizeof(classinst), "%s:%s",
238 ch.res_class ? ch.res_class : "",
239 ch.res_name ? ch.res_name : "");
240 for(i = 0; !matched && i < len; i++)
241 if(rreg[i].clregex && !regexec(rreg[i].clregex, classinst, 1, &tmp, 0)) {
242 c->isfloat = rule[i].isfloat;
243 for(j = 0; rreg[i].tregex && j < ntags; j++) {
244 if(!regexec(rreg[i].tregex, tags[j], 1, &tmp, 0)) {
256 for(i = 0; i < ntags; i++)
257 c->tags[i] = seltag[i];
268 for(i = 0; i < ntags; i++)
269 sel->tags[i] = False;
270 sel->tags[arg->i] = True;
278 arrange = arrange == dofloat ? dotile : dofloat;
290 sel->tags[arg->i] = !sel->tags[arg->i];
291 for(i = 0; i < ntags && !sel->tags[i]; i++);
293 sel->tags[arg->i] = True;
303 seltag[arg->i] = !seltag[arg->i];
304 for(i = 0; i < ntags && !seltag[i]; i++);
306 seltag[arg->i] = True; /* cannot toggle last view */
315 for(i = 0; i < ntags; i++)
317 seltag[arg->i] = True;