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 void (*arrange)(void) = DEFMODE;
13 unsigned int master = MASTER;
14 unsigned int nmaster = NMASTER;
32 static Regexps *regexps = NULL;
33 static unsigned int len = 0;
38 compileregexps(void) {
44 len = sizeof rule / sizeof rule[0];
45 regexps = emallocz(len * sizeof(Regexps));
46 for(i = 0; i < len; i++) {
48 reg = emallocz(sizeof(regex_t));
49 if(regcomp(reg, rule[i].prop, REG_EXTENDED))
52 regexps[i].propregex = reg;
55 reg = emallocz(sizeof(regex_t));
56 if(regcomp(reg, rule[i].tags, REG_EXTENDED))
59 regexps[i].tagregex = reg;
68 for(c = clients; c; c = c->next) {
71 XMoveWindow(dpy, c->win, c->x, c->y);
73 resize(c, c->x, c->y, c->w, c->h, True);
77 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
80 if(!sel || !isvisible(sel)) {
81 for(c = stack; c && !isvisible(c); c = c->snext);
88 unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th;
91 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
94 mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1);
95 mw = (n > nmaster) ? (waw * master) / 1000 : waw;
96 th = (n > nmaster) ? wah / (n - nmaster) : 0;
99 for(i = 0, c = clients; c; c = c->next)
102 XMoveWindow(dpy, c->win, c->x, c->y);
111 nw = mw - 2 * BORDERPX;
112 nh = mh - 2 * BORDERPX;
114 else { /* tile window */
116 nw = tw - 2 * BORDERPX;
117 if(th > 2 * BORDERPX) {
118 ny += (i - nmaster) * th;
119 nh = th - 2 * BORDERPX;
121 else /* fallback if th <= 2 * BORDERPX */
122 nh = wah - 2 * BORDERPX;
124 resize(c, nx, ny, nw, nh, False);
129 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
131 if(!sel || !isvisible(sel)) {
132 for(c = stack; c && !isvisible(c); c = c->snext);
139 incnmaster(Arg *arg) {
140 if((arrange == dofloat) || (nmaster + arg->i < 1)
141 || (wah / (nmaster + arg->i) <= 2 * BORDERPX))
151 isvisible(Client *c) {
154 for(i = 0; i < ntags; i++)
155 if(c->tags[i] && seltag[i])
161 resizemaster(Arg *arg) {
162 if(arrange != dotile)
167 if(waw * (master + arg->i) / 1000 >= waw - 2 * BORDERPX
168 || waw * (master + arg->i) / 1000 <= 2 * BORDERPX)
183 if(sel->isfloat || arrange == dofloat)
184 XRaiseWindow(dpy, sel->win);
185 if(arrange != dofloat) {
187 XLowerWindow(dpy, sel->win);
188 for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
191 XLowerWindow(dpy, c->win);
195 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
199 settags(Client *c, Client *trans) {
203 Bool matched = trans != NULL;
204 XClassHint ch = { 0 };
207 for(i = 0; i < ntags; i++)
208 c->tags[i] = trans->tags[i];
210 XGetClassHint(dpy, c->win, &ch);
211 snprintf(prop, sizeof prop, "%s:%s:%s",
212 ch.res_class ? ch.res_class : "",
213 ch.res_name ? ch.res_name : "", c->name);
214 for(i = 0; i < len; i++)
215 if(regexps[i].propregex && !regexec(regexps[i].propregex, prop, 1, &tmp, 0)) {
216 c->isfloat = rule[i].isfloat;
217 for(j = 0; regexps[i].tagregex && j < ntags; j++) {
218 if(!regexec(regexps[i].tagregex, tags[j], 1, &tmp, 0)) {
230 for(i = 0; i < ntags; i++)
231 c->tags[i] = seltag[i];
240 for(i = 0; i < ntags; i++)
241 sel->tags[i] = (arg->i == -1) ? True : False;
242 if(arg->i >= 0 && arg->i < ntags)
243 sel->tags[arg->i] = True;
248 togglefloat(Arg *arg) {
249 if(!sel || arrange == dofloat)
251 sel->isfloat = !sel->isfloat;
256 toggletag(Arg *arg) {
261 sel->tags[arg->i] = !sel->tags[arg->i];
262 for(i = 0; i < ntags && !sel->tags[i]; i++);
264 sel->tags[arg->i] = True;
269 togglemode(Arg *arg) {
270 arrange = (arrange == dofloat) ? dotile : dofloat;
278 toggleview(Arg *arg) {
281 seltag[arg->i] = !seltag[arg->i];
282 for(i = 0; i < ntags && !seltag[i]; i++);
284 seltag[arg->i] = True; /* cannot toggle last view */
292 for(i = 0; i < ntags; i++)
293 seltag[i] = (arg->i == -1) ? True : False;
294 if(arg->i >= 0 && arg->i < ntags)
295 seltag[arg->i] = True;