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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
|
From 464259603cb3b7346670cc33fd9afa0f8fe0cd49 Mon Sep 17 00:00:00 2001
From: kerberoge <sjoerdenjh@gmail.com>
Date: Sun, 1 Jun 2025 17:03:09 +0200
Subject: [PATCH 1/1] Created tmux-borders patch for stock dwl
---
client.h | 6 ++
dwl.c | 298 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
2 files changed, 280 insertions(+), 24 deletions(-)
diff --git a/client.h b/client.h
index 42f225f..007ab7d 100644
--- a/client.h
+++ b/client.h
@@ -291,6 +291,12 @@ client_is_unmanaged(Client *c)
return 0;
}
+static inline int
+client_needs_borders(Client *c)
+{
+ return c->isfloating || !c->mon->lt[c->mon->sellt]->arrange;
+}
+
static inline void
client_notify_enter(struct wlr_surface *s, struct wlr_keyboard *kb)
{
diff --git a/dwl.c b/dwl.c
index a2711f6..c092c0e 100644
--- a/dwl.c
+++ b/dwl.c
@@ -191,6 +191,7 @@ struct Monitor {
struct wlr_output *wlr_output;
struct wlr_scene_output *scene_output;
struct wlr_scene_rect *fullscreen_bg; /* See createmon() for info */
+ struct wlr_scene_tree *borders, *fborders, *uborders;
struct wl_listener frame;
struct wl_listener destroy;
struct wl_listener request_state;
@@ -255,10 +256,12 @@ static void chvt(const Arg *arg);
static void checkidleinhibitor(struct wlr_surface *exclude);
static void cleanup(void);
static void cleanupmon(struct wl_listener *listener, void *data);
+static int clientindex(Monitor *m, Client *c);
static void closemon(Monitor *m);
static void commitlayersurfacenotify(struct wl_listener *listener, void *data);
static void commitnotify(struct wl_listener *listener, void *data);
static void commitpopup(struct wl_listener *listener, void *data);
+static int countclients(Monitor *m);
static void createdecoration(struct wl_listener *listener, void *data);
static void createidleinhibitor(struct wl_listener *listener, void *data);
static void createkeyboard(struct wlr_keyboard *keyboard);
@@ -273,6 +276,7 @@ static void createpopup(struct wl_listener *listener, void *data);
static void cursorconstrain(struct wlr_pointer_constraint_v1 *constraint);
static void cursorframe(struct wl_listener *listener, void *data);
static void cursorwarptohint(void);
+static void destroyborders(struct wlr_scene_tree *t);
static void destroydecoration(struct wl_listener *listener, void *data);
static void destroydragicon(struct wl_listener *listener, void *data);
static void destroyidleinhibitor(struct wl_listener *listener, void *data);
@@ -285,6 +289,13 @@ static void destroysessionlock(struct wl_listener *listener, void *data);
static void destroysessionmgr(struct wl_listener *listener, void *data);
static void destroykeyboardgroup(struct wl_listener *listener, void *data);
static Monitor *dirtomon(enum wlr_direction dir);
+static void drawclientborders(struct wlr_scene_tree *t, Client *c,
+ int cidx, int n, const float color[static 4]);
+static void drawrect(struct wlr_scene_tree *t,
+ int x, int y, int w, int h, const float color[static 4]);
+static void drawborders(Monitor *m);
+static void drawfborders(Monitor *m);
+static void drawuborders(Monitor *m);
static void focusclient(Client *c, int lift);
static void focusmon(const Arg *arg);
static void focusstack(const Arg *arg);
@@ -517,6 +528,11 @@ arrange(Monitor *m)
if (m->lt[m->sellt]->arrange)
m->lt[m->sellt]->arrange(m);
+
+ drawborders(m);
+ drawuborders(m);
+ drawfborders(m);
+
motionnotify(0, NULL, 0, 0, 0, 0);
checkidleinhibitor(NULL);
}
@@ -721,10 +737,34 @@ cleanupmon(struct wl_listener *listener, void *data)
wlr_scene_output_destroy(m->scene_output);
closemon(m);
+ wlr_scene_node_destroy(&m->borders->node);
+ wlr_scene_node_destroy(&m->fborders->node);
+ wlr_scene_node_destroy(&m->uborders->node);
wlr_scene_node_destroy(&m->fullscreen_bg->node);
free(m);
}
+int
+clientindex(Monitor *m, Client *c)
+{
+ unsigned int i = 0;
+ Client *ci;
+
+ if (!c || m->lt[m->sellt]->arrange != tile)
+ return -1;
+
+ wl_list_for_each(ci, &clients, link) {
+ if (VISIBLEON(ci, m) && !ci->isfloating && !ci->isfullscreen) {
+ if (ci == c)
+ return i;
+ else
+ i++;
+ }
+ }
+
+ return -1;
+}
+
void
closemon(Monitor *m)
{
@@ -743,6 +783,10 @@ closemon(Monitor *m)
selmon = NULL;
}
+ destroyborders(m->borders);
+ destroyborders(m->fborders);
+ destroyborders(m->uborders);
+
wl_list_for_each(c, &clients, link) {
if (c->isfloating && c->geom.x > m->m.width)
resize(c, (struct wlr_box){.x = c->geom.x - m->w.width, .y = c->geom.y,
@@ -849,6 +893,19 @@ commitpopup(struct wl_listener *listener, void *data)
wl_list_remove(&listener->link);
}
+int
+countclients(Monitor *m)
+{
+ unsigned int n = 0;
+ Client *c;
+
+ wl_list_for_each(c, &clients, link)
+ if (VISIBLEON(c, m) && !c->isfloating && !c->isfullscreen)
+ n++;
+
+ return n;
+}
+
void
createdecoration(struct wl_listener *listener, void *data)
{
@@ -985,6 +1042,9 @@ createmon(struct wl_listener *listener, void *data)
m = wlr_output->data = ecalloc(1, sizeof(*m));
m->wlr_output = wlr_output;
+ m->borders = wlr_scene_tree_create(layers[LyrTile]);
+ m->fborders = wlr_scene_tree_create(layers[LyrTile]);
+ m->uborders = wlr_scene_tree_create(layers[LyrTile]);
for (i = 0; i < LENGTH(m->layers); i++)
wl_list_init(&m->layers[i]);
@@ -1171,6 +1231,15 @@ cursorwarptohint(void)
}
}
+void
+destroyborders(struct wlr_scene_tree *t)
+{
+ struct wlr_scene_node *node, *tmp;
+
+ wl_list_for_each_safe(node, tmp, &t->children, link)
+ wlr_scene_node_destroy(node);
+}
+
void
destroydecoration(struct wl_listener *listener, void *data)
{
@@ -1336,6 +1405,154 @@ dirtomon(enum wlr_direction dir)
return selmon;
}
+void
+drawclientborders(struct wlr_scene_tree *t, Client *c, int cidx, int n, const float color[static 4])
+{
+ Monitor *m;
+ int mw, x, y, w, h;
+
+ m = c->mon;
+ mw = (int)round(m->w.width * m->mfact - 0.5 * borderpx);
+
+ if (m->nmaster == 1 && n == 2) {
+ /* Half vertical center line */
+ y = m->w.y + (cidx == 1 ? m->w.height / 2 : 0);
+ h = (int)round(0.5 * m->w.height);
+ drawrect(t, m->w.x + mw, y, borderpx, h, color);
+ } else if (m->nmaster != 1 && n == 2) {
+ /* Half horizontal center line */
+ x = m->w.x + (cidx == 1 ? m->w.width / 2 : 0);
+ y = m->w.y + (int)round(0.5 * m->w.height - 0.5 * borderpx);
+ w = (int)round(0.5 * m->w.width);
+ drawrect(t, x, y, w, borderpx, color);
+ } else {
+ if (m->nmaster && n > m->nmaster)
+ /* Vertical line next to client */
+ drawrect(t, m->w.x + mw, c->geom.y, borderpx, c->geom.height, color);
+
+ if (n > m->nmaster && cidx < m->nmaster) {
+ /* Left half */
+ x = m->w.x;
+ w = mw + borderpx;
+ } else if (m->nmaster && cidx >= m->nmaster) {
+ /* Right half */
+ x = m->w.x + mw;
+ w = m->w.width - mw;
+ } else {
+ /* Full width */
+ x = m->w.x;
+ w = m->w.width;
+ }
+
+ if ((cidx > 0 && cidx < m->nmaster) || (cidx > m->nmaster))
+ /* Line above client */
+ drawrect(t, x, c->geom.y - borderpx, w, borderpx, color);
+
+ if ((cidx < m->nmaster - 1) || (cidx >= m->nmaster && cidx < n - 1))
+ /* Line below client */
+ drawrect(t, x, c->geom.y + c->geom.height, w, borderpx, color);
+ }
+}
+
+void
+drawrect(struct wlr_scene_tree *t, int x, int y, int w, int h, const float color[static 4])
+{
+ struct wlr_scene_rect *r;
+
+ r = wlr_scene_rect_create(t, w, h, color);
+ wlr_scene_node_set_position(&r->node, x, y);
+}
+
+void
+drawborders(Monitor *m)
+{
+ int n, i;
+ int mw, tw, my = 0, ty = 0;
+
+ if (!m)
+ return;
+
+ destroyborders(m->borders);
+ n = countclients(m);
+
+ if (n <= 1 || m->lt[m->sellt]->arrange != tile)
+ return;
+
+ if (m->nmaster > 0 && n > m->nmaster)
+ mw = (int)round(m->w.width * m->mfact - 0.5 * borderpx);
+ else if (n <= m->nmaster)
+ mw = m->w.width;
+ else
+ mw = 0;
+
+ if (mw > 0)
+ tw = m->w.width - mw - borderpx;
+ else
+ tw = m->w.width;
+
+ /* Vertical center line */
+ if (mw > 0 && mw < m->w.width)
+ drawrect(m->borders, m->w.x + mw, m->w.y, borderpx, m->w.height, bordercolor);
+
+ /* Lines between master clients */
+ for (i = 0; i < MIN(n, m->nmaster) - 1; i++) {
+ my += (m->w.height - my - borderpx * (MIN(n, m->nmaster) - i - 1))
+ / (MIN(n, m->nmaster) - i);
+ drawrect(m->borders, m->w.x, m->w.y + my, mw, borderpx, bordercolor);
+ my += borderpx;
+ }
+
+ /* Lines between clients on the stack */
+ for (i = m->nmaster; i < n - 1; i++) {
+ ty += (m->w.height - ty - borderpx * (n - i - 1)) / (n - i);
+ drawrect(m->borders, m->m.x + (mw ? mw + borderpx : 0), m->w.y + ty,
+ tw, borderpx, bordercolor);
+ ty += borderpx;
+ }
+}
+
+void
+drawfborders(Monitor *m)
+{
+ Client *fc;
+ int n, cidx;
+
+ if (!m)
+ return;
+
+ destroyborders(m->fborders);
+ n = countclients(m);
+ fc = focustop(m);
+ cidx = clientindex(m, fc);
+
+ if (n <= 1 || cidx == -1)
+ return;
+
+ drawclientborders(m->fborders, fc, cidx, n, focuscolor);
+}
+
+void
+drawuborders(Monitor *m)
+{
+ Client *c;
+ int n, cidx;
+
+ if (!m)
+ return;
+
+ destroyborders(m->uborders);
+ n = countclients(m);
+
+ if (n <= 1)
+ return;
+
+ wl_list_for_each(c, &clients, link) {
+ cidx = clientindex(m, c);
+ if (cidx != -1 && c->isurgent)
+ drawclientborders(m->uborders, c, cidx, n, urgentcolor);
+ }
+}
+
void
focusclient(Client *c, int lift)
{
@@ -1366,12 +1583,15 @@ focusclient(Client *c, int lift)
wl_list_insert(&fstack, &c->flink);
selmon = c->mon;
c->isurgent = 0;
+ drawuborders(c->mon);
client_restack_surface(c);
/* Don't change border color if there is an exclusive focus or we are
* handling a drag operation */
- if (!exclusive_focus && !seat->drag)
+ if (!exclusive_focus && !seat->drag) {
client_set_border_color(c, focuscolor);
+ drawfborders(c->mon);
+ }
}
/* Deactivate old client if focus is changing */
@@ -1389,7 +1609,8 @@ focusclient(Client *c, int lift)
* and probably other clients */
} else if (old_c && !client_is_unmanaged(old_c) && (!c || !client_wants_focus(c))) {
client_set_border_color(old_c, bordercolor);
-
+ if (old_c->mon && (!c || c->mon != old_c->mon))
+ destroyborders(old_c->mon->fborders);
client_activate_surface(old, 0);
}
}
@@ -2193,15 +2414,20 @@ resize(Client *c, struct wlr_box geo, int interact)
applybounds(c, bbox);
/* Update scene-graph, including borders */
+ c->bw = client_needs_borders(c) ? borderpx : 0;
wlr_scene_node_set_position(&c->scene->node, c->geom.x, c->geom.y);
wlr_scene_node_set_position(&c->scene_surface->node, c->bw, c->bw);
- wlr_scene_rect_set_size(c->border[0], c->geom.width, c->bw);
- wlr_scene_rect_set_size(c->border[1], c->geom.width, c->bw);
- wlr_scene_rect_set_size(c->border[2], c->bw, c->geom.height - 2 * c->bw);
- wlr_scene_rect_set_size(c->border[3], c->bw, c->geom.height - 2 * c->bw);
- wlr_scene_node_set_position(&c->border[1]->node, 0, c->geom.height - c->bw);
- wlr_scene_node_set_position(&c->border[2]->node, 0, c->bw);
- wlr_scene_node_set_position(&c->border[3]->node, c->geom.width - c->bw, c->bw);
+ for (int i = 0; i < 4; i++)
+ wlr_scene_node_set_enabled(&c->border[i]->node, c->bw);
+ if (c->bw) {
+ wlr_scene_rect_set_size(c->border[0], c->geom.width, c->bw);
+ wlr_scene_rect_set_size(c->border[1], c->geom.width, c->bw);
+ wlr_scene_rect_set_size(c->border[2], c->bw, c->geom.height - 2 * c->bw);
+ wlr_scene_rect_set_size(c->border[3], c->bw, c->geom.height - 2 * c->bw);
+ wlr_scene_node_set_position(&c->border[1]->node, 0, c->geom.height - c->bw);
+ wlr_scene_node_set_position(&c->border[2]->node, 0, c->bw);
+ wlr_scene_node_set_position(&c->border[3]->node, c->geom.width - c->bw, c->bw);
+ }
/* this is a no-op if size hasn't changed */
c->resize = client_set_size(c, c->geom.width - 2 * c->bw,
@@ -2359,8 +2585,13 @@ setlayout(const Arg *arg)
return;
if (!arg || !arg->v || arg->v != selmon->lt[selmon->sellt])
selmon->sellt ^= 1;
+ else
+ return;
if (arg && arg->v)
selmon->lt[selmon->sellt] = (Layout *)arg->v;
+ if (selmon->lt[selmon->sellt ^ 1]->arrange == tile && !selmon->lt[selmon->sellt]->arrange)
+ /* Tiled -> floating, remove monitor borders and enable client borders */
+ tile(selmon);
strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, LENGTH(selmon->ltsymbol));
arrange(selmon);
printstatus();
@@ -2692,31 +2923,46 @@ void
tile(Monitor *m)
{
unsigned int mw, my, ty;
- int i, n = 0;
+ int i, n;
Client *c;
+ struct wlr_box wb;
+ int borders = m->lt[m->sellt]->arrange == tile ? 1 : 0;
- wl_list_for_each(c, &clients, link)
- if (VISIBLEON(c, m) && !c->isfloating && !c->isfullscreen)
- n++;
+ n = countclients(m);
if (n == 0)
return;
- if (n > m->nmaster)
- mw = m->nmaster ? (int)roundf(m->w.width * m->mfact) : 0;
- else
+ if (n > m->nmaster && m->nmaster) {
+ mw = (int)round(m->w.width * m->mfact - (borders ? 0.5 * borderpx : 0));
+ } else if (m->nmaster)
mw = m->w.width;
+ else
+ mw = 0;
i = my = ty = 0;
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;
+ wb.x = m->w.x;
+ wb.y = m->w.y + my;
+ wb.width = mw;
+ if (borders)
+ wb.height = (m->w.height - my - borderpx * (MIN(n, m->nmaster) - i - 1))
+ / (MIN(n, m->nmaster) - i);
+ else
+ wb.height = (m->w.height - my) / (MIN(n, m->nmaster) - i);
+ resize(c, wb, 0);
+ my += wb.height + (borders ? borderpx : 0);
} 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;
+ wb.x = m->w.x + mw + (mw && borders ? borderpx : 0);
+ wb.y = m->w.y + ty;
+ wb.width = m->w.width - mw - (mw && borders ? borderpx : 0);
+ if (borders)
+ wb.height = (m->w.height - ty - borderpx * (n - i - 1)) / (n - i);
+ else
+ wb.height = (m->w.height - ty) / (n - i);
+ resize(c, wb, 0);
+ ty += wb.height + (borders ? borderpx : 0);
}
i++;
}
@@ -2941,8 +3187,10 @@ urgent(struct wl_listener *listener, void *data)
c->isurgent = 1;
printstatus();
- if (client_surface(c)->mapped)
+ if (client_surface(c)->mapped) {
client_set_border_color(c, urgentcolor);
+ drawuborders(c->mon);
+ }
}
void
@@ -3147,8 +3395,10 @@ sethints(struct wl_listener *listener, void *data)
c->isurgent = xcb_icccm_wm_hints_get_urgency(c->surface.xwayland->hints);
printstatus();
- if (c->isurgent && surface && surface->mapped)
+ if (c->isurgent && surface && surface->mapped) {
client_set_border_color(c, urgentcolor);
+ drawuborders(c->mon);
+ }
}
void
--
2.49.0
|