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 #if NROWGRID_LAYOUT
{ "###", nrowgrid, {0} }, { "###", nrowgrid, {0} },
#endif #endif
#if CYCLELAYOUTS_PATCH
{ NULL, NULL, {0} },
#endif
}; };
#else #else
static const Layout layouts[] = { static const Layout layouts[] = {
@ -754,9 +751,6 @@ static const Layout layouts[] = {
#if NROWGRID_LAYOUT #if NROWGRID_LAYOUT
{ "###", nrowgrid }, { "###", nrowgrid },
#endif #endif
#if CYCLELAYOUTS_PATCH
{ NULL, NULL },
#endif
}; };
#endif // FLEXTILE_DELUXE_LAYOUT #endif // FLEXTILE_DELUXE_LAYOUT

View File

@ -1,18 +1,10 @@
void void
cyclelayout(const Arg *arg) cyclelayout(const Arg *arg)
{ {
Layout *l; int i;
for (l = (Layout *)layouts; l != selmon->lt[selmon->sellt]; l++); int num_layouts = LENGTH(layouts);
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] }));
}
}
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
}