Remove blw variable in favour of calculating the value when needed 5799dd1f
The purpose and reasoning behind the bar layout width (blw) variable
in dwm the way it is today may not be immediately obvious.

The use of the variable makes more sense when looking at commit
2ce37bc from 2009 where blw was initialised in the setup function
and it represented the maximum of all available layout symbols.

	for(blw = i = 0; LENGTH(layouts) > 1 && i < LENGTH(layouts); i++) {
		w = TEXTW(layouts[i].symbol);
		blw = MAX(blw, w);
	}

As such the layout symbol back then was fixed in size and both drawbar
and buttonpress depended on this variable.

The the way the blw variable is set today in drawbar means that it
merely caches the size of the layout symbol for the last bar drawn.

While unlikely to happen in practice it is possible that the last bar
drawn is not that of the currently selected monitor, which can result
in misaligned button clicks if there is a difference in layout symbol
width between monitors.
Stein · 2022-08-15 14:31 1 file(s) · +3 −3
dwm.c +3 −3
240 240
static char stext[256];
241 241
static int screen;
242 242
static int sw, sh;           /* X display screen geometry width, height */
243 -
static int bh, blw = 0;      /* bar geometry */
243 +
static int bh;               /* bar height */
244 244
static int lrpad;            /* sum of left and right padding for text */
245 245
static int (*xerrorxlib)(Display *, XErrorEvent *);
246 246
static unsigned int numlockmask = 0;
440 440
		if (i < LENGTH(tags)) {
441 441
			click = ClkTagBar;
442 442
			arg.ui = 1 << i;
443 -
		} else if (ev->x < x + blw)
443 +
		} else if (ev->x < x + TEXTW(selmon->ltsymbol))
444 444
			click = ClkLtSymbol;
445 445
		else if (ev->x > selmon->ww - (int)TEXTW(stext))
446 446
			click = ClkStatusText;
731 731
				urg & 1 << i);
732 732
		x += w;
733 733
	}
734 -
	w = blw = TEXTW(m->ltsymbol);
734 +
	w = TEXTW(m->ltsymbol);
735 735
	drw_setscheme(drw, scheme[SchemeNorm]);
736 736
	x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0);
737 737