JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
applied Jukka's patch
[dwm.git] / tile.c
1 /* See LICENSE file for copyright and license details. */
2 #include "dwm.h"
3 #include <stdio.h>
4
5 /* static */
6
7 static double mwfact = MWFACT;
8
9 /* extern */
10
11 void
12 addtomwfact(const char *arg) {
13         double delta;
14
15         if(!isarrange(tile))
16                 return;
17
18         /* arg handling, manipulate mwfact */
19         if(arg == NULL)
20                 mwfact = MWFACT;
21         else if(1 == sscanf(arg, "%lf", &delta)) {
22                 if(delta + mwfact > 0.1 && delta + mwfact < 0.9)
23                         mwfact += delta;
24         }
25         arrange();
26 }
27
28 void
29 tile(void) {
30         unsigned int i, n, nx, ny, nw, nh, mw, th;
31         Client *c;
32
33         for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
34                 n++;
35
36         /* window geoms */
37         mw = (n == 1) ? waw : mwfact * waw;
38         th = (n > 1) ? wah / (n - 1) : 0;
39         if(n > 1 && th < bh)
40                 th = wah;
41
42         nx = wax;
43         ny = way;
44         for(i = 0, c = nexttiled(clients); c; c = nexttiled(c->next)) {
45                 c->ismax = False;
46                 if(i == 0) { /* master */
47                         nw = mw - 2 * c->border;
48                         nh = wah - 2 * c->border;
49                 }
50                 else {  /* tile window */
51                         if(i == 1) {
52                                 ny = way;
53                                 nx += mw;
54                         }
55                         nw = waw - mw - 2 * c->border;
56                         if(i + 1 == n) /* remainder */
57                                 nh = (way + wah) - ny - 2 * c->border;
58                         else
59                                 nh = th - 2 * c->border;
60                 }
61                 resize(c, nx, ny, nw, nh, False);
62                 if(n > 1 && th != wah)
63                         ny += nh + 2 * c->border;
64                 i++;
65         }
66 }
67
68 void
69 zoom(const char *arg) {
70         Client *c;
71
72         if(!sel || !isarrange(tile) || sel->isfloating)
73                 return;
74         if((c = sel) == nexttiled(clients))
75                 if(!(c = nexttiled(c->next)))
76                         return;
77         detach(c);
78         attach(c);
79         focus(c);
80         arrange();
81 }