greenhouse

kore

my public infrastructure monorepo

git clone [email protected]:kore.git

kore / overlays / dwl / gaps.patch125 lines · 4510B · raw

1From 4ebd22f1a34ee89955acc6bdf930f6676bb6b35d Mon Sep 17 00:00:00 2001
2From: peesock <[email protected]>
3Date: Mon, 24 Jun 2024 20:06:42 -0700
4Subject: [PATCH] gaps!
5
6---
7 config.def.h |  4 ++++
8 dwl.c        | 34 ++++++++++++++++++++++++++--------
9 2 files changed, 30 insertions(+), 8 deletions(-)
10
11diff --git a/config.def.h b/config.def.h
12index 1fc6203..b528ca3 100644
13--- a/config.def.h
14+++ b/config.def.h
15@@ -6,6 +6,9 @@
16 /* appearance */
17 static const int sloppyfocus               = 1;  /* focus follows mouse */
18 static const int bypass_surface_visibility = 0;  /* 1 means idle inhibitors will disable idle tracking even if it's surface isn't visible  */
19+static const int smartgaps                 = 0;  /* 1 means no outer gap when there is only one window */
20+static int gaps                            = 1;  /* 1 means gaps between windows are added */
21+static const unsigned int gappx            = 10; /* gap pixel between windows */
22 static const unsigned int borderpx         = 1;  /* border pixel of windows */
23 static const unsigned int snap             = 32; /* snap pixel */
24 static const int showbar                   = 1; /* 0 means no bar */
25@@ -139,6 +142,7 @@ static const Key keys[] = {
26 	{ MODKEY,                    XKB_KEY_Return,      zoom,             {0} },
27 	{ MODKEY,                    XKB_KEY_Tab,         view,             {0} },
28 	{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_c,           killclient,       {0} },
29+	{ MODKEY,                    XKB_KEY_g,           togglegaps,       {0} },
30 	{ MODKEY,                    XKB_KEY_t,           setlayout,        {.v = &layouts[0]} },
31 	{ MODKEY,                    XKB_KEY_f,           setlayout,        {.v = &layouts[1]} },
32 	{ MODKEY,                    XKB_KEY_m,           setlayout,        {.v = &layouts[2]} },
33diff --git a/dwl.c b/dwl.c
34index 751338b..a348dec 100644
35--- a/dwl.c
36+++ b/dwl.c
37@@ -239,6 +239,7 @@ struct Monitor {
38 	struct wlr_box w; /* window area, layout-relative */
39 	struct wl_list layers[4]; /* LayerSurface.link */
40 	const Layout *lt[2];
41+	int gaps;
42 	unsigned int seltags;
43 	unsigned int sellt;
44 	uint32_t tagset[2];
45@@ -392,6 +393,7 @@ static void tile(Monitor *m);
46 static void togglebar(const Arg *arg);
47 static void togglefloating(const Arg *arg);
48 static void togglefullscreen(const Arg *arg);
49+static void togglegaps(const Arg *arg);
50 static void toggletag(const Arg *arg);
51 static void toggleview(const Arg *arg);
52 static void unlocksession(struct wl_listener *listener, void *data);
53@@ -1316,6 +1318,8 @@ createmon(struct wl_listener *listener, void *data)
54 
55 	wlr_output_state_init(&state);
56 	/* Initialize monitor state using configured rules */
57+	m->gaps = gaps;
58+
59 	m->tagset[0] = m->tagset[1] = 1;
60 	for (r = monrules; r < END(monrules); r++) {
61 		if (!r->name || strstr(wlr_output->name, r->name)) {
62@@ -3110,7 +3114,7 @@ tagmon(const Arg *arg)
63 void
64 tile(Monitor *m)
65 {
66-	unsigned int mw, my, ty;
67+	unsigned int h, r, e = m->gaps, mw, my, ty;
68 	int i, n = 0;
69 	Client *c;
70 
71@@ -3119,23 +3123,30 @@ tile(Monitor *m)
72 			n++;
73 	if (n == 0)
74 		return;
75+	if (smartgaps == n)
76+		e = 0;
77 
78 	if (n > m->nmaster)
79-		mw = m->nmaster ? (int)roundf(m->w.width * m->mfact) : 0;
80+		mw = m->nmaster ? (int)roundf((m->w.width + gappx*e) * m->mfact) : 0;
81 	else
82 		mw = m->w.width;
83-	i = my = ty = 0;
84+	i = 0;
85+	my = ty = gappx*e;
86 	wl_list_for_each(c, &clients, link) {
87 		if (!VISIBLEON(c, m) || c->isfloating || c->isfullscreen)
88 			continue;
89 		if (i < m->nmaster) {
90-			resize(c, (struct wlr_box){.x = m->w.x, .y = m->w.y + my, .width = mw,
91-				.height = (m->w.height - my) / (MIN(n, m->nmaster) - i)}, 0);
92-			my += c->geom.height;
93+			r = MIN(n, m->nmaster) - i;
94+			h = (m->w.height - my - gappx*e - gappx*e * (r - 1)) / r;
95+			resize(c, (struct wlr_box){.x = m->w.x + gappx*e, .y = m->w.y + my,
96+				.width = mw - 2*gappx*e, .height = h}, 0);
97+			my += c->geom.height + gappx*e;
98 		} else {
99+			r = n - i;
100+			h = (m->w.height - ty - gappx*e - gappx*e * (r - 1)) / r;
101 			resize(c, (struct wlr_box){.x = m->w.x + mw, .y = m->w.y + ty,
102-				.width = m->w.width - mw, .height = (m->w.height - ty) / (n - i)}, 0);
103-			ty += c->geom.height;
104+				.width = m->w.width - mw - gappx*e, .height = h}, 0);
105+			ty += c->geom.height + gappx*e;
106 		}
107 		i++;
108 	}
109@@ -3167,6 +3178,13 @@ togglefullscreen(const Arg *arg)
110 		setfullscreen(sel, !sel->isfullscreen);
111 }
112 
113+void
114+togglegaps(const Arg *arg)
115+{
116+	selmon->gaps = !selmon->gaps;
117+	arrange(selmon);
118+}
119+
120 void
121 toggletag(const Arg *arg)
122 {
123-- 
1242.55.0
125