From 315474624a29f668088405a5bfec7d48e97a4c31 Mon Sep 17 00:00:00 2001 From: sewn Date: Sat, 23 Mar 2024 14:09:57 +0300 Subject: [PATCH] add border to bar --- config.def.h | 1 + dwl.c | 33 +++++++++++++++++++-------------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/config.def.h b/config.def.h index bd008c9..a51ebe7 100644 --- a/config.def.h +++ b/config.def.h @@ -19,6 +19,7 @@ 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 *fontattrs = "dpi=96"; +static pixman_color_t borderbar = { 0x5555, 0x7777, 0x0000, 0xffff }; static pixman_color_t normbarfg = { 0xbbbb, 0xbbbb, 0xbbbb, 0xffff }; static pixman_color_t normbarbg = { 0x2222, 0x2222, 0x2222, 0xffff }; static pixman_color_t selbarfg = { 0xeeee, 0xeeee, 0xeeee, 0xffff }; diff --git a/dwl.c b/dwl.c index 8341134..8870ce0 100644 --- a/dwl.c +++ b/dwl.c @@ -1428,7 +1428,8 @@ draw_rect(pixman_image_t *pix, void drawbar(Monitor *mon) { - int x, w, tw = 0; + int x, y = borderpx, w, tw = 0; + int mh, mw; int sel; int boxs = font->height / 9; int boxw = font->height / 6 + 2; @@ -1442,6 +1443,8 @@ drawbar(Monitor *mon) if (!mon || !mon->showbar) return; + mh = mon->b.height - borderpx * 2; + mw = mon->b.width - borderpx * 2; stride = mon->b.width * 4; size = stride * mon->b.height; @@ -1452,13 +1455,15 @@ drawbar(Monitor *mon) pix = pixman_image_create_bits( PIXMAN_a8r8g8b8, mon->b.width, mon->b.height, buf->data, stride); + draw_rect(pix, 0, 0, mon->b.width, mon->b.height, 1, &borderbar); + /* draw status first so it can be overdrawn by tags later */ if (mon == selmon) { if (stext[0] == '\0') strncpy(stext, "dwl-"VERSION, sizeof(stext)); - draw_rect(pix, 0, 0, mon->b.width, mon->b.height, 1, &normbarbg); + draw_rect(pix, borderpx, y, mw, mh, 1, &normbarbg); tw = TEXTW(stext) - lrpad + 2; - draw_text(pix, mon->b.width - tw, 0, tw, mon->b.height, 0, stext, &normbarfg); + draw_text(pix, borderpx + mw - tw, y, tw + borderpx, mh, 0, stext, &normbarfg); } wl_list_for_each(c, &clients, link) { @@ -1469,34 +1474,34 @@ drawbar(Monitor *mon) urg |= c->tags; } c = focustop(mon); - x = 0; + x = borderpx; for (i = 0; i < LENGTH(tags); i++) { w = TEXTW(tags[i]); sel = mon->tagset[mon->seltags] & 1 << i; - draw_rect(pix, x, 0, w, mon->b.height, 1, + draw_rect(pix, x, y, w, mh, 1, urg & 1 << i ? &selbarfg : (sel ? &selbarbg : &normbarbg)); - draw_text(pix, x, 0, w, mon->b.height, lrpad / 2, tags[i], + draw_text(pix, x, y, w, mh, lrpad / 2, tags[i], urg & 1 << i ? &selbarbg : (sel ? &selbarfg : &normbarfg)); if (occ & 1 << i) - draw_rect(pix, x + boxs, boxs, boxw, boxw, + draw_rect(pix, x + boxs, y + boxs, boxw, boxw, sel, urg & 1 << i ? &selbarbg : (sel ? &selbarfg : &normbarfg)); x += w; } w = TEXTW(mon->ltsymbol); - draw_rect(pix, x, 0, w, mon->b.height, 1, &normbarbg); - x = draw_text(pix, x, 0, w, mon->b.height, lrpad / 2, mon->ltsymbol, &normbarfg); + draw_rect(pix, x, y, w, mh, 1, &normbarbg); + x = draw_text(pix, x, y, w, mh, lrpad / 2, mon->ltsymbol, &normbarfg); - if ((w = mon->b.width - tw - x) > mon->b.height) { + if ((w = mw - tw - x) > mh) { title = c ? client_get_title(c) : NULL; - draw_rect(pix, x, 0, w, mon->b.height, 1, + draw_rect(pix, x, y, w, mh, 1, (mon == selmon && title) ? &selbarbg : &normbarbg); - draw_text(pix, x, 0, w, mon->b.height, lrpad / 2, title, + draw_text(pix, x, y, w, mh, lrpad / 2, title, mon == selmon ? &selbarfg : &normbarfg); if (c && c->isfloating) - draw_rect(pix, x + boxs, boxs, boxw, boxw, 0, + draw_rect(pix, x + boxs, y + boxs, boxw, boxw, 0, mon == selmon ? &selbarfg : &normbarfg); } @@ -2755,7 +2760,7 @@ setup(void) die("Could not load font"); lrpad = font->height; - bh = font->height + 2; + bh = font->height + 2 + borderpx; status_event_source = wl_event_loop_add_fd(wl_display_get_event_loop(dpy), STDIN_FILENO, WL_EVENT_READABLE, status_in, NULL); -- 2.44.0