2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
15 if((clients && clients->isfloat) || arrange == dofloat)
16 return clients; /* don't touch floating order */
17 for(min = c = clients; c; c = c->next)
18 if(c->weight < min->weight)
24 nexttiled(Client *c) {
25 for(c = getnext(c); c && c->isfloat; c = getnext(c->next));
31 Client *c, *newclients, *tail;
33 newclients = tail = NULL;
34 while((c = minclient())) {
42 tail = newclients = c;
51 if((c->ismax = !c->ismax)) {
52 c->rx = c->x; c->x = sx;
53 c->ry = c->y; c->y = bh;
54 c->rw = c->w; c->w = sw - 2 * BORDERPX;
55 c->rh = c->h; c->h = sh - bh - 2 * BORDERPX;
63 resize(c, True, TopLeft);
64 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
69 void (*arrange)(Arg *) = DEFMODE;
70 StackPos stackpos = STACKPOS;
75 c->prev->next = c->next;
77 c->next->prev = c->prev;
80 c->next = c->prev = NULL;
87 for(c = clients; c; c = c->next) {
89 resize(c, True, TopLeft);
94 if(!sel || !isvisible(sel)) {
95 for(c = stack; c && !isvisible(c); c = c->snext);
101 /* This algorithm is based on a (M)aster area and a (S)tacking area.
102 * It supports following arrangements:
108 int i, n, stackw, stackh, tw, th;
111 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
114 if(stackpos == StackBottom) {
116 stackh = sh - bh - master;
119 stackw = sw - master;
125 th = stackh / (n - 1);
129 for(i = 0, c = clients; c; c = c->next) {
132 resize(c, True, TopLeft);
136 if(n == 1) { /* only 1 window */
139 c->w = sw - 2 * BORDERPX;
140 c->h = sh - 2 * BORDERPX - bh;
142 else if(i == 0) { /* master window */
144 if(stackpos == StackLeft)
150 c->w = master - 2 * BORDERPX;
151 c->h = sh - bh - 2 * BORDERPX;
154 c->w = sw - 2 * BORDERPX;
155 c->h = master - 2 * BORDERPX;
159 else if(th > bh) { /* tile window */
161 if(stackpos == StackRight)
163 c->w = tw - 2 * BORDERPX;
164 c->h = th - 2 * BORDERPX;
168 c->y = sy + (i - 1) * th + bh;
170 c->h = sh - c->y - 2 * BORDERPX;
173 c->y = sy + master + (i - 1) * th + bh;
175 c->h = sh - c->y - 2 * BORDERPX;
179 else { /* fallback if th < bh */
181 if(stackpos == StackRight)
184 if(stackpos == StackBottom)
186 c->w = stackw - 2 * BORDERPX;
187 c->h = stackh - 2 * BORDERPX;
189 resize(c, False, TopLeft);
195 if(!sel || !isvisible(sel)) {
196 for(c = stack; c && !isvisible(c); c = c->snext);
203 focusnext(Arg *arg) {
209 if(!(c = getnext(sel->next)))
210 c = getnext(clients);
218 focusprev(Arg *arg) {
224 if(!(c = getprev(sel->prev))) {
225 for(c = clients; c && c->next; c = c->next);
235 isvisible(Client *c) {
238 for(i = 0; i < ntags; i++)
239 if(c->tags[i] && seltag[i])
245 resizecol(Arg *arg) {
250 for(n = 0, c = clients; c; c = c->next)
251 if(isvisible(c) && !c->isfloat)
253 if(!sel || sel->isfloat || n < 2 || (arrange == dofloat))
256 s = stackpos == StackBottom ? sh - bh : sw;
257 if(sel == getnext(clients)) {
258 if(master + arg->i > s - MINDIM || master + arg->i < MINDIM)
263 if(master - arg->i > s - MINDIM || master - arg->i < MINDIM)
279 if(sel->isfloat || arrange == dofloat) {
280 XRaiseWindow(dpy, sel->win);
281 XRaiseWindow(dpy, sel->twin);
283 if(arrange != dofloat) {
285 XLowerWindow(dpy, sel->twin);
286 XLowerWindow(dpy, sel->win);
288 for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
291 XLowerWindow(dpy, c->twin);
292 XLowerWindow(dpy, c->win);
297 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
301 togglemode(Arg *arg) {
302 arrange = (arrange == dofloat) ? dotile : dofloat;
310 toggleview(Arg *arg) {
313 seltag[arg->i] = !seltag[arg->i];
314 for(i = 0; i < ntags && !seltag[i]; i++);
316 seltag[arg->i] = True; /* cannot toggle last view */
322 togglestackpos(Arg *arg) {
323 if(arrange == dofloat)
325 if(stackpos == StackBottom)
328 stackpos = StackBottom;
329 master = ((stackpos == StackBottom ? sh - bh : sw) * MASTER) / 100;
337 for(i = 0; i < ntags; i++)
339 seltag[arg->i] = True;
348 for(i = 0; i < ntags; i++)
364 if(sel->isfloat || (arrange == dofloat)) {
369 for(n = 0, c = clients; c; c = c->next)
370 if(isvisible(c) && !c->isfloat)
372 if(n < 2 || (arrange == dofloat))
375 if((c = sel) == nexttiled(clients))
376 if(!(c = nexttiled(c->next)))