Adding gappless grid layout

This commit is contained in:
bakkeby 2019-09-09 19:11:31 +02:00
parent cccb8fcecb
commit 9081aef748
14 changed files with 143 additions and 68 deletions

View File

@ -11,7 +11,7 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t
### Changelog:
2019-09-09 - Added deck, fibonacci (dwindle and spiral) layouts
2019-09-09 - Added deck, fibonacci (dwindle and spiral) and gapplessgrid layouts
2019-09-08 - Added cfacts and vanitygaps patches, added bstack and bstackhoriz layouts
@ -120,3 +120,6 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t
- [fibonacci](https://dwm.suckless.org/patches/fibonacci/)
- fibonacci (dwindle and spiral) layouts
- [gapplessgrid](https://dwm.suckless.org/patches/gaplessgrid/)
- gappless grid layout

View File

@ -9,7 +9,8 @@ bstack(Monitor *m)
float mfacts, sfacts;
Client *c;
getgaps(m, &oh, &ov, &ih, &iv, &n, &mfacts, &sfacts);
getgaps(m, &oh, &ov, &ih, &iv, &n);
getfacts(m, &mfacts, &sfacts);
if (n == 0)
return;
@ -81,19 +82,15 @@ bstack(Monitor *m)
unsigned int i, n;
int mx = 0, my = 0, mh = 0, mw = 0;
int sx = 0, sy = 0, sh = 0, sw = 0;
float mfacts = 1, sfacts = 1;
float mfacts, sfacts;
Client *c;
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++) {
if (n < m->nmaster)
mfacts += c->cfact;
else
sfacts += c->cfact;
}
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
if (n == 0)
return;
getfacts(m, &mfacts, &sfacts);
sx = mx = m->wx;
sy = my = m->wy;
sh = mh = m->wh;

View File

@ -9,7 +9,8 @@ bstackhoriz(Monitor *m)
float mfacts, sfacts;
Client *c;
getgaps(m, &oh, &ov, &ih, &iv, &n, &mfacts, &sfacts);
getgaps(m, &oh, &ov, &ih, &iv, &n);
getfacts(m, &mfacts, &sfacts);
if (n == 0)
return;
@ -82,19 +83,15 @@ bstackhoriz(Monitor *m)
unsigned int i, n;
int mx = 0, my = 0, mh = 0, mw = 0;
int sx = 0, sy = 0, sh = 0, sw = 0;
float mfacts = 1, sfacts = 1;
float mfacts, sfacts;
Client *c;
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++) {
if (n < m->nmaster)
mfacts += c->cfact;
else
sfacts += c->cfact;
}
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
if (n == 0)
return;
getfacts(m, &mfacts, &sfacts);
sx = mx = m->wx;
sy = my = m->wy;
sh = mh = m->wh;

View File

@ -15,3 +15,19 @@ setcfact(const Arg *arg) {
c->cfact = f;
arrange(selmon);
}
void
getfacts(Monitor *m, float *mf, float *sf)
{
float mfacts = 0, sfacts = 0;
Client *c;
for (c = nexttiled(m->clients); c; c = nexttiled(c->next)) {
if (!m->nmaster || n < m->nmaster)
mfacts += c->cfact;
else
sfacts += c->cfact;
}
*mf = mfacts; // total factor of master area
*sf = sfacts; // total factor of slave area
}

View File

@ -1 +1,2 @@
static void getfacts(Monitor *m, float *mf, float *sf)
static void setcfact(const Arg *arg);

View File

@ -9,7 +9,8 @@ deck(Monitor *m)
float mfacts, sfacts;
Client *c;
getgaps(m, &oh, &ov, &ih, &iv, &n, &mfacts, &sfacts);
getgaps(m, &oh, &ov, &ih, &iv, &n);
getfacts(m, &mfacts, &sfacts);
if (n == 0)
return;
@ -82,19 +83,15 @@ deck(Monitor *m)
unsigned int i, n;
int mx = 0, my = 0, mh = 0, mw = 0;
int sx = 0, sy = 0, sh = 0, sw = 0;
float mfacts = 1, sfacts = 1;
float mfacts, sfacts;
Client *c;
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++) {
if (n < m->nmaster)
mfacts += c->cfact;
else
sfacts += c->cfact;
}
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
if (n == 0)
return;
getfacts(m, &mfacts, &sfacts);
sx = mx = m->wx;
sy = my = m->wy;
sh = mh = m->wh;
@ -127,7 +124,6 @@ deck(Monitor *m)
Client *c;
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
if (n == 0)
return;

76
patch/gapplessgrid.c Normal file
View File

@ -0,0 +1,76 @@
#if VANITYGAPS_PATCH
void
gaplessgrid(Monitor *m)
{
unsigned int n, cols, rows, cn, rn, i, cx, cy, cw, ch;
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;
/* window geometries */
cw = cols ? (m->ww - 2*ov - iv*(cols - 1)) / cols : m->ww - 2*ov;
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 - 2*oh - ih*(rows - 1)) / rows : m->wh - 2*oh;
cx = m->wx + ov + cn*(cw + iv);
cy = m->wy + oh + rn*(ch + ih);
resize(c, cx, cy, cw - 2*c->bw, ch - 2*c->bw, False);
rn++;
if (rn >= rows) {
rn = 0;
cn++;
}
}
}
#else
void
gaplessgrid(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 <= 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;
/* window geometries */
cw = cols ? m->ww / 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 / rows : m->wh;
cx = m->wx + cn*cw;
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++;
}
}
}
#endif

