JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
renamed seltag into seltags
[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 setmwfact(const char *arg) {
13         double delta, newfact;
14
15         if(!isarrange(tile))
16                 return;
17         /* arg handling, manipulate mwfact */
18         if(arg == NULL)
19                 mwfact = MWFACT;
20         else if(1 == sscanf(arg, "%lf", &delta)) {
21                 if(arg[0] != '+' && arg[0] != '-')
22                         newfact = delta;
23                 else
24                         newfact = mwfact + delta;
25                 if(newfact < 0.1)
26                         newfact = 0.1;
27                 else if(newfact > 0.9)
28                         newfact = 0.9;
29                 mwfact = newfact;
30         }
31         arrange();
32 }
33
34 void
35 tile(void) {
36         unsigned int i, n, nx, ny, nw, nh, mw, th;
37         Client *c;
38
39         for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
40                 n++;
41
42         /* window geoms */
43         mw = (n == 1) ? waw : mwfact * waw;
44         th = (n > 1) ? wah / (n - 1) : 0;
45         if(n > 1 && th < bh)
46                 th = wah;
47
48         nx = wax;
49         ny = way;
50         for(i = 0, c = nexttiled(clients); c; c = nexttiled(c->next)) {
51                 c->ismax = False;
52                 if(i == 0) { /* master */
53                         nw = mw - 2 * c->border;
54                         nh = wah - 2 * c->border;
55                 }
56                 else {  /* tile window */
57                         if(i == 1) {
58                                 ny = way;
59                                 nx += mw;
60                         }
61                         nw = waw - mw - 2 * c->border;
62                         if(i + 1 == n) /* remainder */
63                                 nh = (way + wah) - ny - 2 * c->border;
64                         else
65                                 nh = th - 2 * c->border;
66                 }
67                 resize(c, nx, ny, nw, nh, False);
68                 if(n > 1 && th != wah)
69                         ny += nh + 2 * c->border;
70                 i++;
71         }
72 }
73
74 void
75 zoom(const char *arg) {
76         Client *c;
77
78         if(!sel || !isarrange(tile) || sel->isfloating)
79                 return;
80         if((c = sel) == nexttiled(clients))
81                 if(!(c = nexttiled(c->next)))
82                         return;
83         detach(c);
84         attach(c);
85         focus(c);
86         arrange();
87 }