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);
89 unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th;
92 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
95 mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1);
96 mw = (n > nmaster) ? (waw * master) / 1000 : waw;
97 th = (n > nmaster) ? wah / (n - nmaster) : 0;
100 for(i = 0, c = clients; c; c = c->next)
103 XMoveWindow(dpy, c->win, c->x, c->y);
112 nw = mw - 2 * BORDERPX;
113 nh = mh - 2 * BORDERPX;
115 else { /* tile window */
117 nw = tw - 2 * BORDERPX;
118 if(th > 2 * BORDERPX) {
119 ny += (i - nmaster) * th;
120 nh = th - 2 * BORDERPX;
122 else /* fallback if th <= 2 * BORDERPX */
123 nh = wah - 2 * BORDERPX;
125 resize(c, nx, ny, nw, nh, False);
130 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
132 if(!sel || !isvisible(sel)) {
133 for(c = stack; c && !isvisible(c); c = c->snext);
140 incnmaster(Arg *arg) {
141 if((arrange == dofloat) || (nmaster + arg->i < 1)
142 || (wah / (nmaster + arg->i) <= 2 * BORDERPX))
152 isvisible(Client *c) {
155 for(i = 0; i < ntags; i++)
156 if(c->tags[i] && seltag[i])
162 resizemaster(Arg *arg) {
163 if(arrange != dotile)
168 if(waw * (master + arg->i) / 1000 >= waw - 2 * BORDERPX
169 || waw * (master + arg->i) / 1000 <= 2 * BORDERPX)
184 if(sel->isfloat || arrange == dofloat)
185 XRaiseWindow(dpy, sel->win);
186 if(arrange != dofloat) {
188 XLowerWindow(dpy, sel->win);
189 for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
192 XLowerWindow(dpy, c->win);
196 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
200 settags(Client *c, Client *trans) {
204 Bool matched = trans != NULL;
205 XClassHint ch = { 0 };
208 for(i = 0; i < ntags; i++)
209 c->tags[i] = trans->tags[i];
211 XGetClassHint(dpy, c->win, &ch);
212 snprintf(prop, sizeof prop, "%s:%s:%s",
213 ch.res_class ? ch.res_class : "",
214 ch.res_name ? ch.res_name : "", c->name);
215 for(i = 0; i < len; i++)
216 if(regexps[i].propregex && !regexec(regexps[i].propregex, prop, 1, &tmp, 0)) {
217 c->isfloat = rule[i].isfloat;
218 for(j = 0; regexps[i].tagregex && j < ntags; j++) {
219 if(!regexec(regexps[i].tagregex, tags[j], 1, &tmp, 0)) {
231 for(i = 0; i < ntags; i++)
232 c->tags[i] = seltag[i];
241 for(i = 0; i < ntags; i++)
242 sel->tags[i] = (arg->i == -1) ? True : False;
243 if(arg->i >= 0 && arg->i < ntags)
244 sel->tags[arg->i] = True;
249 togglefloat(Arg *arg) {
250 if(!sel || arrange == dofloat)
252 sel->isfloat = !sel->isfloat;
257 toggletag(Arg *arg) {
262 sel->tags[arg->i] = !sel->tags[arg->i];
263 for(i = 0; i < ntags && !sel->tags[i]; i++);
265 sel->tags[arg->i] = True;
270 togglemode(Arg *arg) {
271 arrange = (arrange == dofloat) ? dotile : dofloat;
279 toggleview(Arg *arg) {
282 seltag[arg->i] = !seltag[arg->i];
283 for(i = 0; i < ntags && !seltag[i]; i++);
285 seltag[arg->i] = True; /* cannot toggle last view */
293 for(i = 0; i < ntags; i++)
294 seltag[i] = (arg->i == -1) ? True : False;
295 if(arg->i >= 0 && arg->i < ntags)
296 seltag[arg->i] = True;