[hackers] [dwm] Remove blw variable in favour of calculating the value when needed || Stein

From: <git_AT_suckless.org>
Date: Wed, 17 Aug 2022 13:35:15 +0200 (CEST)

commit 5799dd1fca6576b662d299e210cd5933b29d502d
Author: Stein <bakkeby_AT_gmail.com>
AuthorDate: Mon Aug 15 14:31:22 2022 +0200
Commit: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
CommitDate: Wed Aug 17 13:33:57 2022 +0200

    Remove blw variable in favour of calculating the value when needed
    
    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.

diff --git a/dwm.c b/dwm.c
index f2bc4ba..253aba7 100644
--- a/dwm.c
+++ b/dwm.c
_AT_@ -240,7 +240,7 @@ static const char broken[] = "broken";
 static char stext[256];
 static int screen;
 static int sw, sh; /* X display screen geometry width, height */
-static int bh, blw = 0; /* bar geometry */
+static int bh; /* bar height */
 static int lrpad; /* sum of left and right padding for text */
 static int (*xerrorxlib)(Display *, XErrorEvent *);
 static unsigned int numlockmask = 0;
_AT_@ -440,7 +440,7 @@ buttonpress(XEvent *e)
                 if (i < LENGTH(tags)) {
                         click = ClkTagBar;
                         arg.ui = 1 << i;
- } else if (ev->x < x + blw)
+ } else if (ev->x < x + TEXTW(selmon->ltsymbol))
                         click = ClkLtSymbol;
                 else if (ev->x > selmon->ww - (int)TEXTW(stext))
                         click = ClkStatusText;
_AT_@ -731,7 +731,7 @@ drawbar(Monitor *m)
                                 urg & 1 << i);
                 x += w;
         }
- w = blw = TEXTW(m->ltsymbol);
+ w = TEXTW(m->ltsymbol);
         drw_setscheme(drw, scheme[SchemeNorm]);
         x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0);
 
Received on Wed Aug 17 2022 - 13:35:15 CEST

This archive was generated by hypermail 2.3.0 : Wed Aug 17 2022 - 13:36:37 CEST