tile.c (view raw)
1/* See LICENSE file for copyright and license details. */
2#include "dwm.h"
3#include <stdio.h>
4
5/* static */
6
7static double mwfact = MWFACT;
8
9/* extern */
10
11void
12setmwfact(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
33void
34tile(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
72void
73zoom(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}