From 2c499e84d16d4a26d92ed41680dd5faf86967702 Mon Sep 17 00:00:00 2001 From: bob8677 <68208828+bob8677@users.noreply.github.com> Date: Thu, 10 Dec 2020 04:40:25 +0000 Subject: [PATCH 1/4] init fibonacci layouts add fibonacci layouts to layouts.h add fibonacci layouts to instantwmctrl.sh add fibonacci layouts to config.def.h fix spacing in instantwmctrl add comments to layouts.c --- config.def.h | 2 + instantwmctrl.sh | 1 + layouts.c | 183 +++++++++++++++++++++++++++++++++++++++++++++++ layouts.h | 3 + 4 files changed, 189 insertions(+) diff --git a/config.def.h b/config.def.h index 96788a42..124b528c 100644 --- a/config.def.h +++ b/config.def.h @@ -119,6 +119,8 @@ static const Layout layouts[] = { { "O", overviewlayout }, { "TTT", bstack }, { "===", bstackhoriz }, + { "[@]", spiral }, + { "[\\]", dwindle }, { NULL, NULL }, }; diff --git a/instantwmctrl.sh b/instantwmctrl.sh index ea273c65..feeb4c28 100755 --- a/instantwmctrl.sh +++ b/instantwmctrl.sh @@ -31,6 +31,7 @@ layout() { ["tile"]=0 ['grid']=1 ['float']=2 ['monocle']=3 ['tcl']=4 ['deck']=5 ['overview']=6 ['bstack']=7 ['bstackhoriz']=8 + ['spiral']=9 ['dwindle']=10 ) layout=${layouts[$1]} [ -z "$layout" ] && diff --git a/layouts.c b/layouts.c index 5a340b09..0689ce6d 100644 --- a/layouts.c +++ b/layouts.c @@ -142,6 +142,189 @@ deck(Monitor *m) resize(c, m->wx + mw, m->wy, m->ww - mw - (2*c->bw), m->wh - (2*c->bw), False); } +void +fibonacci(Monitor *m, int s) { + unsigned int i, n, mx, my, mw, mh, framecount, t; + Client *c; + + if (animated && clientcount() > 4) + framecount = 4; + else + framecount = 7; + + for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++); + if(n == 0) + return; + + my = m->wy; + if (n > m->nmaster) { + if (m->nmaster) { + mw = m->ww * m->mfact; + mx = m->wx + mw; + } else { + mx = m->wx; + mh = m->wh; + mw = m->ww; + } + } else { + if (n > 1 && n < m->nmaster) { + m->nmaster = n; + fibonacci(m, s); + return; + } + mw = m->ww; + } + + for(i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next)) { + if (i < m->nmaster) { + // client is in the master + mh = (m->wy + m->wh - my) / (MIN(n, m->nmaster) - i); + animateclient(c, m->wx, my, mw - (2*c->bw), mh - (2*c->bw), framecount, 0); + if (m->nmaster == 1 && n > 1) + mx = m->wx + c->w + c->bw * 2; + if (my + HEIGHT(c) < m->wh) + my += HEIGHT(c); + if (i == m->nmaster - 1) { + my = m->wy; + mw = m->ww + m->wx - mx; + mh = m->wh; + } + i++; + } else { + // client is in the fibonacci part + if((!((i + m->nmaster) % 2) && mh / 2 > 2 * c->bw) + || ((i + m->nmaster) % 2 && mw / 2 > 2 * c->bw)) { + if(i < n - 1) { + if((i - m->nmaster) % 2) { + t = mw % 2; //checks the the number that is being divided is odd + mw /= 2; + mw += t; // if so, add one pixel here because there will otherwise be a one pixel gap. + } else { + t = mh % 2; // same thing here but for the height + mh /= 2; + mh += t; + } if((i - m->nmaster) % 4 == 1 && !s) + mx += mw - t; + else if((i - m->nmaster) % 4 == 2 && !s) + my += mh - t; + } + if((i - m->nmaster) % 4 == 0 && i != m->nmaster) + mx += mw; + else if((i - m->nmaster) % 4 == 1) + my += mh; + else if((i - m->nmaster) % 4 == 2) { + if(s) + mx += mw; + else + mx -= mw; + } + else if((i - m->nmaster) % 4 == 3) { + if(s) + my += mh; + else + my -= mh; + } + i++; + } + animateclient(c, mx, my, mw - 2 * c->bw, mh - 2 * c->bw, framecount, 0); + if((i - m->nmaster) % 2) { + if(mh / 2 > 2 * c->bw && (s || (i - m->nmaster) % 4 == 1)) { + my -= 2 * (mh - HEIGHT(c)); // these lines expands height if the client did not take up all the space + mh += mh - HEIGHT(c); + } if((i - m->nmaster) % 4 != 3 || s) + my += t; // adds to y if we are doing the spiral layout and the next client is going above this one + mh -= t; // removes the pixel that we added on earlier + } else { + if(mw / 2 > 2 * c->bw && (s || (i - m->nmaster) % 4 == 0)) { + mx -= 2 * (mw - (c->w + c->bw * 2)); //these lines do the same as above but for the x and width + mw += mw - (c->w + c->bw * 2); + } if((i - m->nmaster) % 4 != 2 || s) + mx += t; + mw -= t; + } + } + } +} + +// this is the mostly unmodified code +//void +//fibonacci(Monitor *m, int s) { +// unsigned int i, n, mx, my, mw, mh, framecount; +// Client *c; +// +// if (animated && clientcount() > 4) +// framecount = 4; +// else +// framecount = 7; +// +// for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++); +// if(n == 0) +// return; +// +// if (n > 1 && n < m->nmaster) { +// m->nmaster = n; +// fibonacci(m, s); +// return; +// } +// +// mx = m->wx; +// my = 0; +// mw = m->ww; +// mh = m->wh; +// +// for(i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next)) { +// if((!((i + m->nmaster) % 2) && mh / 2 > 2 * c->bw) +// || ((i + m->nmaster) % 2 && mw / 2 > 2 * c->bw)) { +// if(i < n - 1) { +// if(i % 2) +// mh /= 2; +// else +// mw /= 2; +// if((i % 4) == 2 && !s) +// mx += mw; +// else if((i % 4) == 3 && !s) +// my += mh; +// } +// if((i % 4) == 0) { +// if(s) +// my += mh; +// else +// my -= mh; +// } +// else if((i % 4) == 1) +// mx += mw; +// else if((i % 4) == 2) +// my += mh; +// else if((i % 4) == 3) { +// if(s) +// mx += mw; +// else +// mx -= mw; +// } +// if(i == 0) +// { +// if(n != 1) +// mw = m->ww * m->mfact; +// my = m->wy; +// } +// else if(i == 1) +// mw = m->ww - mw; +// i++; +// } +// animateclient(c, mx, my, mw - 2 * c->bw, mh - 2 * c->bw, framecount, 0); +// } +//} + +void +dwindle(Monitor *m) { + fibonacci(m, 1); +} + +void +spiral(Monitor *m) { + fibonacci(m, 0); +} + void grid(Monitor *m) { int i, n, rows, framecount; diff --git a/layouts.h b/layouts.h index f429f296..f6ea9b38 100644 --- a/layouts.h +++ b/layouts.h @@ -6,6 +6,9 @@ void bstack(Monitor *m); void bstackhoriz(Monitor *m); void deck(Monitor *m); +void fibonacci(Monitor *m, int s); +void spiral(Monitor *m); +void dwindle(Monitor *m); void grid(Monitor *m); void monocle(Monitor *m); void overviewlayout(Monitor *m); From b75441282d364069aec649df6a181746ec84f39b Mon Sep 17 00:00:00 2001 From: bob8677 <11bob8677@gmail.com> Date: Thu, 10 Dec 2020 16:44:11 -0600 Subject: [PATCH 2/4] clean up fibonacci code --- layouts.c | 162 +++++++++++++++--------------------------------------- 1 file changed, 45 insertions(+), 117 deletions(-) diff --git a/layouts.c b/layouts.c index 0689ce6d..85b7a57f 100644 --- a/layouts.c +++ b/layouts.c @@ -144,7 +144,7 @@ deck(Monitor *m) void fibonacci(Monitor *m, int s) { - unsigned int i, n, mx, my, mw, mh, framecount, t; + unsigned int i, n, my, mh, nx, ny, nh, nw, framecount, t; Client *c; if (animated && clientcount() > 4) @@ -157,164 +157,92 @@ fibonacci(Monitor *m, int s) { return; my = m->wy; + ny = m->wy; + nh = m->wh; + if (n > m->nmaster) { - if (m->nmaster) { - mw = m->ww * m->mfact; - mx = m->wx + mw; - } else { - mx = m->wx; - mh = m->wh; - mw = m->ww; - } + nx = m->nmaster ? m->wx + m->ww * m->mfact : 0; + nw = m->ww + m->wx - nx; } else { if (n > 1 && n < m->nmaster) { m->nmaster = n; fibonacci(m, s); return; } - mw = m->ww; + nx = m->ww; } for(i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next)) { if (i < m->nmaster) { // client is in the master mh = (m->wy + m->wh - my) / (MIN(n, m->nmaster) - i); - animateclient(c, m->wx, my, mw - (2*c->bw), mh - (2*c->bw), framecount, 0); - if (m->nmaster == 1 && n > 1) - mx = m->wx + c->w + c->bw * 2; - if (my + HEIGHT(c) < m->wh) + animateclient(c, m->wx, my, nx - m->wx - (2*c->bw), mh - (2*c->bw), framecount, 0); + if (m->nmaster == 1 && n > 1) { + nx = m->wx + c->w + c->bw * 2; + nw = m->ww + m->wx - nx; + } if (my + HEIGHT(c) < m->wh) my += HEIGHT(c); - if (i == m->nmaster - 1) { - my = m->wy; - mw = m->ww + m->wx - mx; - mh = m->wh; - } i++; } else { // client is in the fibonacci part - if((!((i + m->nmaster) % 2) && mh / 2 > 2 * c->bw) - || ((i + m->nmaster) % 2 && mw / 2 > 2 * c->bw)) { + if((!((i + m->nmaster) % 2) && nh / 2 > 2 * c->bw) + || ((i + m->nmaster) % 2 && nw / 2 > 2 * c->bw)) { if(i < n - 1) { if((i - m->nmaster) % 2) { - t = mw % 2; //checks the the number that is being divided is odd - mw /= 2; - mw += t; // if so, add one pixel here because there will otherwise be a one pixel gap. + t = nw % 2; //checks the the number that is being divided is odd + nw /= 2; + nw += t; // if so, add one pixel here because there will otherwise be a one pixel gap } else { - t = mh % 2; // same thing here but for the height - mh /= 2; - mh += t; + t = nh % 2; // same thing here but for the height + nh /= 2; + nh += t; } if((i - m->nmaster) % 4 == 1 && !s) - mx += mw - t; + nx += nw - t; else if((i - m->nmaster) % 4 == 2 && !s) - my += mh - t; + ny += nh - t; } if((i - m->nmaster) % 4 == 0 && i != m->nmaster) - mx += mw; + nx += nw; else if((i - m->nmaster) % 4 == 1) - my += mh; + ny += nh; else if((i - m->nmaster) % 4 == 2) { if(s) - mx += mw; + nx += nw; else - mx -= mw; + nx -= nw; } else if((i - m->nmaster) % 4 == 3) { if(s) - my += mh; + ny += nh; else - my -= mh; + ny -= nh; } i++; } - animateclient(c, mx, my, mw - 2 * c->bw, mh - 2 * c->bw, framecount, 0); + animateclient(c, nx, ny, nw - 2 * c->bw, nh - 2 * c->bw, framecount, 0); if((i - m->nmaster) % 2) { - if(mh / 2 > 2 * c->bw && (s || (i - m->nmaster) % 4 == 1)) { - my -= 2 * (mh - HEIGHT(c)); // these lines expands height if the client did not take up all the space - mh += mh - HEIGHT(c); - } if((i - m->nmaster) % 4 != 3 || s) - my += t; // adds to y if we are doing the spiral layout and the next client is going above this one - mh -= t; // removes the pixel that we added on earlier + if(nh / 2 > 2 * c->bw) { + if((i - m->nmaster) % 4 != 3 - s) { + ny -= 2 * (nh - HEIGHT(c)); // these lines expands height if the client did not take up all the space + nh += nh - HEIGHT(c); + } else if (s) + ny += t; // adds to y if the next client is not going above this one + nh -= t; // removes the pixel that we added on earlier for the next client + } } else { - if(mw / 2 > 2 * c->bw && (s || (i - m->nmaster) % 4 == 0)) { - mx -= 2 * (mw - (c->w + c->bw * 2)); //these lines do the same as above but for the x and width - mw += mw - (c->w + c->bw * 2); - } if((i - m->nmaster) % 4 != 2 || s) - mx += t; - mw -= t; + if(nw / 2 > 2 * c->bw) { + if ((i - m->nmaster) % 4 != 2 - s) { + nx -= 2 * (nw - (c->w + c->bw * 2)); //these lines do the same as above but for the x and width + nw += nw - (c->w + c->bw * 2); + } else if (s) + nx += t; + nw -= t; + } } } } } -// this is the mostly unmodified code -//void -//fibonacci(Monitor *m, int s) { -// unsigned int i, n, mx, my, mw, mh, framecount; -// Client *c; -// -// if (animated && clientcount() > 4) -// framecount = 4; -// else -// framecount = 7; -// -// for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++); -// if(n == 0) -// return; -// -// if (n > 1 && n < m->nmaster) { -// m->nmaster = n; -// fibonacci(m, s); -// return; -// } -// -// mx = m->wx; -// my = 0; -// mw = m->ww; -// mh = m->wh; -// -// for(i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next)) { -// if((!((i + m->nmaster) % 2) && mh / 2 > 2 * c->bw) -// || ((i + m->nmaster) % 2 && mw / 2 > 2 * c->bw)) { -// if(i < n - 1) { -// if(i % 2) -// mh /= 2; -// else -// mw /= 2; -// if((i % 4) == 2 && !s) -// mx += mw; -// else if((i % 4) == 3 && !s) -// my += mh; -// } -// if((i % 4) == 0) { -// if(s) -// my += mh; -// else -// my -= mh; -// } -// else if((i % 4) == 1) -// mx += mw; -// else if((i % 4) == 2) -// my += mh; -// else if((i % 4) == 3) { -// if(s) -// mx += mw; -// else -// mx -= mw; -// } -// if(i == 0) -// { -// if(n != 1) -// mw = m->ww * m->mfact; -// my = m->wy; -// } -// else if(i == 1) -// mw = m->ww - mw; -// i++; -// } -// animateclient(c, mx, my, mw - 2 * c->bw, mh - 2 * c->bw, framecount, 0); -// } -//} - void dwindle(Monitor *m) { fibonacci(m, 1); From 9e7cbe759563fab59a9ec2e9caae8c4f7c347d72 Mon Sep 17 00:00:00 2001 From: bob8677 <11bob8677@gmail.com> Date: Fri, 11 Dec 2020 12:09:54 -0600 Subject: [PATCH 3/4] fibonacci tweaks --- config.def.h | 2 +- layouts.c | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/config.def.h b/config.def.h index 124b528c..461190a2 100644 --- a/config.def.h +++ b/config.def.h @@ -119,7 +119,7 @@ static const Layout layouts[] = { { "O", overviewlayout }, { "TTT", bstack }, { "===", bstackhoriz }, - { "[@]", spiral }, + { "[@]", spiral }, { "[\\]", dwindle }, { NULL, NULL }, }; diff --git a/layouts.c b/layouts.c index 85b7a57f..4c6af2a9 100644 --- a/layouts.c +++ b/layouts.c @@ -189,7 +189,7 @@ fibonacci(Monitor *m, int s) { || ((i + m->nmaster) % 2 && nw / 2 > 2 * c->bw)) { if(i < n - 1) { if((i - m->nmaster) % 2) { - t = nw % 2; //checks the the number that is being divided is odd + t = nw % 2; //checks if the number that is being divided is odd nw /= 2; nw += t; // if so, add one pixel here because there will otherwise be a one pixel gap } else { @@ -222,21 +222,19 @@ fibonacci(Monitor *m, int s) { animateclient(c, nx, ny, nw - 2 * c->bw, nh - 2 * c->bw, framecount, 0); if((i - m->nmaster) % 2) { if(nh / 2 > 2 * c->bw) { - if((i - m->nmaster) % 4 != 3 - s) { + if(s || (i - m->nmaster) % 4 == 1) { ny -= 2 * (nh - HEIGHT(c)); // these lines expands height if the client did not take up all the space nh += nh - HEIGHT(c); - } else if (s) ny += t; // adds to y if the next client is not going above this one - nh -= t; // removes the pixel that we added on earlier for the next client + } nh -= t; // removes the pixel that we added on earlier for the next client } } else { if(nw / 2 > 2 * c->bw) { - if ((i - m->nmaster) % 4 != 2 - s) { + if (s || (i - m->nmaster) % 4 == 0) { nx -= 2 * (nw - (c->w + c->bw * 2)); //these lines do the same as above but for the x and width nw += nw - (c->w + c->bw * 2); - } else if (s) nx += t; - nw -= t; + } nw -= t; } } } From 64b1f1c8f530227c7834cb8005f99b7e894a0d07 Mon Sep 17 00:00:00 2001 From: bob8677 <11bob8677@gmail.com> Date: Mon, 11 Jan 2021 19:37:30 -0600 Subject: [PATCH 4/4] multimonitor fixes for fibonacci --- layouts.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/layouts.c b/layouts.c index 4c6af2a9..6a73d1ae 100644 --- a/layouts.c +++ b/layouts.c @@ -161,7 +161,7 @@ fibonacci(Monitor *m, int s) { nh = m->wh; if (n > m->nmaster) { - nx = m->nmaster ? m->wx + m->ww * m->mfact : 0; + nx = m->nmaster ? m->wx + m->ww * m->mfact : m->wx; nw = m->ww + m->wx - nx; } else { if (n > 1 && n < m->nmaster) { @@ -169,7 +169,7 @@ fibonacci(Monitor *m, int s) { fibonacci(m, s); return; } - nx = m->ww; + nx = m->ww + m->wx; } for(i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next)) {