From e9b07a4d70e8358a05d0c4ab73aeab87aab194ac Mon Sep 17 00:00:00 2001 From: Ray Andrew <4437323+rayandrew@users.noreply.github.com> Date: Sun, 13 Oct 2024 16:33:00 -0500 Subject: [PATCH] add systray border --- dwm.c | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/dwm.c b/dwm.c index 5e26e26..cd9a484 100644 --- a/dwm.c +++ b/dwm.c @@ -207,7 +207,7 @@ static void detachstack(Client *c); static Monitor *dirtomon(int dir); static void drawbar(Monitor *m); static void drawbars(void); -static int drawstatusbar(Monitor *m, int bh, char* text); +static int drawstatusbar(Monitor *m, int bh, char* text, int stw); static void enternotify(XEvent *e); static void expose(XEvent *e); static void focus(Client *c); @@ -945,12 +945,12 @@ dirtomon(int dir) } int -drawstatusbar(Monitor *m, int bh, char* stext) { +drawstatusbar(Monitor *m, int bh, char* stext, int stw) { int ret, i, j, w, x, len; short isCode = 0; char *text; char *p; - int mw = m->ww - borderpx * 2; + int mw = m->ww; int th = bh - borderpx * 2; len = strlen(stext) + 1 ; @@ -995,7 +995,7 @@ drawstatusbar(Monitor *m, int bh, char* stext) { drw_setscheme(drw, scheme[LENGTH(colors)]); drw->scheme[ColFg] = scheme[SchemeNorm][ColFg]; drw->scheme[ColBg] = scheme[SchemeNorm][ColBg]; - drw_rect(drw, x - 2 * sp, borderpx, w + borderpx - sp * 2, th, 1, 1); + drw_rect(drw, x - 2 * sp - stw, borderpx, w + borderpx + stw, th, 1, 1); x++; /* process status text */ @@ -1050,7 +1050,7 @@ drawstatusbar(Monitor *m, int bh, char* stext) { if (!isCode) { w = TEXTW(text, statusfontindex) - lrpad; - drw_text(drw, x - 2 * sp, borderpx, w + borderpx, th, 0, text, 0, statusfontindex); + drw_text(drw, x - 2 * sp - stw, borderpx, w + borderpx + stw, th, 0, text, 0, statusfontindex); } drw_setscheme(drw, scheme[SchemeNorm]); @@ -1070,18 +1070,18 @@ drawbar(Monitor *m) unsigned int i, occ = 0, urg = 0; Client *c; - XSetForeground(drw->dpy, drw->gc, clrborder.pixel); - XFillRectangle(drw->dpy, drw->drawable, drw->gc, 0, 0, m->ww, bh); - if (!m->showbar) return; if(showsystray && m == systraytomon(m)) stw = getsystraywidth(); + XSetForeground(drw->dpy, drw->gc, clrborder.pixel); + XFillRectangle(drw->dpy, drw->drawable, drw->gc, 0, 0, m->ww, bh); + /* draw status first so it can be overdrawn by tags later */ if (m == selmon || 1) { /* status is only drawn on selected monitor */ - tw = statusw = m->ww - drawstatusbar(m, bh, stext); + tw = statusw = m->ww - drawstatusbar(m, bh, stext, stw); } resizebarwin(m); @@ -1097,7 +1097,7 @@ drawbar(Monitor *m) continue; w = TEXTW(tags[i], statusfontindex); drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]); - drw_text(drw, x, y, w , th, lrpad / 2, tags[i], urg & 1 << i, statusfontindex); + drw_text(drw, x, y, w, th, lrpad / 2, tags[i], urg & 1 << i, statusfontindex); if (ulineall || m->tagset[m->seltags] & 1 << i) drw_rect(drw, x + ulinepad, bh - ulinestroke - ulinevoffset, w - (ulinepad * 2), ulinestroke, 1, 0); @@ -1111,14 +1111,14 @@ drawbar(Monitor *m) if ((w = mw - tw - x) > th) { if (m->sel) { drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]); - drw_text(drw, x, y, w - sidepad, th, lrpad / 2, m->sel->name, 0, statusfontindex); + drw_text(drw, x, y, w - sidepad - stw, th, lrpad / 2, m->sel->name, 0, statusfontindex); if (m->sel->isfloating) - drw_rect(drw, x + boxs, y + boxs, boxw, boxw, m->sel->isfixed, 0); + drw_rect(drw, x + boxs, y + boxs, boxw - stw, boxw, m->sel->isfixed, 0); } else { drw_setscheme(drw, scheme[SchemeNorm]); // drw_rect(drw, x, 0, w - 2 * sp, bh, 1, 1); // drw_rect(drw, x, y, w - 2 * sp, th, 1, 1); - drw_rect(drw, x, y, w - 1, th, 1, 1); + drw_rect(drw, x, y, w - sp - stw, th, 1, 1); } } drw_map(drw, m->barwin, 0, 0, m->ww - stw, bh); @@ -2655,7 +2655,7 @@ togglebar(const Arg *arg) wc.y = -bh; else if (selmon->showbar) { wc.y = 0; - if (!selmon->topbar) + if (!selmon->topbar) wc.y = selmon->mh - bh; } XConfigureWindow(dpy, systray->win, CWY, &wc); @@ -3059,6 +3059,8 @@ updatesystrayicongeom(Client *i, int w, int h) if (i->w > 2*bh) i->w = bh; } + i->w = i->w - sp * 2 - borderpx * 2; + i->h = i->h - sp * 2 - borderpx * 2; } void @@ -3096,7 +3098,7 @@ updatesystray(void) XWindowChanges wc; Client *i; Monitor *m = systraytomon(NULL); - unsigned int x = m->mx + m->mw; + unsigned int x = m->mx + m->mw - sp; unsigned int w = 1; if (!showsystray) @@ -3135,22 +3137,24 @@ updatesystray(void) XMapRaised(dpy, i->win); w += systrayspacing; i->x = w; - XMoveResizeWindow(dpy, i->win, i->x, 0, i->w, i->h); + XMoveResizeWindow(dpy, i->win, i->x, 3 * borderpx + 1, i->w, i->h); w += i->w; if (i->mon != m) i->mon = m; } - w = w ? w + systrayspacing : 1; + w = w ? w + systrayspacing + borderpx : 1; x -= w; XMoveResizeWindow(dpy, systray->win, x, m->by, w, bh); - wc.x = x; wc.y = m->by; wc.width = w; wc.height = bh; + wc.x = x; wc.y = m->by - borderpx; wc.width = w; wc.height = bh; wc.stack_mode = Above; wc.sibling = m->barwin; XConfigureWindow(dpy, systray->win, CWX|CWY|CWWidth|CWHeight|CWSibling|CWStackMode, &wc); XMapWindow(dpy, systray->win); XMapSubwindows(dpy, systray->win); /* redraw background */ - XSetForeground(dpy, drw->gc, scheme[SchemeNorm][ColBg].pixel); + XSetForeground(dpy, drw->gc, clrborder.pixel); XFillRectangle(dpy, systray->win, drw->gc, 0, 0, w, bh); + XSetForeground(dpy, drw->gc, scheme[SchemeNorm][ColBg].pixel); + XFillRectangle(dpy, systray->win, drw->gc, 0, borderpx, w - borderpx, bh - 2 * borderpx); XSync(dpy, False); }