summaryrefslogtreecommitdiffstats
path: root/dwl-patches/patches/mastercolumn/mastercolumn.patch
blob: 425e41472d3567832ad4ab5f7a1a8df47cc59625 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
From eb0c6ff53ba823f26d13f18627a084959c353627 Mon Sep 17 00:00:00 2001
From: moe <moemmakki@gmail.com>
Date: Sat, 10 Aug 2024 15:58:15 -0400
Subject: [PATCH] add mastercolumn layout

---
 config.def.h |  2 ++
 dwl.c        | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/config.def.h b/config.def.h
index 22d2171..68b27a7 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 },
+	{ "||=",      mastercol },
 };
 
 /* monitors */
@@ -139,6 +140,7 @@ 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,                    XKB_KEY_c,          setlayout,      {.v = &layouts[3]} },
 	{ MODKEY,                    XKB_KEY_space,      setlayout,      {0} },
 	{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_space,      togglefloating, {0} },
 	{ MODKEY,                    XKB_KEY_e,         togglefullscreen, {0} },
diff --git a/dwl.c b/dwl.c
index a2711f6..49f65ba 100644
--- a/dwl.c
+++ b/dwl.c
@@ -301,6 +301,7 @@ static int keyrepeat(void *data);
 static void killclient(const Arg *arg);
 static void locksession(struct wl_listener *listener, void *data);
 static void mapnotify(struct wl_listener *listener, void *data);
+static void mastercol(Monitor *m);
 static void maximizenotify(struct wl_listener *listener, void *data);
 static void monocle(Monitor *m);
 static void motionabsolute(struct wl_listener *listener, void *data);
@@ -1748,6 +1749,41 @@ unset_fullscreen:
 	}
 }
 
+void
+mastercol(Monitor *m)
+{
+	unsigned int mw, mx, ty;
+	int i, n = 0;
+	Client *c;
+
+	wl_list_for_each(c, &clients, link)
+		if (VISIBLEON(c, m) && !c->isfloating && !c->isfullscreen)
+			n++;
+	if (n == 0)
+		return;
+
+	if (n > m->nmaster)
+		mw = m->nmaster ? (int)roundf(m->w.width * m->mfact) : 0;
+	else
+		mw = m->w.width;
+	i = mx = ty = 0;
+	wl_list_for_each(c, &clients, link) {
+		if (!VISIBLEON(c, m) || c->isfloating || c->isfullscreen)
+			continue;
+		if (i < m->nmaster) {
+			resize(c, (struct wlr_box){.x = m->w.x + mx, .y = m->w.y,
+				.width = (mw - mx) / (MIN(n, m->nmaster) - i), .height = m->w.height}, 0);
+			mx += c->geom.width;
+		} else {
+			resize(c, (struct wlr_box){.x = m->w.x + mw, .y = m->w.y + ty,
+				.width = m->w.width - mw, .height = (m->w.height - ty) / (n - i)}, 0);
+			ty += c->geom.height;
+		}
+		i++;
+	}
+}
+
+
 void
 maximizenotify(struct wl_listener *listener, void *data)
 {
-- 
2.46.0