dwm

personal fork of dwm (rnpnr branch)
git clone anongit@rnpnr.xyz:dwm.git
Log | Files | Refs | Feed | README | LICENSE

Commit: b71369a51be6ab4cc9c6b9efe85c45ce5d34e283
Parent: 2d1408470531bce2edd5d17aef7434ee01252917
Author: Hiltjo Posthuma
Date:   Sat,  7 May 2022 23:59:19 +0200

add functions for cycling between layouts

Diffstat:
Mconfig.def.h | 4+++-
Mdwm.1 | 7+++++--
Mdwm.c | 34++++++++++++++++++++++++++++++++++
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 @@ -207,6 +207,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); @@ -1565,6 +1567,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)