swaywm / sway

i3-compatible Wayland compositor
https://swaywm.org
MIT License
14.43k stars 1.1k forks source link

Allow numpad bindings to be sensitive to numlock #6530

Open CobaltSpace opened 2 years ago

CobaltSpace commented 2 years ago

Please fill out the following:

Usecases:

litoj commented 1 year ago

this is in fact not exactly an enhancment, but mainly a compatibility with i3, which should be another reason to make this work.

dfoxfranke commented 2 months ago

+1 for attention to this issue.

The way I had things working in i3 was that I had most of my numpad mapped to i3 commands (with no modifier key required), but had it function as a normal numpad when numlock was on. I did this by discriminating on, e.g. KP_Begin vs. KP_5. I also customized my xkb map so that the numpad's +, -, *, /, and Enter would map to F13 through F17 when numlock was off, so that these keys would map to distinct keysyms that would allow me to discriminate on numlock state.

I haven't gone diving into the sway sources yet, but what appears to be going on here is that sway is too-eagerly trying to translate bindsym commands into equivalent bindcode commands. So e.g. when I write bindsym KP_Left move left, it seems as though sway is searching my keymap for a keycode that translates to KP_Left, finding 84 (aka <KP5>), and behaving as though I had written bindcode 84 move left. But these aren't the same thing, because keycode 84 only translates to KP_Left when numlock is off.