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);
55 XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
66 for(n = 0, c = clients; c; c = c->next)
67 if(isvisible(c) && !c->isfloat)
71 h = (sh - bh) / (n - 1);
75 for(i = 0, c = clients; c; c = c->next) {
79 resize(c, True, TopLeft);
96 c->y = sy + (i - 1) * h + bh;
103 else { /* fallback if h < bh */
109 resize(c, False, TopLeft);
115 if(!sel || !isvisible(sel))
116 sel = getnext(clients);
120 XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
127 for(; c && !isvisible(c); c = c->next);
134 for(; c && !isvisible(c); c = c->prev);
146 len = sizeof(rule) / sizeof(rule[0]);
147 rreg = emallocz(len * sizeof(RReg));
149 for(i = 0; i < len; i++) {
150 if(rule[i].clpattern) {
151 reg = emallocz(sizeof(regex_t));
152 if(regcomp(reg, rule[i].clpattern, 0))
155 rreg[i].clregex = reg;
157 if(rule[i].tpattern) {
158 reg = emallocz(sizeof(regex_t));
159 if(regcomp(reg, rule[i].tpattern, 0))
162 rreg[i].tregex = reg;
172 for(i = 0; i < ntags; i++)
173 if(c->tags[i] && seltag[i])
181 static unsigned int nwins = 0;
182 static Window *wins = NULL;
183 unsigned int f, fi, m, mi, n;
187 for(f = 0, m = 0, c = clients; c; c = c->next)
189 if(c->isfloat || arrange == dofloat)
194 if(!(n = 2 * (f + m))) {
200 wins = erealloc(wins, nwins * sizeof(Window));
205 if(sel->isfloat || arrange == dofloat) {
206 wins[fi++] = sel->title;
207 wins[fi++] = sel->win;
210 wins[mi++] = sel->title;
211 wins[mi++] = sel->win;
213 for(c = clients; c; c = c->next)
214 if(isvisible(c) && c != sel) {
215 if(c->isfloat || arrange == dofloat) {
216 wins[fi++] = c->title;
220 wins[mi++] = c->title;
224 XRestackWindows(dpy, wins, n);
227 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
236 Bool matched = False;
239 if(XGetClassHint(dpy, c->win, &ch)) {
240 snprintf(classinst, sizeof(classinst), "%s:%s",
241 ch.res_class ? ch.res_class : "",
242 ch.res_name ? ch.res_name : "");
243 for(i = 0; !matched && i < len; i++)
244 if(rreg[i].clregex && !regexec(rreg[i].clregex, classinst, 1, &tmp, 0)) {
245 c->isfloat = rule[i].isfloat;
246 for(j = 0; rreg[i].tregex && j < ntags; j++) {
247 if(!regexec(rreg[i].tregex, tags[j], 1, &tmp, 0)) {
259 for(i = 0; i < ntags; i++)
260 c->tags[i] = seltag[i];
271 for(i = 0; i < ntags; i++)
272 sel->tags[i] = False;
273 sel->tags[arg->i] = True;
282 arrange = arrange == dofloat ? dotile : dofloat;
297 sel->tags[arg->i] = !sel->tags[arg->i];
298 for(i = 0; i < ntags && !sel->tags[i]; i++);
300 sel->tags[arg->i] = True;
312 seltag[arg->i] = !seltag[arg->i];
313 for(i = 0; i < ntags && !seltag[i]; i++);
315 seltag[arg->i] = True; /* cannot toggle last view */
324 for(i = 0; i < ntags; i++)
326 seltag[arg->i] = True;