-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayouts.c
211 lines (183 loc) · 5.01 KB
/
layouts.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
static void
monocle(Monitor *m)
{
unsigned int n = 0;
Client *c;
for (c = m->clients; c; c = c->next)
if (ISVISIBLE(c))
n++;
if (n > 0) /* override layout symbol */
snprintf(m->ltsymbol, sizeof m->ltsymbol, "[%d]", n);
for (c = nexttiled(m->clients); c; c = nexttiled(c->next))
resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw, 0);
}
static void
mastergrid(Monitor *m) {
int i, gap;
unsigned int n, cols, rows, cn, rn, cx, cy, cw, ch, mw, mh, my, eh = 0;
Client *c;
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
if (n == 0)
return;
/* dynamic gapps if there are more than 4 slaves */
if (n > 4) {
gap = ((gap = gappx - 2*(n - 4)) > 0) ? gap : 0;
} else
gap = gappx;
/* vertical monitor, vertically stacked windows */
if (m->mh > m->mw)
m->nmaster = 0;
/* if one window or nmaster 0 then full width master window */
if (n <= 1 || m->nmaster == 0) {
mw = m->ww;
/* scaled master window */
} else {
/* scale master window's width */
mw = m->ww*m->mfact;
/* ignore master window's count to calculate slave grids */
n--;
}
/* Calculate how many rows required */
for (rows = 1; rows*rows < n; rows++);
/* set tiling layout until we have more than 3 slaves */
if (n == 3)
rows = 3;
cols = n/rows;
/* window geometries */
ch = rows ? (m->wh-gap) / rows : m->wh;
cn = 0; /* current column number */
rn = 0; /* current row number */
my = gap; /* master y coord. */
for (i = -1, c = nexttiled(m->clients); c; i++, c = nexttiled(c->next)) {
if (i == -1 || m->nmaster == 0) {
mh = (m->wh - my) / ((m->nmaster ? 1 : n) - i - 1);
resize(c, m->wx + gap, m->wy + my,
mw - 2*c->bw - 2*gap, mh - 2*c->bw - gap,0);
my += HEIGHT(c) + gap;
continue;
}
if (i/cols + 1 > rows - n%rows)
cols = n/rows + 1;
cw = cols ? (m->ww - mw)/cols : (m->ww - mw) - gap;
cx = m->wx + cn*cw + mw;
cy = m->wy + rn*ch;
if (++cn >= cols) {
cn = 0;
rn++;
}
/* add unused pixels to the bottom row clients */
if (rn == rows - 1)
eh = m->wh - ch*rows - gap;
resize(c, cx, cy + gap, cw - 2*c->bw - gap,
ch - 2*c->bw - gap + eh, 0);
}
}
/* There is gappx implemented by gg. Rest is gappless grid patch. */
static void
gapfulgrid(Monitor *m) {
unsigned int n, cols, rows, cn, rn, i, cx, cy, cw, ch;
Client *c;
for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
if(n == 0)
return;
/* grid dimensions */
for (cols = 0; cols*cols < n; cols++);
rows = n/cols;
/* window geometries */
cw = cols ? (m->ww-gappx) / cols : m->ww;
cn = 0; /* current column number */
rn = 0; /* current row number */
for(i = 0, c = nexttiled(m->clients); c; i++, c = nexttiled(c->next)) {
if(i/rows + 1 > cols - n%cols)
rows = n/cols + 1;
ch = rows ? (m->wh-gappx) / rows : m->wh;
cx = m->wx + cn*cw;
cy = m->wy + rn*ch;
/* prepare to move to the next column */
if(++rn >= rows) {
rn = 0;
cn++;
/* add unused pixels to the bottom row clients */
ch += m->wh - ch*rows - gappx;
}
resize(c,
cx + gappx,
cy + gappx,
cw - 2 * c->bw - gappx,
ch - 2 * c->bw - gappx,
0);
}
}
#ifdef extra_layouts
static void
vertmastergrid(Monitor *m) {
int i;
unsigned int n, cols, rows, cn, rn, cx, cy, cw, ch, mw;
Client *c;
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++) ;
if (n == 0)
return;
if (n > 1) {
/* scale master window's width */
mw = m->ww * m->mfact;
/* reduce number windows for calculating slave grids */
n--;
} else
mw = m->ww;
/* Calculate how many columns are required */
for (cols = 0; cols*cols < n; cols++);
rows = n/cols;
/* window geometries */
cw = cols ? (m->ww - mw) / cols : (m->ww - mw);
cn = 0; /* current column number */
rn = 0; /* current row number */
for (i = -1, c = nexttiled(m->clients); c; i++, c = nexttiled(c->next)) {
if (i == -1) {
cy = 0; //gappx;
resize(c,
m->wx, //+ gappx,
m->wy + cy,
mw - (2*c->bw),// - 2*gappx,
m->wh - cy - (2*c->bw), //- gappx,
0);
continue;
}
if (i/rows + 1 > cols - n%cols)
rows = n/cols + 1;
ch = rows ? m->wh / rows : m->wh;
cx = m->wx + cn*cw + mw;
cy = m->wy + rn*ch;
resize(c, cx, cy, cw - 2 * c->bw, ch - 2 * c->bw, False);
rn++;
if (rn >= rows) {
rn = 0;
cn++;
}
}
}
static void
tile(Monitor *m)
{
unsigned int i, n, h, mw, my, ty;
Client *c;
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
if (n == 0)
return;
if (n > m->nmaster)
mw = m->nmaster ? m->ww * m->mfact : gappx;
else
mw = m->ww;
for (i = 0, my = ty = gappx, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
if (i < m->nmaster) {
h = (m->wh - my) / (MIN(n, m->nmaster) - i) - gappx;
resize(c, m->wx + gappx, m->wy + my, mw - (2*c->bw) - 2*gappx, h - (2*c->bw), 0);
if (my + HEIGHT(c) < m->wh)
my += HEIGHT(c) + gappx;
} else {
h = (m->wh - ty) / (n - i) - gappx;
resize(c, m->wx + mw, m->wy + ty, m->ww - mw - (2*c->bw) - gappx, h - (2*c->bw), 0);
if (ty + HEIGHT(c) < m->wh)
ty += HEIGHT(c) + gappx;
}
}
#endif