dwm-flexipatch/patch/layout_fibonacci.c

192 lines
3.1 KiB
C
Raw Normal View History

2019-09-09 16:50:05 +00:00
#if VANITYGAPS_PATCH
2020-05-10 08:31:11 +00:00
void
2019-09-09 16:50:05 +00:00
fibonacci(Monitor *m, int s)
{
unsigned int i, n;
int nx, ny, nw, nh;
int oh, ov, ih, iv;
2020-05-10 08:31:11 +00:00
int nv, hrest = 0, wrest = 0, r = 1;
2019-09-09 16:50:05 +00:00
Client *c;
getgaps(m, &oh, &ov, &ih, &iv, &n);
if (n == 0)
return;
nx = m->wx + ov;
ny = oh;
nw = m->ww - 2*ov;
nh = m->wh - 2*oh;
for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next)) {
2020-05-10 08:31:11 +00:00
if (r) {
if ((i % 2 && (nh - ih) / 2 <= (bh + 2*c->bw))
|| (!(i % 2) && (nw - iv) / 2 <= (bh + 2*c->bw))) {
r = 0;
}
if (r && i < n - 1) {
if (i % 2) {
nv = (nh - ih) / 2;
hrest = nh - 2*nv - ih;
nh = nv;
} else {
nv = (nw - iv) / 2;
wrest = nw - 2*nv - iv;
nw = nv;
}
2019-09-09 16:50:05 +00:00
if ((i % 4) == 2 && !s)
nx += nw + iv;
else if ((i % 4) == 3 && !s)
ny += nh + ih;
}
2020-05-10 08:31:11 +00:00
2019-09-09 16:50:05 +00:00
if ((i % 4) == 0) {
2020-05-10 08:31:11 +00:00
if (s) {
2019-09-09 16:50:05 +00:00
ny += nh + ih;
2020-05-10 08:31:11 +00:00
nh += hrest;
}
else {
nh -= hrest;
2019-09-09 16:50:05 +00:00
ny -= nh + ih;
2020-05-10 08:31:11 +00:00
}
2019-09-09 16:50:05 +00:00
}
2020-05-10 08:31:11 +00:00
else if ((i % 4) == 1) {
2019-09-09 16:50:05 +00:00
nx += nw + iv;
2020-05-10 08:31:11 +00:00
nw += wrest;
}
else if ((i % 4) == 2) {
2019-09-09 16:50:05 +00:00
ny += nh + ih;
2020-05-10 08:31:11 +00:00
nh += hrest;
if (i < n - 1)
nw += wrest;
}
2019-09-09 16:50:05 +00:00
else if ((i % 4) == 3) {
2020-05-10 08:31:11 +00:00
if (s) {
2019-09-09 16:50:05 +00:00
nx += nw + iv;
2020-05-10 08:31:11 +00:00
nw -= wrest;
} else {
nw -= wrest;
2019-09-09 16:50:05 +00:00
nx -= nw + iv;
2020-05-10 08:31:11 +00:00
nh += hrest;
}
2019-09-09 16:50:05 +00:00
}
if (i == 0) {
2020-05-10 08:31:11 +00:00
if (n != 1) {
nw = (m->ww - iv - 2*ov) - (m->ww - iv - 2*ov) * (1 - m->mfact);
wrest = 0;
}
2019-09-09 16:50:05 +00:00
ny = m->wy + oh;
}
else if (i == 1)
nw = m->ww - nw - iv - 2*ov;
i++;
}
resize(c, nx, ny, nw - (2*c->bw), nh - (2*c->bw), False);
}
}
#else
void
2020-05-10 08:31:11 +00:00
fibonacci(Monitor *m, int s)
2019-09-09 16:50:05 +00:00
{
2020-05-10 08:31:11 +00:00
unsigned int i, n;
int nx, ny, nw, nh;
int nv, hrest = 0, wrest = 0, r = 1;
2019-09-09 16:50:05 +00:00
Client *c;
2020-05-10 08:31:11 +00:00
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
2019-09-09 16:50:05 +00:00
if (n == 0)
return;
2020-05-10 08:31:11 +00:00
nx = m->wx;
ny = m->wy;
nw = m->ww;
nh = m->wh;
for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next)) {
if (r) {
if ((i % 2 && nh / 2 <= (bh + 2*c->bw))
|| (!(i % 2) && nw / 2 <= (bh + 2*c->bw))) {
r = 0;
}
if (r && i < n - 1) {
if (i % 2) {
nv = nh / 2;
hrest = nh - 2*nv;
nh = nv;
} else {
nv = nw / 2;
wrest = nw - 2*nv;
nw = nv;
}
2019-09-09 16:50:05 +00:00
if ((i % 4) == 2 && !s)
nx += nw;
else if ((i % 4) == 3 && !s)
ny += nh;
}
2020-05-10 08:31:11 +00:00
2019-09-09 16:50:05 +00:00
if ((i % 4) == 0) {
2020-05-10 08:31:11 +00:00
if (s) {
2019-09-09 16:50:05 +00:00
ny += nh;
2020-05-10 08:31:11 +00:00
nh += hrest;
}
else {
nh -= hrest;
2019-09-09 16:50:05 +00:00
ny -= nh;
2020-05-10 08:31:11 +00:00
}
2019-09-09 16:50:05 +00:00
}
2020-05-10 08:31:11 +00:00
else if ((i % 4) == 1) {
2019-09-09 16:50:05 +00:00
nx += nw;
2020-05-10 08:31:11 +00:00
nw += wrest;
}
else if ((i % 4) == 2) {
2019-09-09 16:50:05 +00:00
ny += nh;
2020-05-10 08:31:11 +00:00
nh += hrest;
if (i < n - 1)
nw += wrest;
}
2019-09-09 16:50:05 +00:00
else if ((i % 4) == 3) {
2020-05-10 08:31:11 +00:00
if (s) {
2019-09-09 16:50:05 +00:00
nx += nw;
2020-05-10 08:31:11 +00:00
nw -= wrest;
} else {
nw -= wrest;
2019-09-09 16:50:05 +00:00
nx -= nw;
2020-05-10 08:31:11 +00:00
nh += hrest;
}
2019-09-09 16:50:05 +00:00
}
2020-05-10 08:31:11 +00:00
if (i == 0) {
if (n != 1) {
nw = m->ww - m->ww * (1 - m->mfact);
wrest = 0;
}
ny = m->wy;
2019-09-09 16:50:05 +00:00
}
else if (i == 1)
2020-05-10 08:31:11 +00:00
nw = m->ww - nw;
2019-09-09 16:50:05 +00:00
i++;
}
2020-05-10 08:31:11 +00:00
resize(c, nx, ny, nw - (2*c->bw), nh - (2*c->bw), False);
2019-09-09 16:50:05 +00:00
}
}
#endif
#if FIBONACCI_DWINDLE_LAYOUT
static void
dwindle(Monitor *m)
{
fibonacci(m, 1);
}
#endif
#if FIBONACCI_SPIRAL_LAYOUT
static void
spiral(Monitor *m)
{
fibonacci(m, 0);
}
2019-09-10 22:51:37 +00:00
#endif