--- Replaces magic numbers in statusbar with configurable variables. horizpadbar for horizontal statusbar padding vertpadbar for vertical statusbar padding StatusText now has both left and right padding, as well as the vertical padding that all of the statusbar shares. Other than the addition of left padding to StatusText, appearance of the statusbar is identical to pre-patch when using the defaults in config.def.h --- config.def.h | 2 ++ dwm.c | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/config.def.h b/config.def.h index a9ac303..5819399 100644 --- a/config.def.h +++ b/config.def.h _AT_@ -5,6 +5,8 @@ static const unsigned int borderpx = 1; /* border pixel of windows */ static const unsigned int snap = 32; /* snap pixel */ static const int showbar = 1; /* 0 means no bar */ static const int topbar = 1; /* 0 means bottom bar */ +static const int horizpadbar = 2; /* horizontal padding for statusbar */ +static const int vertpadbar = 0; /* vertical padding for statusbar */ static const char *fonts[] = { "monospace:size=10" }; static const char dmenufont[] = "monospace:size=10"; static const char col_gray1[] = "#222222"; diff --git a/dwm.c b/dwm.c index bb95e26..7b9ed42 100644 --- a/dwm.c +++ b/dwm.c _AT_@ -704,8 +704,8 @@ drawbar(Monitor *m) /* draw status first so it can be overdrawn by tags later */ if (m == selmon) { /* status is only drawn on selected monitor */ drw_setscheme(drw, scheme[SchemeNorm]); - sw = TEXTW(stext) - lrpad + 2; /* 2px right padding */ - drw_text(drw, m->ww - sw, 0, sw, bh, 0, stext, 0); + sw = TEXTW(stext); + drw_text(drw, m->ww - sw, 0, sw, bh, lrpad / 2, stext, 0); } for (c = m->clients; c; c = c->next) { _AT_@ -1544,8 +1544,8 @@ setup(void) drw = drw_create(dpy, screen, root, sw, sh); if (!drw_fontset_create(drw, fonts, LENGTH(fonts))) die("no fonts could be loaded."); - lrpad = drw->fonts->h; - bh = drw->fonts->h + 2; + lrpad = drw->fonts->h + horizpadbar; + bh = drw->fonts->h + vertpadbar; updategeom(); /* init atoms */ utf8string = XInternAtom(dpy, "UTF8_STRING", False); -- 2.7.4 On Thu, May 24, 2018 at 10:48 PM, Christopher Drelich <cd_AT_cdrakka.com> wrote: > Currently in dwm there are two magic numbers relating to the statusbar in dwm.c: > > sw = TEXTW(stext) - lrpad + 2; /* 2px right padding */ > > bh = drw->fonts->h + 2; > > I made a patch that replaced these magic numbers with configurable > variables, plus a third configurable variable that made sense with > these: > > vertbarpad is vertical padding for the statusbar. > horizbarpad is horizontal padding for the statusbar. > statusrpad is right hand padding for StatusText in the statusbar. > > It would be possible to add a 'statuslpad' as well, or to just make > the padding for the StatusText the same as that for other elements of > the statusbar, or to divide it by 2 and just use that for the > rightpadding. > > I think that having StatusText have the same padding as other elements > in the statusbar would probably end up making things cleanest. > > The main purpose of this patch is to eliminate 'magic numbers,' so the > hope is to open up discussion on how to do that, be it by this patch, > a suggested variant of it, something else, or if people think they > should just stay. > Chris > > --- > > Removes two magic numbers and replaces them with configurable > variables in config.def.h > > A third configurable variable was added, as it made sense to be > there given the existence of the other two variables. > > vertbarpad is vertical padding for the statusbar. > horizbarpad is horizontal padding for the statusbar. > statusrpad is right hand padding for StatusText in the statusbar. > --- > config.def.h | 3 +++ > dwm.c | 8 ++++---- > 2 files changed, 7 insertions(+), 4 deletions(-) > > diff --git a/config.def.h b/config.def.h > index a9ac303..4f03aa1 100644 > --- a/config.def.h > +++ b/config.def.h > _AT_@ -5,6 +5,9 @@ static const unsigned int borderpx = 1; /* > border pixel of windows */ > static const unsigned int snap = 32; /* snap pixel */ > static const int showbar = 1; /* 0 means no bar */ > static const int topbar = 1; /* 0 means bottom bar */ > +static const int horizbarpad = 0; /* horizontal bar padding */ > +static const int vertbarpad = 2; /* vertical bar padding */ > +static const int statusrpad = 2; /* right padding for > StatusText */ > static const char *fonts[] = { "monospace:size=10" }; > static const char dmenufont[] = "monospace:size=10"; > static const char col_gray1[] = "#222222"; > diff --git a/dwm.c b/dwm.c > index bb95e26..9014261 100644 > --- a/dwm.c > +++ b/dwm.c > _AT_@ -439,7 +439,7 @@ buttonpress(XEvent *e) > arg.ui = 1 << i; > } else if (ev->x < x + blw) > click = ClkLtSymbol; > - else if (ev->x > selmon->ww - TEXTW(stext)) > + else if (ev->x > selmon->ww - TEXTW(stext) + lrpad - statusrpad) > click = ClkStatusText; > else > click = ClkWinTitle; > _AT_@ -704,7 +704,7 @@ drawbar(Monitor *m) > /* draw status first so it can be overdrawn by tags later */ > if (m == selmon) { /* status is only drawn on selected monitor */ > drw_setscheme(drw, scheme[SchemeNorm]); > - sw = TEXTW(stext) - lrpad + 2; /* 2px right padding */ > + sw = TEXTW(stext) - lrpad + statusrpad; > drw_text(drw, m->ww - sw, 0, sw, bh, 0, stext, 0); > } > > _AT_@ -1544,8 +1544,8 @@ setup(void) > drw = drw_create(dpy, screen, root, sw, sh); > if (!drw_fontset_create(drw, fonts, LENGTH(fonts))) > die("no fonts could be loaded."); > - lrpad = drw->fonts->h; > - bh = drw->fonts->h + 2; > + lrpad = drw->fonts->h + horizbarpad; > + bh = drw->fonts->h + vertbarpad; > updategeom(); > /* init atoms */ > utf8string = XInternAtom(dpy, "UTF8_STRING", False); > -- > 2.7.4Received on Fri May 25 2018 - 05:31:28 CEST
This archive was generated by hypermail 2.3.0 : Fri May 25 2018 - 05:36:24 CEST