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