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 || !isvisible(sel))
51 sel = getnext(clients);
57 XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
67 for(n = 0, c = clients; c; c = c->next)
68 if(isvisible(c) && !c->isfloat)
72 h = (sh - bh) / (n - 1);
76 for(i = 0, c = clients; c; c = c->next) {
80 resize(c, True, TopLeft);
97 c->y = sy + (i - 1) * h + bh;
100 c->h = sh - c->y - 2;
104 else { /* fallback if h < bh */
110 resize(c, False, TopLeft);
116 if(!sel || !isvisible(sel))
117 sel = getnext(clients);
121 XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
128 for(; c && !isvisible(c); c = c->next);
135 for(; c && !isvisible(c); c = c->prev);
147 len = sizeof(rule) / sizeof(rule[0]);
148 rreg = emallocz(len * sizeof(RReg));
150 for(i = 0; i < len; i++) {
151 if(rule[i].clpattern) {
152 reg = emallocz(sizeof(regex_t));
153 if(regcomp(reg, rule[i].clpattern, 0))
156 rreg[i].clregex = reg;
158 if(rule[i].tpattern) {
159 reg = emallocz(sizeof(regex_t));
160 if(regcomp(reg, rule[i].tpattern, 0))
163 rreg[i].tregex = reg;
173 for(i = 0; i < ntags; i++)
174 if(c->tags[i] && seltag[i])
182 static unsigned int nwins = 0;
183 static Window *wins = NULL;
184 unsigned int f, fi, m, mi, n;
188 for(f = 0, m = 0, c = clients; c; c = c->next)
190 if(c->isfloat || arrange == dofloat)
195 if(!(n = 2 * (f + m))) {
201 wins = erealloc(wins, nwins * sizeof(Window));
206 if(sel->isfloat || arrange == dofloat) {
207 wins[fi++] = sel->title;
208 wins[fi++] = sel->win;
211 wins[mi++] = sel->title;
212 wins[mi++] = sel->win;
214 for(c = clients; c; c = c->next)
215 if(isvisible(c) && c != sel) {
216 if(c->isfloat || arrange == dofloat) {
217 wins[fi++] = c->title;
221 wins[mi++] = c->title;
225 XRestackWindows(dpy, wins, n);
228 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
237 Bool matched = False;
240 if(XGetClassHint(dpy, c->win, &ch)) {
241 snprintf(classinst, sizeof(classinst), "%s:%s",
242 ch.res_class ? ch.res_class : "",
243 ch.res_name ? ch.res_name : "");
244 for(i = 0; !matched && i < len; i++)
245 if(rreg[i].clregex && !regexec(rreg[i].clregex, classinst, 1, &tmp, 0)) {
246 c->isfloat = rule[i].isfloat;
247 for(j = 0; rreg[i].tregex && j < ntags; j++) {
248 if(!regexec(rreg[i].tregex, tags[j], 1, &tmp, 0)) {
260 for(i = 0; i < ntags; i++)
261 c->tags[i] = seltag[i];
272 for(i = 0; i < ntags; i++)
273 sel->tags[i] = False;
274 sel->tags[arg->i] = True;
283 arrange = arrange == dofloat ? dotile : dofloat;
298 sel->tags[arg->i] = !sel->tags[arg->i];
299 for(i = 0; i < ntags && !sel->tags[i]; i++);
301 sel->tags[arg->i] = True;
313 seltag[arg->i] = !seltag[arg->i];
314 for(i = 0; i < ntags && !seltag[i]; i++);
316 seltag[arg->i] = True; /* cannot toggle last view */
325 for(i = 0; i < ntags; i++)
327 seltag[arg->i] = True;