dwm-flexipatch/patch/layout_gapplessgrid.c

99 lines
2.2 KiB
C
Raw Normal View History

2019-09-09 17:11:31 +00:00
#if VANITYGAPS_PATCH
void
gaplessgrid(Monitor *m)
{
2020-05-10 08:40:47 +00:00
unsigned int i, n;
int x, y, cols, rows, ch, cw, cn, rn, rrest, crest; // counters
2019-09-09 17:11:31 +00:00
int oh, ov, ih, iv;
Client *c;
getgaps(m, &oh, &ov, &ih, &iv, &n);
if (n == 0)
return;
/* grid dimensions */
for (cols = 0; cols <= n/2; cols++)
if (cols*cols >= n)
break;
if (n == 5) /* set layout against the general calculation: not 1:2:2, but 2:3 */
cols = 2;
rows = n/cols;
2020-05-10 08:40:47 +00:00
cn = rn = 0; // reset column no, row no, client count
ch = (m->wh - 2*oh - ih * (rows - 1)) / rows;
cw = (m->ww - 2*ov - iv * (cols - 1)) / cols;
rrest = (m->wh - 2*oh - ih * (rows - 1)) - ch * rows;
crest = (m->ww - 2*ov - iv * (cols - 1)) - cw * cols;
x = m->wx + ov;
y = m->wy + oh;
2019-09-09 17:11:31 +00:00
for (i = 0, c = nexttiled(m->clients); c; i++, c = nexttiled(c->next)) {
2020-05-10 08:40:47 +00:00
if (i/rows + 1 > cols - n%cols) {
2019-09-09 17:11:31 +00:00
rows = n/cols + 1;
2020-05-10 08:40:47 +00:00
ch = (m->wh - 2*oh - ih * (rows - 1)) / rows;
rrest = (m->wh - 2*oh - ih * (rows - 1)) - ch * rows;
}
resize(c,
x,
y + rn*(ch + ih) + MIN(rn, rrest),
cw + (cn < crest ? 1 : 0) - 2*c->bw,
ch + (rn < rrest ? 1 : 0) - 2*c->bw,
0);
2019-09-09 17:11:31 +00:00
rn++;
if (rn >= rows) {
rn = 0;
2020-05-10 08:40:47 +00:00
x += cw + ih + (cn < crest ? 1 : 0);
2019-09-09 17:11:31 +00:00
cn++;
}
}
}
#else
void
2019-09-10 22:51:37 +00:00
gaplessgrid(Monitor *m)
{
2020-05-10 08:40:47 +00:00
unsigned int i, n;
int x, y, cols, rows, ch, cw, cn, rn, rrest, crest; // counters
2019-09-09 17:11:31 +00:00
Client *c;
2020-05-10 08:40:47 +00:00
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
2019-09-10 22:51:37 +00:00
if (n == 0)
2019-09-09 17:11:31 +00:00
return;
/* grid dimensions */
2019-09-10 22:51:37 +00:00
for (cols = 0; cols <= n/2; cols++)
if (cols*cols >= n)
2019-09-09 17:11:31 +00:00
break;
2019-09-10 22:51:37 +00:00
if (n == 5) /* set layout against the general calculation: not 1:2:2, but 2:3 */
2019-09-09 17:11:31 +00:00
cols = 2;
rows = n/cols;
2020-05-10 08:40:47 +00:00
cn = rn = 0; // reset column no, row no, client count
ch = m->wh / rows;
cw = m->ww / cols;
rrest = m->wh - ch * rows;
crest = m->ww - cw * cols;
x = m->wx;
y = m->wy;
2019-09-09 17:11:31 +00:00
2019-09-10 22:51:37 +00:00
for (i = 0, c = nexttiled(m->clients); c; i++, c = nexttiled(c->next)) {
2020-05-10 08:40:47 +00:00
if (i/rows + 1 > cols - n%cols) {
2019-09-09 17:11:31 +00:00
rows = n/cols + 1;
2020-05-10 08:40:47 +00:00
ch = m->wh / rows;
rrest = m->wh - ch * rows;
}
resize(c,
x,
y + rn*ch + MIN(rn, rrest),
cw + (cn < crest ? 1 : 0) - 2*c->bw,
ch + (rn < rrest ? 1 : 0) - 2*c->bw,
0);
2019-09-09 17:11:31 +00:00
rn++;
2019-09-10 22:51:37 +00:00
if (rn >= rows) {
2019-09-09 17:11:31 +00:00
rn = 0;
2020-05-10 08:40:47 +00:00
x += cw + (cn < crest ? 1 : 0);
2019-09-09 17:11:31 +00:00
cn++;
}
}
}
2019-09-10 22:51:37 +00:00
#endif