1
patch/gapplessgrid.h Normal file
View File

@ -0,0 +1 @@
static void gaplessgrid(Monitor *m);

View File

@ -70,6 +70,10 @@
#include "fibonacci.c"
#endif
#if GAPPLESSGRID_LAYOUT
#include "gapplessgrid.c"
#endif
#if MONOCLE_LAYOUT
#include "monocle.c"
#endif

View File

@ -66,6 +66,10 @@
#include "fibonacci.h"
#endif
#if GAPPLESSGRID_LAYOUT
#include "gapplessgrid.h"
#endif
#if MONOCLE_LAYOUT
#include "monocle.h"
#endif

View File

@ -9,7 +9,8 @@ tile(Monitor *m)
float mfacts, sfacts;
Client *c;
getgaps(m, &oh, &ov, &ih, &iv, &n, &mfacts, &sfacts);
getgaps(m, &oh, &ov, &ih, &iv, &n);
getfacts(m, &mfacts, &sfacts);
if (n == 0)
return;
@ -78,19 +79,15 @@ tile(Monitor *m)
unsigned int i, n;
int mx = 0, my = 0, mh = 0, mw = 0;
int sx = 0, sy = 0, sh = 0, sw = 0;
float mfacts = 1, sfacts = 1;
float mfacts, sfacts;
Client *c;
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++) {
if (n < m->nmaster)
mfacts += c->cfact;
else
sfacts += c->cfact;
}
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
if (n == 0)
return;
getfacts(m, &mfacts, &sfacts);
sx = mx = m->wx;
sy = my = m->wy;
sh = mh = m->wh;

View File

@ -107,26 +107,12 @@ incrivgaps(const Arg *arg)
}
static void
#if CFACTS_PATCH
getgaps(Monitor *m, int *oh, int *ov, int *ih, int *iv, unsigned int *nc, float *mf, float *sf)
#else
getgaps(Monitor *m, int *oh, int *ov, int *ih, int *iv, unsigned int *nc)
#endif // CFACTS_PATCH
{
unsigned int n, oe = enablegaps, ie = enablegaps;
#if CFACTS_PATCH
float mfacts = 0, sfacts = 0;
#endif // CFACTS_PATCH
Client *c;
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++) {
#if CFACTS_PATCH
if (!m->nmaster || n < m->nmaster)
mfacts += c->cfact;
else
sfacts += c->cfact;
#endif // CFACTS_PATCH
}
for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
if (smartgaps && n == 1) {
oe = 0; // outer gaps disabled when only one client
}
@ -136,8 +122,4 @@ getgaps(Monitor *m, int *oh, int *ov, int *ih, int *iv, unsigned int *nc )
*ih = m->gappih*ie; // inner horizontal gap
*iv = m->gappiv*ie; // inner vertical gap
*nc = n; // number of clients
#if CFACTS_PATCH
*mf = mfacts; // total factor of master area
*sf = sfacts; // total factor of slave area
#endif // CFACTS_PATCH
}

View File

@ -10,9 +10,5 @@ static void incrivgaps(const Arg *arg);
static void togglegaps(const Arg *arg);
/* Internals */
#if CFACTS_PATCH
static void getgaps(Monitor *m, int *oh, int *ov, int *ih, int *iv, unsigned int *nc, float *mf, float *sf);
#else
static void getgaps(Monitor *m, int *oh, int *ov, int *ih, int *iv, unsigned int *nc);
#endif // CFACTS_PATCH
static void setgaps(int oh, int ov, int ih, int iv);

View File

@ -190,27 +190,32 @@
/* Bottomstack layout.
* https://dwm.suckless.org/patches/bottomstack/
*/
#define BSTACK_LAYOUT 0
#define BSTACK_LAYOUT 1
/* Bottomstack horizontal layout.
* https://dwm.suckless.org/patches/bottomstack/
*/
#define BSTACKHORIZ_LAYOUT 0
#define BSTACKHORIZ_LAYOUT 1
/* Deck layout.
* https://dwm.suckless.org/patches/deck/
*/
#define DECK_LAYOUT 0
#define DECK_LAYOUT 1
/* Fibonacci dwindle layout.
* https://dwm.suckless.org/patches/fibonacci/
*/
#define FIBONACCI_DWINDLE_LAYOUT 0
#define FIBONACCI_DWINDLE_LAYOUT 1
/* Fibonacci spiral layout.
* https://dwm.suckless.org/patches/fibonacci/
*/
#define FIBONACCI_SPIRAL_LAYOUT 0
#define FIBONACCI_SPIRAL_LAYOUT 1
/* Gappless grid layout.
* https://dwm.suckless.org/patches/gaplessgrid/
*/
#define GAPPLESSGRID_LAYOUT 1
/* The default tile layout.
* This can be optionally disabled in favour of other layouts.