Function to cycle through available layouts.

This commit is contained in:
Vladislav Nepogodin 2021-07-27 23:01:45 +04:00 committed by Leonardo Hernández Hernández
parent 46dcc997e2
commit 879021bd94
No known key found for this signature in database
GPG key ID: E538897EE11B9624
2 changed files with 22 additions and 0 deletions

View file

@ -36,6 +36,7 @@ static const Layout layouts[] = {
{ "[]=", tile },
{ "><>", NULL }, /* no layout function means floating behavior */
{ "[M]", monocle },
{ NULL, NULL },
};
/* monitors
@ -149,6 +150,8 @@ static const Key keys[] = {
{ MODKEY, XKB_KEY_t, setlayout, {.v = &layouts[0]} },
{ MODKEY, XKB_KEY_f, setlayout, {.v = &layouts[1]} },
{ MODKEY, XKB_KEY_m, setlayout, {.v = &layouts[2]} },
{ MODKEY|WLR_MODIFIER_CTRL, XKB_KEY_comma, cyclelayout, {.i = -1 } },
{ MODKEY|WLR_MODIFIER_CTRL, XKB_KEY_period, cyclelayout, {.i = +1 } },
{ MODKEY, XKB_KEY_space, setlayout, {0} },
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_space, togglefloating, {0} },
{ MODKEY, XKB_KEY_e, togglefullscreen, {0} },

19
dwl.c
View file

@ -280,6 +280,7 @@ static void createpointerconstraint(struct wl_listener *listener, void *data);
static void cursorconstrain(struct wlr_pointer_constraint_v1 *constraint);
static void cursorframe(struct wl_listener *listener, void *data);
static void cursorwarptoconstrainthint(void);
static void cyclelayout(const Arg *arg);
static void destroydragicon(struct wl_listener *listener, void *data);
static void destroyidleinhibitor(struct wl_listener *listener, void *data);
static void destroylayersurfacenotify(struct wl_listener *listener, void *data);
@ -1324,6 +1325,24 @@ cursorwarptoconstrainthint(void)
}
}
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] }));
}
}
void
destroydragicon(struct wl_listener *listener, void *data)
{