nixos-dotfiles

nixos-dotfiles

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