1 /* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
2 * See LICENSE file for license details.
10 nexttiled(Client *c) {
11 for(; c && (c->isfloat || !isvisible(c)); c = c->next);
16 togglemax(Client *c) {
22 if((c->ismax = !c->ismax)) {
27 resize(c, wax, way, waw - 2 * BORDERPX, wah - 2 * BORDERPX, True);
30 resize(c, c->rx, c->ry, c->rw, c->rh, True);
31 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
36 void (*arrange)(void) = DEFMODE;
41 c->prev->next = c->next;
43 c->next->prev = c->prev;
46 c->next = c->prev = NULL;
53 for(c = clients; c; c = c->next) {
56 XMoveWindow(dpy, c->win, c->x, c->y);
61 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
64 if(!sel || !isvisible(sel)) {
65 for(c = stack; c && !isvisible(c); c = c->snext);
73 unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th;
76 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
79 mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1);
80 mw = (n > nmaster) ? (waw * master) / 1000 : waw;
81 th = (n > nmaster) ? wah / (n - nmaster) : 0;
84 for(i = 0, c = clients; c; c = c->next)
87 XMoveWindow(dpy, c->win, c->x, c->y);
96 nw = mw - 2 * BORDERPX;
97 nh = mh - 2 * BORDERPX;
99 else { /* tile window */
101 nw = tw - 2 * BORDERPX;
102 if(th > 2 * BORDERPX) {
103 ny += (i - nmaster) * th;
104 nh = th - 2 * BORDERPX;
106 else /* fallback if th <= 2 * BORDERPX */
107 nh = wah - 2 * BORDERPX;
109 resize(c, nx, ny, nw, nh, False);
114 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
116 if(!sel || !isvisible(sel)) {
117 for(c = stack; c && !isvisible(c); c = c->snext);
124 focusnext(Arg *arg) {
129 for(c = sel->next; c && !isvisible(c); c = c->next);
131 for(c = clients; c && !isvisible(c); c = c->next);
139 focusprev(Arg *arg) {
144 for(c = sel->prev; c && !isvisible(c); c = c->prev);
146 for(c = clients; c && c->next; c = c->next);
147 for(; c && !isvisible(c); c = c->prev);
156 incnmaster(Arg *arg) {
157 if((arrange == dofloat) || (nmaster + arg->i < 1)
158 || (wah / (nmaster + arg->i) <= 2 * BORDERPX))
168 isvisible(Client *c) {
171 for(i = 0; i < ntags; i++)
172 if(c->tags[i] && seltag[i])
178 resizemaster(Arg *arg) {
182 if(waw * (master + arg->i) / 1000 >= waw - 2 * BORDERPX
183 || waw * (master + arg->i) / 1000 <= 2 * BORDERPX)
198 if(sel->isfloat || arrange == dofloat)
199 XRaiseWindow(dpy, sel->win);
200 if(arrange != dofloat) {
202 XLowerWindow(dpy, sel->win);
203 for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
206 XLowerWindow(dpy, c->win);
210 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
214 togglefloat(Arg *arg) {
215 if(!sel || arrange == dofloat)
217 sel->isfloat = !sel->isfloat;
222 togglemode(Arg *arg) {
223 arrange = (arrange == dofloat) ? dotile : dofloat;
231 toggleview(Arg *arg) {
234 seltag[arg->i] = !seltag[arg->i];
235 for(i = 0; i < ntags && !seltag[i]; i++);
237 seltag[arg->i] = True; /* cannot toggle last view */
245 for(i = 0; i < ntags; i++)
246 seltag[i] = (arg->i == -1) ? True : False;
247 if(arg->i >= 0 && arg->i < ntags)
248 seltag[arg->i] = True;
259 if(sel->isfloat || (arrange == dofloat)) {
263 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
266 if((c = sel) == nexttiled(clients))
267 if(!(c = nexttiled(c->next)))