From f713ddee39070ce85b5bad1ac20af497f8fae549 Mon Sep 17 00:00:00 2001 From: bakkeby Date: Sun, 29 Jan 2023 22:13:50 +0100 Subject: [PATCH] cyclelayouts: reimplementing patch to not require the NULL layout, addresses #331 --- config.def.h | 6 ------ patch/cyclelayouts.c | 20 ++++++-------------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/config.def.h b/config.def.h index e030ee9..d8741eb 100644 --- a/config.def.h +++ b/config.def.h @@ -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 diff --git a/patch/cyclelayouts.c b/patch/cyclelayouts.c index 81339bc..b8a6199 100644 --- a/patch/cyclelayouts.c +++ b/patch/cyclelayouts.c @@ -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 +}