add bar border

This commit is contained in:
Ray Andrew 2024-10-08 01:31:04 -05:00
parent 71137ae6d7
commit c5c6a42c53
2 changed files with 32 additions and 20 deletions

View file

@ -32,6 +32,7 @@ static const char col_gray1[] = "#101010";
static const char col_gray2[] = "#444444"; static const char col_gray2[] = "#444444";
static const char col_gray3[] = "#b9b9b9"; static const char col_gray3[] = "#b9b9b9";
static const char col_gray4[] = "#525252"; static const char col_gray4[] = "#525252";
static const char col_borderbar[] = "#525252";
static const char *colors[][3] = { static const char *colors[][3] = {
/* fg bg border */ /* fg bg border */
[SchemeNorm] = { col_gray3, col_gray1, col_gray2 }, [SchemeNorm] = { col_gray3, col_gray1, col_gray2 },

49
dwm.c
View file

@ -341,7 +341,7 @@ static void (*handler[LASTEvent]) (XEvent *) = {
static Atom wmatom[WMLast], netatom[NetLast], xatom[XLast]; static Atom wmatom[WMLast], netatom[NetLast], xatom[XLast];
static int running = 1; static int running = 1;
static Cur *cursor[CurLast]; static Cur *cursor[CurLast];
static Clr **scheme; static Clr **scheme, clrborder;
static Display *dpy; static Display *dpy;
static Drw *drw; static Drw *drw;
static Monitor *mons, *selmon; static Monitor *mons, *selmon;
@ -947,6 +947,8 @@ drawstatusbar(Monitor *m, int bh, char* stext) {
short isCode = 0; short isCode = 0;
char *text; char *text;
char *p; char *p;
int mw = m->ww - borderpx * 2;
int th = bh - borderpx * 2;
len = strlen(stext) + 1 ; len = strlen(stext) + 1 ;
if (!(text = (char*) malloc(sizeof(char)*len))) if (!(text = (char*) malloc(sizeof(char)*len)))
@ -985,12 +987,12 @@ drawstatusbar(Monitor *m, int bh, char* stext) {
text = p; text = p;
w += 2; /* 1px padding on both sides */ w += 2; /* 1px padding on both sides */
ret = x = m->ww - w; ret = x = m->ww - w - borderpx * 2;
drw_setscheme(drw, scheme[LENGTH(colors)]); drw_setscheme(drw, scheme[LENGTH(colors)]);
drw->scheme[ColFg] = scheme[SchemeNorm][ColFg]; drw->scheme[ColFg] = scheme[SchemeNorm][ColFg];
drw->scheme[ColBg] = scheme[SchemeNorm][ColBg]; drw->scheme[ColBg] = scheme[SchemeNorm][ColBg];
drw_rect(drw, x, 0, w, bh, 1, 1); drw_rect(drw, x, borderpx, w + borderpx - sp * 2, th, 1, 1);
x++; x++;
/* process status text */ /* process status text */
@ -1001,7 +1003,7 @@ drawstatusbar(Monitor *m, int bh, char* stext) {
text[i] = '\0'; text[i] = '\0';
w = TEXTW(text, statusfontindex) - lrpad; w = TEXTW(text, statusfontindex) - lrpad;
drw_text(drw, x, 0, w, bh, 0, text, 0, statusfontindex); drw_text(drw, x, borderpx, w + borderpx, bh, 0, text, 0, statusfontindex);
x += w; x += w;
@ -1045,7 +1047,7 @@ drawstatusbar(Monitor *m, int bh, char* stext) {
if (!isCode) { if (!isCode) {
w = TEXTW(text, statusfontindex) - lrpad; w = TEXTW(text, statusfontindex) - lrpad;
drw_text(drw, x, 0, w, bh, 0, text, 0, statusfontindex); drw_text(drw, x - 2 * sp, borderpx, w + borderpx, th, 0, text, 0, statusfontindex);
} }
drw_setscheme(drw, scheme[SchemeNorm]); drw_setscheme(drw, scheme[SchemeNorm]);
@ -1057,12 +1059,17 @@ drawstatusbar(Monitor *m, int bh, char* stext) {
void void
drawbar(Monitor *m) drawbar(Monitor *m)
{ {
int x, w, tw = 0, stw = 0; int x, y = borderpx, w, tw = 0, stw = 0;
int th = bh - borderpx * 2;
int mw = m->ww - borderpx * 2;
int boxs = drw->fonts->h / 9; int boxs = drw->fonts->h / 9;
int boxw = drw->fonts->h / 6 + 2; int boxw = drw->fonts->h / 6 + 2;
unsigned int i, occ = 0, urg = 0; unsigned int i, occ = 0, urg = 0;
Client *c; Client *c;
XSetForeground(drw->dpy, drw->gc, clrborder.pixel);
XFillRectangle(drw->dpy, drw->drawable, drw->gc, 0, 0, m->ww, bh);
if (!m->showbar) if (!m->showbar)
return; return;
@ -1071,10 +1078,6 @@ drawbar(Monitor *m)
/* draw status first so it can be overdrawn by tags later */ /* draw status first so it can be overdrawn by tags later */
if (m == selmon || 1) { /* status is only drawn on selected monitor */ if (m == selmon || 1) { /* status is only drawn on selected monitor */
// drw_setscheme(drw, scheme[SchemeNorm]);
// tw = TEXTW(stext, statusfontindex) - lrpad + 2; /* 2px right padding */
// drw_text(drw, m->ww - tw - stw, 0, tw, bh, 0, stext, 0, statusfontindex);
// tw = m->ww - drawstatusbar(m, bh, stext);
tw = statusw = m->ww - drawstatusbar(m, bh, stext); tw = statusw = m->ww - drawstatusbar(m, bh, stext);
} }
@ -1084,14 +1087,14 @@ drawbar(Monitor *m)
if (c->isurgent) if (c->isurgent)
urg |= c->tags; urg |= c->tags;
} }
x = 0; x = borderpx;
for (i = 0; i < LENGTH(tags); i++) { for (i = 0; i < LENGTH(tags); i++) {
/* Do not draw vacant tags */ /* Do not draw vacant tags */
if(!(occ & 1 << i || m->tagset[m->seltags] & 1 << i)) if(!(occ & 1 << i || m->tagset[m->seltags] & 1 << i))
continue; continue;
w = TEXTW(tags[i], statusfontindex); w = TEXTW(tags[i], statusfontindex);
drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]); drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]);
drw_text(drw, x, 0, w, bh, 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) if (ulineall || m->tagset[m->seltags] & 1 << i)
drw_rect(drw, x + ulinepad, bh - ulinestroke - ulinevoffset, w - (ulinepad * 2), ulinestroke, 1, 0); drw_rect(drw, x + ulinepad, bh - ulinestroke - ulinevoffset, w - (ulinepad * 2), ulinestroke, 1, 0);
@ -1099,17 +1102,21 @@ drawbar(Monitor *m)
} }
w = TEXTW(m->ltsymbol, statusfontindex); w = TEXTW(m->ltsymbol, statusfontindex);
drw_setscheme(drw, scheme[SchemeNorm]); drw_setscheme(drw, scheme[SchemeNorm]);
x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0, statusfontindex); x = drw_text(drw, x, y, w, th, lrpad / 2, m->ltsymbol, 0, statusfontindex);
if ((w = m->ww - tw - stw - x) > bh) { // if ((w = m->ww - tw - x) > th) {
if ((w = mw - tw - x) > th) {
if (m->sel) { if (m->sel) {
drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]); drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]);
drw_text(drw, x, 0, w - 2 * sp, bh, lrpad / 2, m->sel->name, 0, statusfontindex);
drw_text(drw, x, y, w - 1, th, lrpad / 2, m->sel->name, 0, statusfontindex);
if (m->sel->isfloating) if (m->sel->isfloating)
drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0); drw_rect(drw, x + boxs, y + boxs, boxw, boxw, m->sel->isfixed, 0);
} else { } else {
drw_setscheme(drw, scheme[SchemeNorm]); drw_setscheme(drw, scheme[SchemeNorm]);
drw_rect(drw, x, 0, w - 2 * sp, bh, 1, 1); // 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_map(drw, m->barwin, 0, 0, m->ww - stw, bh); drw_map(drw, m->barwin, 0, 0, m->ww - stw, bh);
@ -2033,7 +2040,8 @@ resizebarwin(Monitor *m) {
unsigned int w = m->ww; unsigned int w = m->ww;
if (showsystray && m == systraytomon(m)) if (showsystray && m == systraytomon(m))
w -= getsystraywidth(); w -= getsystraywidth();
XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, w, bh); // XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, w, bh);
XMoveResizeWindow(dpy, m->barwin, m->wx + sp, m->by + vp, w - 2 * sp, bh);
} }
void void
@ -2419,6 +2427,7 @@ setup(void)
die("no fonts could be loaded."); die("no fonts could be loaded.");
lrpad = drw->fonts->h; lrpad = drw->fonts->h;
bh = user_bh ? user_bh : drw->fonts->h + 2; bh = user_bh ? user_bh : drw->fonts->h + 2;
bh = bh + borderpx * 2;
sp = sidepad; sp = sidepad;
vp = (topbar == 1) ? vertpad : - vertpad; vp = (topbar == 1) ? vertpad : - vertpad;
updategeom(); updategeom();
@ -2456,6 +2465,8 @@ setup(void)
scheme[LENGTH(colors)] = drw_scm_create(drw, colors[0], 3); scheme[LENGTH(colors)] = drw_scm_create(drw, colors[0], 3);
for (i = 0; i < LENGTH(colors); i++) for (i = 0; i < LENGTH(colors); i++)
scheme[i] = drw_scm_create(drw, colors[i], 3); scheme[i] = drw_scm_create(drw, colors[i], 3);
drw_clr_create(drw, &clrborder, col_borderbar);
/* init system tray */ /* init system tray */
updatesystray(); updatesystray();
/* init bars */ /* init bars */
@ -2813,7 +2824,7 @@ updatebars(void)
w = m->ww; w = m->ww;
if (showsystray && m == systraytomon(m)) if (showsystray && m == systraytomon(m))
w -= getsystraywidth(); w -= getsystraywidth();
m->barwin = XCreateWindow(dpy, root, m->wx, m->by, w, bh, 0, DefaultDepth(dpy, screen), m->barwin = XCreateWindow(dpy, root, m->wx + sp, m->by + vp, m->ww - 2 * sp, bh, 0, DefaultDepth(dpy, screen),
CopyFromParent, DefaultVisual(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen),
CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa); CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa);
XDefineCursor(dpy, m->barwin, cursor[CurNormal]->cursor); XDefineCursor(dpy, m->barwin, cursor[CurNormal]->cursor);