Commit: 79f4c6e7750f5ecc767e6fe905b3f90121d22545
Parent: 78d3c57062c730fe04b225c00e7d9668ffbbb3d0
Author: Hiltjo Posthuma
Date: Sat, 7 May 2022 23:59:19 +0200
add functions for cycling between layouts
Diffstat:
3 files changed, 42 insertions(+), 3 deletions(-)
diff --git a/config.def.h b/config.def.h
@@ -68,6 +68,7 @@ static const Layout layouts[] = {
{ "M[]", deck },
{ "|M|", centeredmaster },
{ "><>", NULL }, /* no layout function means floating behavior */
+ { NULL, NULL }, /* terminator for {next,prev}layout() */
};
/* key definitions */
@@ -127,7 +128,8 @@ static const Key keys[] = {
{ MODKEY|ShiftMask, XK_r, setlayout, {.v = &layouts[5]} }, /* deck */
{ MODKEY, XK_u, setlayout, {.v = &layouts[6]} }, /* centermaster */
{ MODKEY|ShiftMask, XK_y, setlayout, {.v = &layouts[7]} }, /* float */
- { MODKEY, XK_space, setlayout, {0} }, /* last layout */
+ { MODKEY, XK_space, nextlayout, {0} },
+ { MODKEY|ControlMask, XK_space, prevlayout, {0} },
{ MODKEY|ShiftMask, XK_space, togglefloating, {0} },
{ MODKEY, XK_f, togglefullscr, {0} },
{ MODKEY|ShiftMask, XK_f, togglefakefull, {0} },
diff --git a/dwm.1 b/dwm.1
@@ -107,8 +107,11 @@ Sets horizontal grid layout.
.B Mod1-Shift-r
Sets deck layout.
.TP
-.B Mod1\-space
-Toggles between current and previous layout.
+.B Mod1-space
+Cycles to the next layout.
+.TP
+.B Mod1-Ctrl-space
+Cycles to the previous layout.
.TP
.B Mod1\-f
Fullscreens focused window.
diff --git a/dwm.c b/dwm.c
@@ -208,6 +208,8 @@ static void setclientstate(Client *c, long state);
static void setfocus(Client *c);
static void setfullscreen(Client *c, int fullscreen);
static void setlayout(const Arg *arg);
+static void nextlayout(const Arg *arg);
+static void prevlayout(const Arg *arg);
static void setmfact(const Arg *arg);
static void setup(void);
static void seturgent(Client *c, int urg);
@@ -1566,6 +1568,38 @@ setlayout(const Arg *arg)
drawbar(selmon);
}
+void
+nextlayout(const Arg *arg)
+{
+ const Layout *l;
+ Arg a;
+
+ for (l = layouts; l != selmon->lt[selmon->sellt]; l++);
+
+ if (l->symbol && (l + 1)->symbol)
+ a.v = (l + 1);
+ else
+ a.v = layouts;
+
+ setlayout(&a);
+}
+
+void
+prevlayout(const Arg *arg)
+{
+ const Layout *l;
+ Arg a;
+
+ for (l = layouts; l != selmon->lt[selmon->sellt]; l++);
+
+ if (l != layouts && (l - 1)->symbol)
+ a.v = (l - 1);
+ else
+ a.v = &layouts[LENGTH(layouts) - 2];
+
+ setlayout(&a);
+}
+
/* arg > 1.0 will set mfact absolutely */
void
setmfact(const Arg *arg)