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
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
|
From 3944cc81d0683700405cd106edf965293abbb87c Mon Sep 17 00:00:00 2001
From: dev-gm <codeberg@gavinm.us>
Date: Sat, 16 Nov 2024 23:27:19 -0500
Subject: [PATCH] Add tab support
---
config.def.h | 25 +++-
dwl.c | 392 +++++++++++++++++++++++++++++++++++++++++++++++----
2 files changed, 386 insertions(+), 31 deletions(-)
diff --git a/config.def.h b/config.def.h
index 5d1dc2b..52fcfee 100644
--- a/config.def.h
+++ b/config.def.h
@@ -10,6 +10,13 @@ static const unsigned int borderpx = 1; /* border pixel of windows */
static const int showbar = 1; /* 0 means no bar */
static const int topbar = 1; /* 0 means bottom bar */
static const char *fonts[] = {"monospace:size=10"};
+static const char *tbar_fonts[] = {"monospace:size=10"};
+static const int tbar_top = 0;
+static const int tbar_height = -1;
+static const int tbar_borderpx = 1;
+static const int tbar_padding = 10;
+static const float tbar_scale = -1; /* -1 means use monitor scale */
+static const int tbar_float_sel_sep = 0; /* should tbar be highlighted only on the currently selected window or on both the last selected floating window and the laste selected tiling window */
static const float rootcolor[] = COLOR(0x000000ff);
/* This conforms to the xdg-protocol. Set the alpha to zero to restore the old behavior */
static const float fullscreen_bg[] = {0.1f, 0.1f, 0.1f, 1.0f}; /* You can also use glsl colors */
@@ -20,6 +27,13 @@ static uint32_t colors[][3] = {
[SchemeUrg] = { 0, 0, 0x770000ff },
};
+static uint32_t tbar_colors[][3] = {
+ /* fg bg border */
+ [SchemeNorm] = { 0xbbbbbbff, 0x222222ff, 0x555555ff },
+ [SchemeSel] = { 0xeeeeeeff, 0x005577ff, 0x555555ff },
+ [SchemeUrg] = { 0xc7c7c7ff, 0x222222ff, 0x770000ff },
+};
+
/* tagging - TAGCOUNT must be no greater than 31 */
static char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
@@ -34,12 +48,15 @@ static const Rule rules[] = {
{ "firefox_EXAMPLE", NULL, 1 << 8, 0, -1 }, /* Start on ONLY tag "9" */
};
+static const unsigned int floating_tbar_type = TBarLabel;
+static const int floating_tbar_only_top = 0;
+
/* layout(s) */
static const Layout layouts[] = {
- /* symbol arrange function */
- { "[]=", tile },
- { "><>", NULL }, /* no layout function means floating behavior */
- { "[M]", monocle },
+ /* symbol tbar type tbar only on top arrange function */
+ { "[]=", TBarLabel, 0, tile },
+ { "><>", TBarLabel, 0, NULL }, /* no layout function means floating behavior */
+ { "[M]", TBarMultiple, 1, monocle },
};
/* monitors */
diff --git a/dwl.c b/dwl.c
index 1e199f3..e7754d3 100644
--- a/dwl.c
+++ b/dwl.c
@@ -13,6 +13,7 @@
#include <time.h>
#include <unistd.h>
#include <wayland-server-core.h>
+#include <wayland-util.h>
#include <wlr/backend.h>
#include <wlr/backend/libinput.h>
#include <wlr/render/allocator.h>
@@ -90,6 +91,7 @@ enum { CurNormal, CurPressed, CurMove, CurResize }; /* cursor */
enum { XDGShell, LayerShell, X11 }; /* client types */
enum { LyrBg, LyrBottom, LyrTile, LyrFloat, LyrTop, LyrFS, LyrOverlay, LyrBlock, NUM_LAYERS }; /* scene layers */
enum { ClkTagBar, ClkLtSymbol, ClkStatus, ClkTitle, ClkClient, ClkRoot }; /* clicks */
+enum { TBarNone, TBarLabel, TBarMultiple, TBarAlways }; /* tbar types */
#ifdef XWAYLAND
enum { NetWMWindowTypeDialog, NetWMWindowTypeSplash, NetWMWindowTypeToolbar,
NetWMWindowTypeUtility, NetLast }; /* EWMH atoms */
@@ -110,6 +112,14 @@ typedef struct {
const Arg arg;
} Button;
+typedef struct {
+ struct wlr_buffer base;
+ struct wl_listener release;
+ bool busy;
+ Img *image;
+ uint32_t data[];
+} Buffer;
+
typedef struct Monitor Monitor;
typedef struct {
/* Must keep these three elements in this order */
@@ -119,6 +129,11 @@ typedef struct {
struct wlr_scene_tree *scene;
struct wlr_scene_rect *border[4]; /* top, bottom, left, right */
struct wlr_scene_tree *scene_surface;
+ struct wlr_scene_buffer *tbar_buffer;
+ Drwl *drw;
+ Buffer *pool[2];
+ int tbar_height, tbar_real_height;
+ float tbar_scale;
struct wl_list link;
struct wl_list flink;
union {
@@ -146,7 +161,7 @@ typedef struct {
#endif
unsigned int bw;
uint32_t tags;
- int isfloating, isurgent, isfullscreen;
+ int isfloating, isurgent, isfullscreen, tbar_enabled, resize_tbar_enabled;
uint32_t resize; /* configure serial of a pending resize */
} Client;
@@ -190,17 +205,11 @@ typedef struct {
typedef struct {
const char *symbol;
+ unsigned int tbar_type; /* type of tbar */
+ int tbar_only_top;
void (*arrange)(Monitor *);
} Layout;
-typedef struct {
- struct wlr_buffer base;
- struct wl_listener release;
- bool busy;
- Img *image;
- uint32_t data[];
-} Buffer;
-
struct Monitor {
struct wl_list link;
struct wlr_output *wlr_output;
@@ -275,10 +284,11 @@ static void arrangelayer(Monitor *m, struct wl_list *list,
static void arrangelayers(Monitor *m);
static void axisnotify(struct wl_listener *listener, void *data);
static bool baracceptsinput(struct wlr_scene_buffer *buffer, double *sx, double *sy);
-static void bufdestroy(struct wlr_buffer *buffer);
-static bool bufdatabegin(struct wlr_buffer *buffer, uint32_t flags,
+static Buffer *bufclient(Client *c);
+static void bufdestroy(struct wlr_buffer *wlr_buffer);
+static bool bufdatabegin(struct wlr_buffer *wlr_buffer, uint32_t flags,
void **data, uint32_t *format, size_t *stride);
-static void bufdataend(struct wlr_buffer *buffer);
+static void bufdataend(struct wlr_buffer *wlr_buffer);
static Buffer *bufmon(Monitor *m);
static void bufrelease(struct wl_listener *listener, void *data);
static void buttonpress(struct wl_listener *listener, void *data);
@@ -316,12 +326,15 @@ 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 drawtbars(Monitor *m, int floating, int clients_changed);
+static void drawtbar(Client *c, unsigned int tbar_type, unsigned int len, Client *sel, Client *sel_in_layout);
static void drawbar(Monitor *m);
static void drawbars(void);
static void focusclient(Client *c, int lift);
static void focusmon(const Arg *arg);
static void focusstack(const Arg *arg);
static Client *focustop(Monitor *m);
+static Client *focustop_onlytiled(Monitor *m, int onlytiled);
static void fullscreennotify(struct wl_listener *listener, void *data);
static void gpureset(struct wl_listener *listener, void *data);
static void handlesig(int signo);
@@ -529,14 +542,16 @@ void
arrange(Monitor *m)
{
Client *c;
+ int enabled;
if (!m->wlr_output->enabled)
return;
wl_list_for_each(c, &clients, link) {
if (c->mon == m) {
- wlr_scene_node_set_enabled(&c->scene->node, VISIBLEON(c, m));
- client_set_suspended(c, !VISIBLEON(c, m));
+ enabled = VISIBLEON(c, m);
+ wlr_scene_node_set_enabled(&c->scene->node, enabled);
+ client_set_suspended(c, !enabled);
}
}
@@ -561,6 +576,7 @@ arrange(Monitor *m)
if (m->lt[m->sellt]->arrange)
m->lt[m->sellt]->arrange(m);
+
motionnotify(0, NULL, 0, 0, 0, 0);
checkidleinhibitor(NULL);
}
@@ -650,6 +666,36 @@ baracceptsinput(struct wlr_scene_buffer *buffer, double *sx, double *sy)
return true;
}
+Buffer *
+bufclient(Client *c)
+{
+ size_t i;
+ Buffer *buf = NULL;
+
+ for (i = 0; i < LENGTH(c->pool); i++) {
+ if (c->pool[i]) {
+ if (c->pool[i]->busy)
+ continue;
+ buf = c->pool[i];
+ break;
+ }
+
+ buf = ecalloc(1, sizeof(Buffer) + (int)(c->geom.width * c->tbar_scale * 4 * (c->tbar_height + 2*tbar_borderpx)));
+ buf->image = drwl_image_create(NULL, (int)(c->geom.width * c->tbar_scale), c->tbar_height + 2*tbar_borderpx, buf->data);
+ wlr_buffer_init(&buf->base, &buffer_impl, (int)(c->geom.width * c->tbar_scale), c->tbar_height + 2*tbar_borderpx);
+ c->pool[i] = buf;
+ break;
+ }
+ if (!buf)
+ return NULL;
+
+ buf->busy = true;
+ LISTEN(&buf->base.events.release, &buf->release, bufrelease);
+ wlr_buffer_lock(&buf->base);
+ drwl_setimage(c->drw, buf->image);
+ return buf;
+}
+
void
bufdestroy(struct wlr_buffer *wlr_buffer)
{
@@ -827,6 +873,21 @@ checkidleinhibitor(struct wlr_surface *exclude)
void
cleanup(void)
{
+ Client *c;
+ unsigned int i;
+
+ wl_list_for_each(c, &clients, link) {
+ if (!c->tbar_enabled)
+ continue;
+
+ for (i = 0; i < LENGTH(c->pool); i++)
+ wlr_buffer_drop(&c->pool[i]->base);
+
+ drwl_setimage(c->drw, NULL);
+ drwl_destroy(c->drw);
+
+ wlr_scene_node_destroy(&c->tbar_buffer->node);
+ }
#ifdef XWAYLAND
wlr_xwayland_destroy(xwayland);
xwayland = NULL;
@@ -1230,6 +1291,10 @@ createnotify(struct wl_listener *listener, void *data)
c = toplevel->base->data = ecalloc(1, sizeof(*c));
c->surface.xdg = toplevel->base;
c->bw = borderpx;
+ c->tbar_enabled = 0;
+ c->resize_tbar_enabled = 0;
+ c->tbar_height = 0;
+ c->tbar_buffer = NULL;
LISTEN(&toplevel->base->surface->events.commit, &c->commit, commitnotify);
LISTEN(&toplevel->base->surface->events.map, &c->map, mapnotify);
@@ -1579,6 +1644,166 @@ drawbars(void)
drawbar(m);
}
+void
+drawtbars(Monitor *m, int floating, int clients_changed)
+{
+ unsigned int tbar_type, tbar_only_top, len = 0;
+ int nodraw = 0, ismonocle;
+ Client *c, *sel = NULL, *sel_in_layout = NULL;
+
+ if (!m)
+ return;
+
+ tbar_type = floating ? floating_tbar_type : m->lt[m->sellt]->tbar_type;
+ tbar_only_top = floating ? floating_tbar_only_top : m->lt[m->sellt]->tbar_only_top;
+ ismonocle = m->lt[m->sellt]->arrange == monocle;
+
+ if (!clients_changed && !floating && ismonocle && (sel = focustop_onlytiled(m, 1))) {
+ wlr_scene_node_raise_to_top(&sel->scene->node);
+ if (sel->tbar_buffer)
+ wlr_scene_node_raise_to_top(&sel->tbar_buffer->node);
+ return;
+ }
+
+ if (tbar_type == TBarNone)
+ nodraw = 2;
+
+ if (!nodraw) {
+ wl_list_for_each(c, &fstack, flink) {
+ if (!VISIBLEON(c, m))
+ continue;
+ if (!sel && (!tbar_float_sel_sep || c->isfloating == floating))
+ sel = c;
+ if (!sel_in_layout && c->isfloating == floating)
+ sel_in_layout = c;
+ if (c->isfloating == floating && !c->isfullscreen)
+ len++;
+ }
+
+ if (len == 0)
+ return;
+ }
+
+ if (tbar_type == TBarMultiple && len <= 1)
+ nodraw = 2;
+
+ wl_list_for_each(c, &fstack, flink) {
+ if (!VISIBLEON(c, m) || c->isfloating != floating)
+ continue;
+ if (c->tbar_buffer && c->tbar_enabled && (nodraw == 2 || c->isfullscreen)) {
+ wlr_scene_node_set_enabled(&c->tbar_buffer->node, 0);
+ c->tbar_enabled = 0;
+ if (m->lt[m->sellt]->arrange != tile)
+ resize(c, c->geom, 0);
+ }
+ if (!nodraw && !c->isfullscreen) {
+ drawtbar(c, tbar_type, len, ismonocle ? c : sel_in_layout, sel_in_layout);
+ if (!ismonocle && tbar_only_top)
+ nodraw = 1;
+ }
+ if (c == sel_in_layout) {
+ wlr_scene_node_raise_to_top(&sel_in_layout->scene->node);
+ if (sel_in_layout->tbar_buffer)
+ wlr_scene_node_raise_to_top(&sel_in_layout->tbar_buffer->node);
+ }
+ }
+
+ if (m->lt[m->sellt]->arrange == tile)
+ m->lt[m->sellt]->arrange(m);
+}
+
+void
+drawtbar(Client *c, unsigned int tbar_type, unsigned int len, Client *sel, Client *sel_in_layout)
+{
+ Buffer *buf;
+ float width = c->geom.width * c->tbar_scale;
+ unsigned int i, scheme;
+ Client *l;
+ uint32_t tbar_border_colors[][3] = {
+ [SchemeNorm] = { [ColBg] = tbar_colors[SchemeNorm][2] },
+ [SchemeSel] = { [ColBg] = tbar_colors[SchemeSel][2] },
+ [SchemeUrg] = { [ColBg] = tbar_colors[SchemeUrg][2] }
+ };
+
+ if (!c->tbar_buffer)
+ c->tbar_buffer = wlr_scene_buffer_create(c->scene, NULL);
+
+ for (i = 0; i < LENGTH(c->pool); i++) {
+ if (c->pool[i]) {
+ wlr_buffer_drop(&c->pool[i]->base);
+ c->pool[i] = NULL;
+ }
+ }
+ drwl_setimage(c->drw, NULL);
+
+ if (!(buf = bufclient(c)))
+ return;
+
+ switch (tbar_type) {
+ case TBarLabel:
+ scheme = c->isurgent ? SchemeUrg : (c == sel ? SchemeSel : SchemeNorm);
+
+ if (tbar_borderpx) {
+ drwl_setscheme(c->drw, tbar_border_colors[scheme]);
+ drwl_rect(c->drw, 0, 0, (unsigned int)width, tbar_borderpx, 1, 1);
+ drwl_rect(c->drw, 0, c->tbar_height + tbar_borderpx, (unsigned int)width, tbar_borderpx, 1, 1);
+ drwl_rect(c->drw, 0, tbar_borderpx, tbar_borderpx, c->tbar_height, 1, 1);
+ drwl_rect(c->drw, (unsigned int)width - tbar_borderpx, tbar_borderpx, tbar_borderpx, c->tbar_height, 1, 1);
+ }
+
+ drwl_setscheme(c->drw, tbar_colors[scheme]);
+ drwl_text(c->drw, tbar_borderpx, tbar_borderpx,
+ (unsigned int)width - 2*tbar_borderpx, c->tbar_height,
+ tbar_padding, client_get_title(c), 0);
+
+ break;
+
+ case TBarMultiple:
+ case TBarAlways:
+ width /= len;
+ i = 0;
+
+ wl_list_for_each(l, &clients, link) {
+ if (!VISIBLEON(l, c->mon) || l->isfullscreen || l->isfloating != c->isfloating)
+ continue;
+
+ scheme = l->isurgent ? SchemeUrg : (l == sel ? SchemeSel : SchemeNorm);
+
+ if (tbar_borderpx) {
+ drwl_setscheme(c->drw, tbar_border_colors[scheme]);
+ drwl_rect(c->drw, (unsigned int)(width*i), 0, (unsigned int)width, tbar_borderpx, 1, 1);
+ drwl_rect(c->drw, (unsigned int)(width*i), c->tbar_height + tbar_borderpx,
+ (unsigned int)width, tbar_borderpx, 1, 1);
+ drwl_rect(c->drw, (unsigned int)(width*i), tbar_borderpx, tbar_borderpx, c->tbar_height, 1, 1);
+ if (i == len-1)
+ drwl_rect(c->drw, (unsigned int)(width*(i+1)) - tbar_borderpx, tbar_borderpx,
+ tbar_borderpx, c->tbar_height + 2*tbar_borderpx, 1, 1);
+ }
+
+ drwl_setscheme(c->drw, tbar_colors[scheme]);
+ drwl_text(c->drw, (unsigned int)(width*i) + tbar_borderpx, tbar_borderpx,
+ (unsigned int)width - (i == len-1 ? 2*tbar_borderpx : tbar_borderpx),
+ c->tbar_height, tbar_padding, client_get_title(l), 0);
+
+ i += 1;
+ }
+
+ break;
+ }
+
+ c->tbar_enabled = 1;
+ if (!c->resize_tbar_enabled)
+ resize(c, c->geom, 0);
+
+ wlr_scene_buffer_set_dest_size(c->tbar_buffer, c->geom.width,
+ c->tbar_real_height + 2*tbar_borderpx);
+ wlr_scene_node_set_position(&c->tbar_buffer->node, 0, tbar_top ? 0
+ : (c->geom.height - c->tbar_real_height - 2*tbar_borderpx));
+ wlr_scene_buffer_set_buffer(c->tbar_buffer, &buf->base);
+ wlr_scene_node_set_enabled(&c->tbar_buffer->node, 1);
+ wlr_buffer_unlock(&buf->base);
+}
+
void
focusclient(Client *c, int lift)
{
@@ -1635,6 +1860,12 @@ focusclient(Client *c, int lift)
client_activate_surface(old, 0);
}
}
+
+ if (c && c->mon)
+ drawtbars(c->mon, c->isfloating, 0);
+ if (c && old_c && old_c->mon && (old_c->mon != c->mon || old_c->isfloating != c->isfloating))
+ drawtbars(old_c->mon, old_c->isfloating, 0);
+
drawbars();
if (!c) {
@@ -1705,6 +1936,20 @@ focustop(Monitor *m)
return NULL;
}
+Client *
+focustop_onlytiled(Monitor *m, int onlytiled)
+{
+ Client *c;
+ wl_list_for_each(c, &fstack, flink) {
+ if (VISIBLEON(c, m)) {
+ if ((onlytiled == 1 && c->isfloating) || (onlytiled == 2 && !c->isfloating && m->lt[m->sellt]->arrange))
+ continue;
+ return c;
+ }
+ }
+ return NULL;
+}
+
void
fullscreennotify(struct wl_listener *listener, void *data)
{
@@ -1764,6 +2009,7 @@ incnmaster(const Arg *arg)
return;
selmon->nmaster = MAX(selmon->nmaster + arg->i, 0);
arrange(selmon);
+ drawtbars(selmon, 0, 0);
}
void
@@ -1932,6 +2178,7 @@ mapnotify(struct wl_listener *listener, void *data)
Client *w, *c = wl_container_of(listener, c, map);
Monitor *m;
int i;
+ char fontattrs[12];
/* Create scene tree for this client and its border */
c->scene = client_surface(c)->data = wlr_scene_tree_create(layers[LyrTile]);
@@ -1988,6 +2235,20 @@ unset_fullscreen:
if (w != c && w != p && w->isfullscreen && m == w->mon && (w->tags & c->tags))
setfullscreen(w, 0);
}
+
+ if (!(c->drw = drwl_create()))
+ die("failed to create drwl context");
+ c->tbar_scale = tbar_scale > 0 ? tbar_scale : m->wlr_output->scale;
+ snprintf(fontattrs, sizeof(fontattrs), "dpi=%.2f", 96. * c->tbar_scale);
+ if (!(drwl_font_create(c->drw, LENGTH(tbar_fonts), tbar_fonts, fontattrs)))
+ die("Could not load font");
+ if (!c->tbar_height) {
+ c->tbar_height = c->drw->font->height;
+ if (tbar_height > c->tbar_height)
+ c->tbar_height = tbar_height;
+ c->tbar_real_height = (int)((float)c->tbar_height / c->tbar_scale);
+ }
+ drawtbars(c->mon, c->isfloating, 1);
}
void
@@ -2012,18 +2273,28 @@ void
monocle(Monitor *m)
{
Client *c;
- int n = 0;
+ int n = 0, old_tbar_enabled;
wl_list_for_each(c, &clients, link) {
if (!VISIBLEON(c, m) || c->isfloating || c->isfullscreen)
continue;
- resize(c, m->w, 0);
+ if (!n)
+ wlr_scene_node_raise_to_top(&c->scene->node);
n++;
+ if (n > 1)
+ break;
+ }
+ wl_list_for_each(c, &fstack, flink) {
+ if (!VISIBLEON(c, m) || c->isfloating || c->isfullscreen)
+ continue;
+ old_tbar_enabled = c->tbar_enabled;
+ c->tbar_enabled = m->lt[m->sellt]->tbar_type != TBarNone
+ && m->lt[m->sellt]->tbar_type == TBarMultiple ? n > 1 : 1;
+ resize(c, m->w, 0);
+ c->tbar_enabled = old_tbar_enabled;
}
if (n)
snprintf(m->ltsymbol, LENGTH(m->ltsymbol), "[%d]", n);
- if ((c = focustop(m)))
- wlr_scene_node_raise_to_top(&c->scene->node);
}
void
@@ -2384,32 +2655,37 @@ resize(Client *c, struct wlr_box geo, int interact)
{
struct wlr_box *bbox;
struct wlr_box clip;
+ unsigned int th;
if (!c->mon || !client_surface(c)->mapped)
return;
bbox = interact ? &sgeom : &c->mon->w;
+ th = c->tbar_enabled ? (unsigned int)(c->tbar_real_height + 2*tbar_borderpx) : c->bw;
+
client_set_bounds(c, geo.width, geo.height);
c->geom = geo;
applybounds(c, bbox);
/* Update scene-graph, including borders */
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->scene_surface->node, c->bw, tbar_top ? th : c->bw);
+ wlr_scene_rect_set_size(c->border[0], c->geom.width, (c->tbar_enabled && tbar_top) ? 0 : c->bw);
+ wlr_scene_rect_set_size(c->border[1], c->geom.width, (c->tbar_enabled && !tbar_top) ? 0 : c->bw);
+ wlr_scene_rect_set_size(c->border[2], c->bw, c->geom.height - th - c->bw);
+ wlr_scene_rect_set_size(c->border[3], c->bw, c->geom.height - th - 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);
+ wlr_scene_node_set_position(&c->border[2]->node, 0, tbar_top ? th : c->bw);
+ wlr_scene_node_set_position(&c->border[3]->node, c->geom.width - c->bw, tbar_top ? th : c->bw);
/* this is a no-op if size hasn't changed */
c->resize = client_set_size(c, c->geom.width - 2 * c->bw,
- c->geom.height - 2 * c->bw);
+ c->geom.height - th - c->bw);
client_get_clip(c, &clip);
wlr_scene_subsurface_tree_set_clip(&c->scene_surface->node, &clip);
+
+ c->resize_tbar_enabled = c->tbar_enabled;
}
void
@@ -2505,6 +2781,8 @@ setfloating(Client *c, int floating)
: c->isfloating ? LyrFloat : LyrTile]);
arrange(c->mon);
drawbars();
+ drawtbars(c->mon, 0, 1);
+ drawtbars(c->mon, 1, 1);
}
void
@@ -2528,6 +2806,7 @@ setfullscreen(Client *c, int fullscreen)
}
arrange(c->mon);
drawbars();
+ drawtbars(c->mon, c->isfloating, 1);
}
void
@@ -2553,6 +2832,7 @@ setlayout(const Arg *arg)
strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, LENGTH(selmon->ltsymbol));
arrange(selmon);
drawbar(selmon);
+ drawtbars(selmon, 0, 1);
}
/* arg > 1.0 will set mfact absolutely */
@@ -2568,6 +2848,7 @@ setmfact(const Arg *arg)
return;
selmon->mfact = f;
arrange(selmon);
+ drawtbars(selmon, 0, 0);
}
void
@@ -2898,14 +3179,22 @@ tag(const Arg *arg)
focusclient(focustop(selmon), 1);
arrange(selmon);
drawbars();
+ drawtbars(selmon, 0, 1);
+ drawtbars(selmon, 1, 1);
}
void
tagmon(const Arg *arg)
{
Client *sel = focustop(selmon);
- if (sel)
+ Monitor *old_mon = selmon;
+ if (sel) {
setmon(sel, dirtomon(arg->i), 0);
+ if (selmon)
+ drawtbars(selmon, sel->isfloating, 1);
+ if (old_mon && selmon != old_mon)
+ drawtbars(old_mon, sel->isfloating, 1);
+ }
}
void
@@ -2979,6 +3268,8 @@ toggletag(const Arg *arg)
focusclient(focustop(selmon), 1);
arrange(selmon);
drawbars();
+ drawtbars(selmon, 0, 1);
+ drawtbars(selmon, 1, 1);
}
void
@@ -2992,6 +3283,8 @@ toggleview(const Arg *arg)
focusclient(focustop(selmon), 1);
arrange(selmon);
drawbars();
+ drawtbars(selmon, 0, 1);
+ drawtbars(selmon, 1, 1);
}
void
@@ -3022,6 +3315,9 @@ unmapnotify(struct wl_listener *listener, void *data)
{
/* Called when the surface is unmapped, and should no longer be shown. */
Client *c = wl_container_of(listener, c, unmap);
+ Monitor *m = c->mon;
+ unsigned int i;
+
if (c == grabc) {
cursor_mode = CurNormal;
grabc = NULL;
@@ -3038,6 +3334,20 @@ unmapnotify(struct wl_listener *listener, void *data)
wl_list_remove(&c->flink);
}
+ if (m && !c->isfloating && m->lt[m->sellt]->arrange == monocle)
+ drawtbars(m, c->isfloating, 1);
+
+ if (c->tbar_enabled) {
+ for (i = 0; i < LENGTH(c->pool); i++)
+ if (c->pool[i])
+ wlr_buffer_drop(&c->pool[i]->base);
+
+ drwl_setimage(c->drw, NULL);
+ drwl_destroy(c->drw);
+
+ wlr_scene_node_destroy(&c->tbar_buffer->node);
+ }
+
wlr_scene_node_destroy(&c->scene->node);
drawbars();
motionnotify(0, NULL, 0, 0, 0, 0);
@@ -3058,9 +3368,12 @@ updatemons(struct wl_listener *listener, void *data)
Client *c;
struct wlr_output_configuration_head_v1 *config_head;
Monitor *m;
+ char fontattrs[12];
/* First remove from the layout the disabled monitors */
wl_list_for_each(m, &mons, link) {
+ if (m->asleep)
+ continue;
if (m->wlr_output->enabled || m->asleep)
continue;
config_head = wlr_output_configuration_head_v1_create(config, m->wlr_output);
@@ -3124,6 +3437,23 @@ updatemons(struct wl_listener *listener, void *data)
if (!selmon) {
selmon = m;
}
+
+ wl_list_for_each(c, &clients, link) {
+ if (!VISIBLEON(c, m) || (c->drw && (tbar_scale > 0 || c->tbar_scale == m->wlr_output->scale)))
+ continue;
+ if (!c->drw && !(c->drw = drwl_create()))
+ die("failed to create drwl context");
+ drwl_font_destroy(c->drw->font);
+ c->tbar_scale = m->wlr_output->scale;
+ snprintf(fontattrs, sizeof(fontattrs), "dpi=%.2f", 96. * c->tbar_scale);
+ if (!(drwl_font_create(c->drw, LENGTH(tbar_fonts), tbar_fonts, fontattrs)))
+ die("Could not load font");
+ if (!c->tbar_height) {
+ c->tbar_height = c->drw->font->height;
+ if (tbar_height > c->tbar_height)
+ c->tbar_height = tbar_height;
+ }
+ }
}
if (selmon && selmon->wlr_output->enabled) {
@@ -3195,6 +3525,7 @@ updatetitle(struct wl_listener *listener, void *data)
Client *c = wl_container_of(listener, c, set_title);
if (c == focustop(c->mon))
drawbars();
+ drawtbars(c->mon, c->isfloating, 1);
}
void
@@ -3208,6 +3539,7 @@ urgent(struct wl_listener *listener, void *data)
c->isurgent = 1;
drawbars();
+ drawtbars(c->mon, 1, 1);
if (client_surface(c)->mapped)
client_set_border_color(c, (float[])COLOR(colors[SchemeUrg][ColBorder]));
@@ -3322,8 +3654,10 @@ zoom(const Arg *arg)
wl_list_remove(&sel->link);
wl_list_insert(&clients, &sel->link);
+ drawtbars(selmon, 0, 1);
focusclient(sel, 1);
arrange(selmon);
+ drawtbars(selmon, 0, 0);
}
#ifdef XWAYLAND
@@ -3375,6 +3709,10 @@ createnotifyx11(struct wl_listener *listener, void *data)
c->surface.xwayland = xsurface;
c->type = X11;
c->bw = client_is_unmanaged(c) ? 0 : borderpx;
+ c->tbar_enabled = 0;
+ c->resize_tbar_enabled = 0;
+ c->tbar_height = 0;
+ c->tbar_buffer = NULL;
/* Listen to the various events it can emit */
LISTEN(&xsurface->events.associate, &c->associate, associatex11);
--
2.47.0
|