Re: [hackers] [dwm][PATCH] Ignore scroll lock along with caps and num lock
Hiltjo Posthuma (hiltjo=codemadness.org) via suckless hackers list wrote:
> On Wed, Oct 28, 2026 at 09:15:16AM +0000, Vedant Sule via suckless hackers list wrote:
>> Add scroll lock mask to the list of masks ignored when registering key
>> and button presses. This also expands the updatenumlockmask function to
>> update the modmasks of all locks (caps, num, and scroll).
>>
>> Updated to be compatible with the current head of the repo.
>> ---
>> dwm.c | 27 ++++++++++++++++++++-------
>> 1 file changed, 20 insertions(+), 7 deletions(-)
>>
>> diff --git a/dwm.c b/dwm.c
>> index 421704c..42b24a1 100644
>> --- a/dwm.c
>> +++ b/dwm.c
>> _at_@ -46,10 +46,13 @@
>>
>> /* macros */
>> #define BUTTONMASK (ButtonPressMask|ButtonReleaseMask)
>> -#define CLEANMASK(mask) (mask & ~(numlockmask|LockMask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask))
>> +#define CLEANMASK(mask) (mask & ~(capslockmask|numlockmask|scrolllockmask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask))
>> #define INTERSECT(x,y,w,h,m) (MAX(0, MIN((x)+(w),(m)->wx+(m)->ww) - MAX((x),(m)->wx)) \
>> * MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy)))
>> #define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags]))
>> +#define MODIFIERS { 0, capslockmask, numlockmask, scrolllockmask, \
>> + capslockmask|numlockmask, numlockmask|scrolllockmask, capslockmask|scrolllockmask, \
>> + capslockmask|numlockmask|scrolllockmask }
>> #define MOUSEMASK (BUTTONMASK|PointerMotionMask)
>> #define WIDTH(X) ((X)->w + 2 * (X)->bw)
>> #define HEIGHT(X) ((X)->h + 2 * (X)->bw)
>> _at_@ -219,7 +222,7 @@ static void updatebarpos(Monitor *m);
>> static void updatebars(void);
>> static void updateclientlist(void);
>> static int updategeom(void);
>> -static void updatenumlockmask(void);
>> +static void updatelockmasks(void);
>> static void updatesizehints(Client *c);
>> static void updatestatus(void);
>> static void updatetitle(Client *c);
>> _at_@ -241,7 +244,9 @@ static int sw, sh; /* X display screen geometry width, height */
>> static int bh; /* bar height */
>> static int lrpad; /* sum of left and right padding for text */
>> static int (*xerrorxlib)(Display *, XErrorEvent *);
>> +static unsigned int capslockmask = 0;
>> static unsigned int numlockmask = 0;
>> +static unsigned int scrolllockmask = 0;
>> static void (*handler[LASTEvent]) (XEvent *) = {
>> [ButtonPress] = buttonpress,
>> [ClientMessage] = clientmessage,
>> _at_@ -937,10 +942,10 @@ gettextprop(Window w, Atom atom, char *text, unsigned int size)
>> void
>> grabbuttons(Client *c, int focused)
>> {
>> - updatenumlockmask();
>> + updatelockmasks();
>> {
>> unsigned int i, j;
>> - unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask };
>> + unsigned int modifiers[] = MODIFIERS;
>> XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
>> if (!focused)
>> XGrabButton(dpy, AnyButton, AnyModifier, c->win, False,
>> _at_@ -958,10 +963,10 @@ grabbuttons(Client *c, int focused)
>> void
>> grabkeys(void)
>> {
>> - updatenumlockmask();
>> + updatelockmasks();
>> {
>> unsigned int i, j, k;
>> - unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask };
>> + unsigned int modifiers[] = MODIFIERS;
>> int start, end, skip;
>> KeySym *syms;
>>
>> _at_@ -1955,19 +1960,27 @@ updategeom(void)
>> }
>>
>> void
>> -updatenumlockmask(void)
>> +updatelockmasks(void)
>> {
>> unsigned int i, j;
>> XModifierKeymap *modmap;
>>
>> + capslockmask = 0;
>> numlockmask = 0;
>> + scrolllockmask = 0;
>> if (!(modmap = XGetModifierMapping(dpy)))
>> return;
>> for (i = 0; i < 8; i++)
>> for (j = 0; j < modmap->max_keypermod; j++)
>> if (modmap->modifiermap[i * modmap->max_keypermod + j]
>> + == XKeysymToKeycode(dpy, XK_Caps_Lock))
>> + capslockmask = (1 << i);
>> + else if (modmap->modifiermap[i * modmap->max_keypermod + j]
>> == XKeysymToKeycode(dpy, XK_Num_Lock))
>> numlockmask = (1 << i);
>> + else if (modmap->modifiermap[i * modmap->max_keypermod + j]
>> + == XKeysymToKeycode(dpy, XK_Scroll_Lock))
>> + scrolllockmask = (1 << i);
>> XFreeModifiermap(modmap);
>> }
>>
>> --
>> 2.55.0
>>
>>
>
> Hi,
>
> Thanks for the patch.
>
> Sorry if its obvious, but could you describe what it solves?
>
> I don't have issues with numlock or capslock being set and modifier keys.
> They work fine if its on or off.
>
Hi,
Thanks for your reply. Basically, dwm already ignores the state of caps
lock and num lock when listening for key presses, and I wanted to add
scroll lock to this. I recently enabled scroll lock by adding it to mod3
and found that none of my key presses worked if scroll lock was on.
I also expanded updatenumlockmask() to update the masks of the other two
locks because I'd already added scroll lock to it and thought I might as
well include caps lock. I also thought it would be better than relying
on capslock's mask being set to LockMask.
tldr it makes scroll lock work the same way as caps and num lock on dwm
Received on Fri Oct 30 2026 - 16:55:00 CET
This archive was generated by hypermail 2.3.0
: Fri Oct 30 2026 - 19:12:38 CET