cyclelayouts: reimplementing patch to not require the NULL layout, addresses #331

This commit is contained in:
bakkeby 2023-01-29 22:13:50 +01:00
parent 954e60b735
commit f713ddee39
2 changed files with 6 additions and 20 deletions

View File

@ -704,9 +704,6 @@ static const Layout layouts[] = {
#if NROWGRID_LAYOUT
{ "###", nrowgrid, {0} },
#endif
#if CYCLELAYOUTS_PATCH
{ NULL, NULL, {0} },
#endif
};
#else
static const Layout layouts[] = {
@ -754,9 +751,6 @@ static const Layout layouts[] = {
#if NROWGRID_LAYOUT
{ "###", nrowgrid },
#endif
#if CYCLELAYOUTS_PATCH
{ NULL, NULL },
#endif
};
#endif // FLEXTILE_DELUXE_LAYOUT

View File

@ -1,18 +1,10 @@
void
cyclelayout(const Arg *arg)
{
Layout *l;
for (l = (Layout *)layouts; l != selmon->lt[selmon->sellt]; l++);
if (arg->i > 0) {
if (l->symbol && (l + 1)->symbol)
setlayout(&((Arg) { .v = (l + 1) }));
else
setlayout(&((Arg) { .v = layouts }));
} else {
if (l != layouts && (l - 1)->symbol)
setlayout(&((Arg) { .v = (l - 1) }));
else
setlayout(&((Arg) { .v = &layouts[LENGTH(layouts) - 2] }));
}
}
int i;
int num_layouts = LENGTH(layouts);
for (i = 0; i < num_layouts && &layouts[i] != selmon->lt[selmon->sellt]; i++);
i += arg->i;
setlayout(&((Arg) { .v = &layouts[(i % num_layouts + num_layouts) % num_layouts] })); // modulo
}