summaryrefslogtreecommitdiffstats
path: root/dwl-patches/patches/snail-gaps/snail-gaps.patch
blob: 51d2812921ca77d2186edcbf4f8882de4a0e5a5d (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
From 804e69ca4bf586bcec46e018630f94c1c4e0b7e7 Mon Sep 17 00:00:00 2001
From: JoaoCostaIFG <joaocosta.work@posteo.net>
Date: Thu, 8 Aug 2024 00:05:27 +0100
Subject: [PATCH 2/2] Add gaps support to snail layout

---
 dwl.c | 105 +++++++++++++++++++++++++++++++++-------------------------
 1 file changed, 59 insertions(+), 46 deletions(-)

diff --git a/dwl.c b/dwl.c
index 46bdca1..a158dd6 100644
--- a/dwl.c
+++ b/dwl.c
@@ -2659,8 +2659,8 @@ void
 snail(Monitor *m)
 {
 	int i = 0, n = 0;
-	unsigned int mw = m->w.width;
-	Client *c, *prev;
+	unsigned int mw = m->w.width, e = m->gaps, w = 0, h = 0, egappx = 0;
+	Client *c, *prev = NULL;
 	enum wlr_direction dir = WLR_DIRECTION_RIGHT;
 
 	wl_list_for_each(c, &clients, link)
@@ -2668,9 +2668,12 @@ snail(Monitor *m)
 			n++;
 	if (n == 0)
 		return;
+  if (smartgaps == n)
+		e = 0;
+	egappx = e * gappx;
 
 	if (n > m->nmaster)
-		mw = m->nmaster ? ROUND(m->w.width * m->mfact) : 0;
+		mw = m->nmaster ? (unsigned int)round((m->w.width + egappx) * m->mfact) : 0;
 
 	wl_list_for_each(c, &clients, link) {
 		if (!VISIBLEON(c, m) || c->isfloating || c->isfullscreen)
@@ -2681,8 +2684,8 @@ snail(Monitor *m)
 		 * master area with this window
 		 */
 		if (mw > 0 && i == 0) {
-			c->geom = (struct wlr_box){.x = m->w.x, .y = m->w.y,
-				.width = mw, .height = m->w.height};
+			c->geom = (struct wlr_box){.x = m->w.x + egappx, .y = m->w.y + egappx,
+				.width = mw - 2*egappx, .height = m->w.height - 2*egappx};
 			/*
 			 * If the first window in the master area is wide, split it
 			 * horizontally and put next one on its right; otherwise, split it
@@ -2694,55 +2697,65 @@ snail(Monitor *m)
 		 * m->nmaster-th window
 		 */
 		} else if (i == m->nmaster) {
-			c->geom = (struct wlr_box){.x = m->w.x + mw, .y = m->w.y,
-				.width = m->w.width - mw, .height = m->w.height};
+			c->geom = (struct wlr_box){.x = m->w.x + mw + egappx, .y = m->w.y + egappx,
+				.width = m->w.width - mw - 2*egappx, .height = m->w.height - 2*egappx};
 			/*
 			 * If the first window in the stack is wide, split it horizontally
 			 * and put next one on its right; otherwise, split it vertically and
 			 * put the next one below it
 			 */
 			dir = c->geom.width > m->w.height ? WLR_DIRECTION_RIGHT : WLR_DIRECTION_DOWN;
-		/*
-		 * Split the previous horizontally and put the current window on the right
-		 */
-		} else if (dir == WLR_DIRECTION_RIGHT) {
-			c->geom = (struct wlr_box){.x = prev->geom.x + prev->geom.width / 2, .y = prev->geom.y,
-				.width = prev->geom.width / 2, .height = prev->geom.height};
-			prev->geom = (struct wlr_box){.x = prev->geom.x, .y = prev->geom.y,
-				.width = prev->geom.width / 2, .height = prev->geom.height};
+		} else if (prev) {
 			/*
-			 * If it's a stack window or the first narrow window in the master
-			 * area, put the next one below it
+			 * Split the previous horizontally and put the current window on the right
 			 */
-			if (i >= m->nmaster || c->geom.width < m->w.height)
-				dir = WLR_DIRECTION_DOWN;
-		/*
-		 * Split the previous vertically and put the current window below it
-		 */
-		} else if (dir == WLR_DIRECTION_DOWN) {
-			c->geom = (struct wlr_box){.x = prev->geom.x, .y = prev->geom.y + prev->geom.height / 2,
-				.width = prev->geom.width, .height = prev->geom.height / 2};
-			prev->geom = (struct wlr_box){.x = prev->geom.x, .y = prev->geom.y,
-				.width = prev->geom.width, .height = prev->geom.height / 2};
-			dir = WLR_DIRECTION_LEFT;
-		/*
-		 * Split the previous horizontally and put the current window on the left
-		 */
-		} else if (dir == WLR_DIRECTION_LEFT) {
-			c->geom = (struct wlr_box){.x = prev->geom.x, .y = prev->geom.y,
-				.width = prev->geom.width / 2, .height = prev->geom.height};
-			prev->geom = (struct wlr_box){.x = prev->geom.x + prev->geom.width / 2, .y = prev->geom.y,
-				.width = prev->geom.width / 2, .height = prev->geom.height};
-			dir = WLR_DIRECTION_UP;
-		/*
-		 * Split the previous vertically and put the current window above it
-		 */
-		} else {
-			c->geom = (struct wlr_box){.x = prev->geom.x, .y = prev->geom.y,
-				.width = prev->geom.width, .height = prev->geom.height / 2};
-			prev->geom = (struct wlr_box){.x = prev->geom.x, .y = prev->geom.y + prev->geom.height / 2,
-				.width = prev->geom.width, .height = prev->geom.height / 2};
-			dir = WLR_DIRECTION_RIGHT;
+			if (dir == WLR_DIRECTION_RIGHT) {
+				w = prev->geom.width / 2 - egappx;
+				h = prev->geom.height;
+				c->geom = (struct wlr_box){.x = prev->geom.x + prev->geom.width / 2 + egappx, .y = prev->geom.y,
+					.width = w, .height = h};
+				prev->geom = (struct wlr_box){.x = prev->geom.x, .y = prev->geom.y,
+					.width = w, .height = h};
+				/*
+				 * If it's a stack window or the first narrow window in the master
+				 * area, put the next one below it
+				 */
+				if (i >= m->nmaster || c->geom.width < m->w.height)
+					dir = WLR_DIRECTION_DOWN;
+			/*
+			 * Split the previous vertically and put the current window below it
+			 */
+			} else if (dir == WLR_DIRECTION_DOWN) {
+				w = prev->geom.width;
+				h = prev->geom.height / 2 - egappx;
+				c->geom = (struct wlr_box){.x = prev->geom.x, .y = prev->geom.y + prev->geom.height / 2 + egappx,
+					.width = w, .height = h};
+				prev->geom = (struct wlr_box){.x = prev->geom.x, .y = prev->geom.y,
+					.width = w, .height = h};
+				dir = WLR_DIRECTION_LEFT;
+			/*
+			 * Split the previous horizontally and put the current window on the left
+			 */
+			} else if (dir == WLR_DIRECTION_LEFT) {
+				w = prev->geom.width / 2 - egappx;
+				h = prev->geom.height;
+				c->geom = (struct wlr_box){.x = prev->geom.x, .y = prev->geom.y,
+					.width = w, .height = h};
+				prev->geom = (struct wlr_box){.x = prev->geom.x + prev->geom.width / 2 + egappx, .y = prev->geom.y,
+					.width = w, .height = h};
+				dir = WLR_DIRECTION_UP;
+			/*
+			 * Split the previous vertically and put the current window above it
+			 */
+			} else {
+				w = prev->geom.width;
+				h = prev->geom.height / 2 - egappx;
+				c->geom = (struct wlr_box){.x = prev->geom.x, .y = prev->geom.y,
+					.width = w, .height = h};
+				prev->geom = (struct wlr_box){.x = prev->geom.x, .y = prev->geom.y + prev->geom.height / 2 + egappx,
+					.width = w, .height = h};
+				dir = WLR_DIRECTION_RIGHT;
+			}
 		}
 		i++;
 		prev = c;
-- 
2.46.0