1 /* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
2 * See LICENSE file for license details.
10 #include <X11/Xutil.h>
12 unsigned int master = MASTER;
13 unsigned int nmaster = NMASTER;
33 static Regs *regs = NULL;
34 static unsigned int nrules = 0;
35 static unsigned int nlayouts = 0;
39 unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th;
42 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
45 mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1);
46 mw = (n > nmaster) ? (waw * master) / 1000 : waw;
47 th = (n > nmaster) ? wah / (n - nmaster) : 0;
50 for(i = 0, c = clients; c; c = c->next)
53 XMoveWindow(dpy, c->win, c->x, c->y);
62 nw = mw - 2 * BORDERPX;
63 nh = mh - 2 * BORDERPX;
65 else { /* tile window */
67 nw = tw - 2 * BORDERPX;
68 if(th > 2 * BORDERPX) {
69 ny += (i - nmaster) * th;
70 nh = th - 2 * BORDERPX;
72 else /* fallback if th <= 2 * BORDERPX */
73 nh = wah - 2 * BORDERPX;
75 resize(c, nx, ny, nw, nh, False);
80 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
82 if(!sel || !isvisible(sel)) {
83 for(c = stack; c && !isvisible(c); c = c->snext);
100 nrules = sizeof rule / sizeof rule[0];
101 regs = emallocz(nrules * sizeof(Regs));
102 for(i = 0; i < nrules; i++) {
104 reg = emallocz(sizeof(regex_t));
105 if(regcomp(reg, rule[i].prop, REG_EXTENDED))
108 regs[i].propregex = reg;
111 reg = emallocz(sizeof(regex_t));
112 if(regcomp(reg, rule[i].tags, REG_EXTENDED))
115 regs[i].tagregex = reg;
121 incnmaster(Arg *arg) {
122 if((lt->arrange != tile) || (nmaster + arg->i < 1)
123 || (wah / (nmaster + arg->i) <= 2 * BORDERPX))
137 nlayouts = sizeof layout / sizeof layout[0];
138 for(blw = i = 0; i < nlayouts; i++) {
139 w = textw(layout[i].symbol);
146 isvisible(Client *c) {
149 for(i = 0; i < ntags; i++)
150 if(c->tags[i] && seltag[i])
156 resizemaster(Arg *arg) {
157 if(lt->arrange != tile)
162 if(waw * (master + arg->i) / 1000 >= waw - 2 * BORDERPX
163 || waw * (master + arg->i) / 1000 <= 2 * BORDERPX)
178 if(sel->swimming || lt->arrange == swim)
179 XRaiseWindow(dpy, sel->win);
180 if(lt->arrange != swim) {
182 XLowerWindow(dpy, sel->win);
183 for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
186 XLowerWindow(dpy, c->win);
190 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
194 settags(Client *c, Client *trans) {
198 Bool matched = trans != NULL;
199 XClassHint ch = { 0 };
202 for(i = 0; i < ntags; i++)
203 c->tags[i] = trans->tags[i];
205 XGetClassHint(dpy, c->win, &ch);
206 snprintf(prop, sizeof prop, "%s:%s:%s",
207 ch.res_class ? ch.res_class : "",
208 ch.res_name ? ch.res_name : "", c->name);
209 for(i = 0; i < nrules; i++)
210 if(regs[i].propregex && !regexec(regs[i].propregex, prop, 1, &tmp, 0)) {
211 c->swimming = rule[i].swimming;
212 for(j = 0; regs[i].tagregex && j < ntags; j++) {
213 if(!regexec(regs[i].tagregex, tags[j], 1, &tmp, 0)) {
225 for(i = 0; i < ntags; i++)
226 c->tags[i] = seltag[i];
233 for(c = clients; c; c = c->next) {
236 XMoveWindow(dpy, c->win, c->x, c->y);
238 resize(c, c->x, c->y, c->w, c->h, True);
242 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
245 if(!sel || !isvisible(sel)) {
246 for(c = stack; c && !isvisible(c); c = c->snext);
258 for(i = 0; i < ntags; i++)
259 sel->tags[i] = (arg->i == -1) ? True : False;
260 if(arg->i >= 0 && arg->i < ntags)
261 sel->tags[arg->i] = True;
266 toggleswimming(Arg *arg) {
267 if(!sel || lt->arrange == swim)
269 sel->swimming = !sel->swimming;
274 toggletag(Arg *arg) {
279 sel->tags[arg->i] = !sel->tags[arg->i];
280 for(i = 0; i < ntags && !sel->tags[i]; i++);
282 sel->tags[arg->i] = True;
287 togglelayout(Arg *arg) {
290 for(i = 0; i < nlayouts && lt != &layout[i]; i++);
291 if(i == nlayouts - 1)
302 toggleview(Arg *arg) {
305 seltag[arg->i] = !seltag[arg->i];
306 for(i = 0; i < ntags && !seltag[i]; i++);
308 seltag[arg->i] = True; /* cannot toggle last view */
316 for(i = 0; i < ntags; i++)
317 seltag[i] = (arg->i == -1) ? True : False;
318 if(arg->i >= 0 && arg->i < ntags)
319 seltag[arg->i] = True;