summaryrefslogtreecommitdiffstats
path: root/dwl-patches/patches/nextlayout/nextlayout.patch
blob: 11f4dc7b81632f6d737b80f12acf1cb93e189bf9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
From 7d8cfa63681830a3af4512799b8260f8249bc514 Mon Sep 17 00:00:00 2001
From: sewn <sewn@disroot.org>
Date: Sun, 8 Sep 2024 22:49:33 +0300
Subject: [PATCH] add feature to switch to next available layout

ported from suckless cyclelayouts to be slightly more useful
https://dwm.suckless.org/patches/cyclelayouts/
---
 config.def.h |  2 ++
 dwl.c        | 12 ++++++++++++
 2 files changed, 14 insertions(+)

diff --git a/config.def.h b/config.def.h
index 22d2171..f88a615 100644
--- a/config.def.h
+++ b/config.def.h
@@ -34,6 +34,7 @@ static const Layout layouts[] = {
 	{ "[]=",      tile },
 	{ "><>",      NULL },    /* no layout function means floating behavior */
 	{ "[M]",      monocle },
+	{ NULL,       NULL }, /* terminate */
 };
 
 /* monitors */
@@ -140,6 +141,7 @@ static const Key keys[] = {
 	{ MODKEY,                    XKB_KEY_f,          setlayout,      {.v = &layouts[1]} },
 	{ MODKEY,                    XKB_KEY_m,          setlayout,      {.v = &layouts[2]} },
 	{ MODKEY,                    XKB_KEY_space,      setlayout,      {0} },
+	{ MODKEY,                    XKB_KEY_n,          nextlayout,    {0} },
 	{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_space,      togglefloating, {0} },
 	{ MODKEY,                    XKB_KEY_e,         togglefullscreen, {0} },
 	{ MODKEY,                    XKB_KEY_0,          view,           {.ui = ~0} },
diff --git a/dwl.c b/dwl.c
index a2711f6..a66d9d9 100644
--- a/dwl.c
+++ b/dwl.c
@@ -308,6 +308,7 @@ static void motionnotify(uint32_t time, struct wlr_input_device *device, double
 		double sy, double sx_unaccel, double sy_unaccel);
 static void motionrelative(struct wl_listener *listener, void *data);
 static void moveresize(const Arg *arg);
+static void nextlayout(const Arg *arg);
 static void outputmgrapply(struct wl_listener *listener, void *data);
 static void outputmgrapplyortest(struct wlr_output_configuration_v1 *config, int test);
 static void outputmgrtest(struct wl_listener *listener, void *data);
@@ -1927,6 +1928,17 @@ moveresize(const Arg *arg)
 	}
 }
 
+void
+nextlayout(const Arg *arg)
+{
+	Layout *l;
+	for(l = (Layout *)layouts; l != selmon->lt[selmon->sellt]; l++);
+	if(l->symbol && (l + 1)->symbol)
+		setlayout(&((Arg) { .v = (l + 1) }));
+	else
+		setlayout(&((Arg) { .v = layouts }));
+}
+
 void
 outputmgrapply(struct wl_listener *listener, void *data)
 {
-- 
2.46.0