implemented barpadding patch and fixed issues with systray

This commit is contained in:
_N0x 2021-10-13 16:26:23 +02:00
parent 0297cb5edc
commit e429212501
2 changed files with 27 additions and 15 deletions

View File

@ -11,6 +11,8 @@ static const int systraypinningfailfirst = 1; /* 1: if pinning fails, display
static const int showsystray = 1; /* 0 means no systray */ static const int showsystray = 1; /* 0 means no systray */
static const int showbar = 1; /* 0 means no bar */ static const int showbar = 1; /* 0 means no bar */
static const int topbar = 1; /* 0 means bottom bar */ static const int topbar = 1; /* 0 means bottom bar */
static const int vertpad = 8; /* vertical padding of bar */
static const int sidepad = 8; /* horizontal padding of bar */
static const char *fonts[] = { "MesloLGS NF:size=11" }; static const char *fonts[] = { "MesloLGS NF:size=11" };
static const char dmenufont[] = "MesloLGS NF:size=11"; static const char dmenufont[] = "MesloLGS NF:size=11";
static const char dmenupromt[] = "Run:"; static const char dmenupromt[] = "Run:";

View File

@ -284,6 +284,8 @@ static int screen;
static int sw, sh; /* X display screen geometry width, height */ static int sw, sh; /* X display screen geometry width, height */
static int bh, blw = 0; /* bar geometry */ static int bh, blw = 0; /* bar geometry */
static int lrpad; /* sum of left and right padding for text */ static int lrpad; /* sum of left and right padding for text */
static int vp; /* vertical padding for bar */
static int sp; /* side padding for bar */
static int (*xerrorxlib)(Display *, XErrorEvent *); static int (*xerrorxlib)(Display *, XErrorEvent *);
static unsigned int numlockmask = 0; static unsigned int numlockmask = 0;
static void (*handler[LASTEvent]) (XEvent *) = { static void (*handler[LASTEvent]) (XEvent *) = {
@ -850,8 +852,7 @@ drawstatusbar(Monitor *m, int bh, char* stext, int stw) {
text[i] = '\0'; text[i] = '\0';
w = TEXTW(text) - lrpad; w = TEXTW(text) - lrpad;
drw_text(drw, x - stw, 0, w, bh, 0, text, 0); drw_text(drw, x - stw - 2 * sp, 0, w, bh, 0, text, 0);
x += w; x += w;
/* process code */ /* process code */
@ -894,7 +895,7 @@ drawstatusbar(Monitor *m, int bh, char* stext, int stw) {
if (!isCode) { if (!isCode) {
w = TEXTW(text) - lrpad; w = TEXTW(text) - lrpad;
drw_text(drw, x - stw, 0, w, bh, 0, text, 0); drw_text(drw, x - stw - 2 * sp, 0, w, bh, 0, text, 0);
} }
drw_setscheme(drw, scheme[SchemeNorm]); drw_setscheme(drw, scheme[SchemeNorm]);
@ -947,12 +948,12 @@ drawbar(Monitor *m)
if ((w = m->ww - sw - stw - x) > bh) { if ((w = m->ww - sw - stw - x) > bh) {
if (m->sel) { if (m->sel) {
drw_setscheme(drw, scheme[m == selmon ? SchemeInfoSel : SchemeInfoNorm]); drw_setscheme(drw, scheme[m == selmon ? SchemeInfoSel : SchemeInfoNorm]);
drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0); drw_text(drw, x, 0, w - 2 * sp, bh, lrpad / 2, m->sel->name, 0);
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, boxs, boxw, boxw, m->sel->isfixed, 0);
} else { } else {
drw_setscheme(drw, scheme[SchemeInfoNorm]); drw_setscheme(drw, scheme[SchemeInfoNorm]);
drw_rect(drw, x, 0, w, bh, 1, 1); drw_rect(drw, x, 0, w - 2 * sp, bh, 1, 1);
} }
} }
drw_map(drw, m->barwin, 0, 0, m->ww - stw, bh); drw_map(drw, m->barwin, 0, 0, m->ww - stw, bh);
@ -1543,7 +1544,7 @@ 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 + sp, m->by + vp, w - 2 * sp, bh);
} }
void void
@ -1931,6 +1932,9 @@ setup(void)
lrpad = drw->fonts->h; lrpad = drw->fonts->h;
bh = drw->fonts->h + 2; bh = drw->fonts->h + 2;
updategeom(); updategeom();
sp = sidepad;
vp = (topbar == 1) ? vertpad : - vertpad;
/* init atoms */ /* init atoms */
utf8string = XInternAtom(dpy, "UTF8_STRING", False); utf8string = XInternAtom(dpy, "UTF8_STRING", False);
wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False); wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
@ -1967,6 +1971,7 @@ setup(void)
/* init bars */ /* init bars */
updatebars(); updatebars();
updatestatus(); updatestatus();
updatebarpos(selmon);
/* supporting window for NetWMCheck */ /* supporting window for NetWMCheck */
wmcheckwin = XCreateSimpleWindow(dpy, root, 0, 0, 1, 1, 0, 0, 0); wmcheckwin = XCreateSimpleWindow(dpy, root, 0, 0, 1, 1, 0, 0, 0);
XChangeProperty(dpy, wmcheckwin, netatom[NetWMCheck], XA_WINDOW, 32, XChangeProperty(dpy, wmcheckwin, netatom[NetWMCheck], XA_WINDOW, 32,
@ -2226,7 +2231,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, w -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);
@ -2243,11 +2248,11 @@ updatebarpos(Monitor *m)
m->wy = m->my; m->wy = m->my;
m->wh = m->mh; m->wh = m->mh;
if (m->showbar) { if (m->showbar) {
m->wh -= bh; m->wh = m->wh - vertpad - bh;
m->by = m->topbar ? m->wy : m->wy + m->wh; m->by = m->topbar ? m->wy : m->wy + m->wh + vertpad;
m->wy = m->topbar ? m->wy + bh : m->wy; m->wy = m->topbar ? m->wy + bh + vp : m->wy;
} else } else
m->by = -bh; m->by = -bh - vp;
} }
void void
@ -2468,7 +2473,8 @@ updatesystray(void)
XWindowChanges wc; XWindowChanges wc;
Client *i; Client *i;
Monitor *m = systraytomon(NULL); Monitor *m = systraytomon(NULL);
unsigned int x = m->mx + m->mw; unsigned int x = m->mx + m->mw - sp;
unsigned int y = m->by + vp;
unsigned int w = 1; unsigned int w = 1;
if (!showsystray) if (!showsystray)
@ -2477,7 +2483,7 @@ updatesystray(void)
/* init systray */ /* init systray */
if (!(systray = (Systray *)calloc(1, sizeof(Systray)))) if (!(systray = (Systray *)calloc(1, sizeof(Systray))))
die("fatal: could not malloc() %u bytes\n", sizeof(Systray)); die("fatal: could not malloc() %u bytes\n", sizeof(Systray));
systray->win = XCreateSimpleWindow(dpy, root, x, m->by, w, bh, 0, 0, scheme[SchemeSel][ColBg].pixel); systray->win = XCreateSimpleWindow(dpy, root, x, y, w, bh, 0, 0, scheme[SchemeSel][ColBg].pixel);
wa.event_mask = ButtonPressMask | ExposureMask; wa.event_mask = ButtonPressMask | ExposureMask;
wa.override_redirect = True; wa.override_redirect = True;
wa.background_pixel = scheme[SchemeNorm][ColBg].pixel; wa.background_pixel = scheme[SchemeNorm][ColBg].pixel;
@ -2513,8 +2519,12 @@ updatesystray(void)
w = w ? w + systrayspacing : 1; w = w ? w + systrayspacing : 1;
x -= w; x -= w;
XMoveResizeWindow(dpy, systray->win, x, m->by, w, bh); 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.stack_mode = Above; wc.sibling = m->barwin; wc.y = y;
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); XConfigureWindow(dpy, systray->win, CWX|CWY|CWWidth|CWHeight|CWSibling|CWStackMode, &wc);
XMapWindow(dpy, systray->win); XMapWindow(dpy, systray->win);
XMapSubwindows(dpy, systray->win); XMapSubwindows(dpy, systray->win);