gaps.patch

on kitten's pastes | raw

expires: 28 Jun, 2024

 1From 7cb273a8486fc399f3982f1c98ac1fd523ce17d6 Mon Sep 17 00:00:00 2001
 2From: sewn <sewn@disroot.org>
 3Date: Sat, 30 Mar 2024 22:59:02 +0300
 4Subject: [PATCH 1/2] port gaps patch from dwm
 5
 6---
 7 config.def.h |  1 +
 8 dwl.c        | 25 +++++++++++++++----------
 9 2 files changed, 16 insertions(+), 10 deletions(-)
10
11diff --git a/config.def.h b/config.def.h
12index 9009517..dbe7c57 100644
13--- a/config.def.h
14+++ b/config.def.h
15@@ -7,6 +7,7 @@
16 static const int sloppyfocus               = 1;  /* focus follows mouse */
17 static const int bypass_surface_visibility = 0;  /* 1 means idle inhibitors will disable idle tracking even if it's surface isn't visible  */
18 static const unsigned int borderpx         = 1;  /* border pixel of windows */
19+static const unsigned int gappx            = 6;  /* gap pixel between windows */
20 static const float rootcolor[]             = COLOR(0x222222ff);
21 static const float bordercolor[]           = COLOR(0x444444ff);
22 static const float focuscolor[]            = COLOR(0x005577ff);
23diff --git a/dwl.c b/dwl.c
24index 5867b0c..44d843d 100644
25--- a/dwl.c
26+++ b/dwl.c
27@@ -2572,7 +2572,7 @@ tagmon(const Arg *arg)
28 void
29 tile(Monitor *m)
30 {
31-	unsigned int mw, my, ty;
32+	unsigned int h, r, mw, my, ty;
33 	int i, n = 0;
34 	Client *c;
35 
36@@ -2583,21 +2583,26 @@ tile(Monitor *m)
37 		return;
38 
39 	if (n > m->nmaster)
40-		mw = m->nmaster ? ROUND(m->w.width * m->mfact) : 0;
41+		mw = m->nmaster ? ROUND((m->w.width + gappx) * m->mfact) : 0;
42 	else
43-		mw = m->w.width;
44-	i = my = ty = 0;
45+		mw = m->w.width - gappx * 2 + gappx;
46+	i = 0;
47+	my = ty = gappx;
48 	wl_list_for_each(c, &clients, link) {
49 		if (!VISIBLEON(c, m) || c->isfloating || c->isfullscreen)
50 			continue;
51 		if (i < m->nmaster) {
52-			resize(c, (struct wlr_box){.x = m->w.x, .y = m->w.y + my, .width = mw,
53-				.height = (m->w.height - my) / (MIN(n, m->nmaster) - i)}, 0);
54-			my += c->geom.height;
55+			r = MIN(n, m->nmaster) - i;
56+			h = (m->w.height - my - gappx - gappx * (r - 1)) / r;
57+			resize(c, (struct wlr_box){.x = m->w.x + gappx, .y = m->w.y + my,
58+				.width = mw - gappx, .height = h}, 0);
59+			my += c->geom.height + gappx;
60 		} else {
61-			resize(c, (struct wlr_box){.x = m->w.x + mw, .y = m->w.y + ty,
62-				.width = m->w.width - mw, .height = (m->w.height - ty) / (n - i)}, 0);
63-			ty += c->geom.height;
64+			r = (n - i);
65+			h = (m->w.height - ty - gappx - gappx * (r - 1)) / r;
66+			resize(c, (struct wlr_box){.x = m->w.x + mw + gappx, .y = m->w.y + ty,
67+				.width = m->w.width - mw - gappx*2, .height = h}, 0);
68+			ty += c->geom.height + gappx;
69 		}
70 		i++;
71 	}
72-- 
732.44.0
74