Re: [hackers] [dwm][PATCH] Status bar magic numbers replaced with configurable variables.

From: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
Date: Fri, 25 May 2018 06:50:44 +0200

On Thu, May 24, 2018 at 10:48:27PM -0400, Christopher Drelich 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
>

How are they magic? Is any number in arithmetic some magic number for you?

I don't see the point of this endless bikeshedding and refactoring.

I won't apply this.

> ---
>
> 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.4
>

-- 
Kind regards,
Hiltjo
Received on Fri May 25 2018 - 06:50:44 CEST

This archive was generated by hypermail 2.3.0 : Fri May 25 2018 - 07:00:28 CEST