forked from djpohly/dwl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uselessgaps.patch
137 lines (131 loc) · 5.17 KB
/
uselessgaps.patch
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
From 366a810531ce3425ea5eca4e32eba431dc26570e Mon Sep 17 00:00:00 2001
From: serenevoid <[email protected]>
Date: Sun, 16 Jul 2023 22:07:02 +0530
Subject: [PATCH] feat(gaps): Useless Gaps
- KISS (Keep it simple and stupid)
- Use common gap value instead of separate inner and outer gaps
- Set gap value in config.h and toggle gaps on or off
- minimal and efficient
---
config.def.h | 3 +++
dwl.c | 41 +++++++++++++++++++++++++++++++----------
2 files changed, 34 insertions(+), 10 deletions(-)
diff --git a/config.def.h b/config.def.h
index 447ba005..16ad12ce 100644
--- a/config.def.h
+++ b/config.def.h
@@ -1,7 +1,9 @@
/* appearance */
static const int sloppyfocus = 1; /* focus follows mouse */
static const int bypass_surface_visibility = 0; /* 1 means idle inhibitors will disable idle tracking even if it's surface isn't visible */
+static const int smartgaps = 0; /* 1 means no outer gap when there is only one window */
static const unsigned int borderpx = 1; /* border pixel of windows */
+static const unsigned int gappx = 10; /* horiz inner gap between windows */
static const float bordercolor[] = {0.5, 0.5, 0.5, 1.0};
static const float focuscolor[] = {1.0, 0.0, 0.0, 1.0};
/* To conform the xdg-protocol, set the alpha to zero to restore the old behavior */
@@ -119,6 +121,7 @@ static const Key keys[] = {
{ MODKEY, XKB_KEY_l, setmfact, {.f = +0.05} },
{ MODKEY, XKB_KEY_Return, zoom, {0} },
{ MODKEY, XKB_KEY_Tab, view, {0} },
++ { MODKEY, XKB_KEY_g, togglegaps, {0} },
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_C, killclient, {0} },
{ MODKEY, XKB_KEY_t, setlayout, {.v = &layouts[0]} },
{ MODKEY, XKB_KEY_f, setlayout, {.v = &layouts[1]} },
diff --git a/dwl.c b/dwl.c
index 93f66efe..aea07d68 100644
--- a/dwl.c
+++ b/dwl.c
@@ -185,6 +185,7 @@ struct Monitor {
struct wlr_box w; /* window area, layout-relative */
struct wl_list layers[4]; /* LayerSurface::link */
const Layout *lt[2];
+ int gappx; /* horizontal outer gaps */
unsigned int seltags;
unsigned int sellt;
uint32_t tagset[2];
@@ -304,6 +305,7 @@ static void tagmon(const Arg *arg);
static void tile(Monitor *m);
static void togglefloating(const Arg *arg);
static void togglefullscreen(const Arg *arg);
+static void togglegaps(const Arg *arg);
static void toggletag(const Arg *arg);
static void toggleview(const Arg *arg);
static void unlocksession(struct wl_listener *listener, void *data);
@@ -367,6 +369,8 @@ static struct wlr_box sgeom;
static struct wl_list mons;
static Monitor *selmon;
+static int enablegaps = 1; /* enables gaps, used by togglegaps */
+
/* global event handlers */
static struct wl_listener cursor_axis = {.notify = axisnotify};
static struct wl_listener cursor_button = {.notify = buttonpress};
@@ -913,6 +917,7 @@ createmon(struct wl_listener *listener, void *data)
/* Initialize monitor state using configured rules */
for (i = 0; i < LENGTH(m->layers); i++)
wl_list_init(&m->layers[i]);
+ m->gappx = gappx;
m->tagset[0] = m->tagset[1] = 1;
for (r = monrules; r < END(monrules); r++) {
if (!r->name || strstr(wlr_output->name, r->name)) {
@@ -2361,7 +2366,7 @@ tagmon(const Arg *arg)
void
tile(Monitor *m)
{
- unsigned int i, n = 0, mw, my, ty;
+ unsigned int i, n = 0, h, r, e = enablegaps, mw, my, ty;
Client *c;
wl_list_for_each(c, &clients, link)
@@ -2370,22 +2375,31 @@ tile(Monitor *m)
if (n == 0)
return;
+ if (smartgaps == n) {
+ e = 0; // outer gaps disabled
+ }
+
if (n > m->nmaster)
- mw = m->nmaster ? m->w.width * m->mfact : 0;
+ mw = m->nmaster ? (m->w.width + m->gappx*e) * m->mfact : 0;
else
- mw = m->w.width;
- i = my = ty = 0;
+ mw = m->w.width - 2*m->gappx*e + m->gappx*e;
+ i = 0;
+ my = ty = m->gappx*e;
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, .y = m->w.y + my, .width = mw,
- .height = (m->w.height - my) / (MIN(n, m->nmaster) - i)}, 0);
- my += c->geom.height;
+ r = MIN(n, m->nmaster) - i;
+ h = (m->w.height - my - m->gappx*e - m->gappx*e * (r - 1)) / r;
+ resize(c, (struct wlr_box){.x = m->w.x + m->gappx*e, .y = m->w.y + my,
+ .width = mw - m->gappx*e, .height = h}, 0);
+ my += c->geom.height + m->gappx*e;
} 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;
+ r = n - i;
+ h = (m->w.height - ty - m->gappx*e - m->gappx*e * (r - 1)) / r;
+ resize(c, (struct wlr_box){.x = m->w.x + mw + m->gappx*e, .y = m->w.y + ty,
+ .width = m->w.width - mw - 2*m->gappx*e, .height = h}, 0);
+ ty += c->geom.height + m->gappx*e;
}
i++;
}
@@ -2408,6 +2422,13 @@ togglefullscreen(const Arg *arg)
setfullscreen(sel, !sel->isfullscreen);
}
+void
+togglegaps(const Arg *arg)
+{
+ enablegaps = !enablegaps;
+ arrange(selmon);
+}
+
void
toggletag(const Arg *arg)
{