swaywm / sway

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

Bindsyms using Mod5 (ISO_Level3_Shift) fail #1844

Closed frsfnrrg closed 6 years ago

frsfnrrg commented 6 years ago

Using wlroots & sway builds from today (swaywm/wlroots@12bf39a715b2 and 48c84cd1f).

My relevant environment variables are

  export XKB_DEFAULT_OPTIONS=lv3:caps_switch

And the relevant lines of .config/sway/sway are set $mod Mod5 and bindsym $mod+Return exec st. Pressing keys CapsLock+Enter should launch st; it doesn't. The cause is that keysym_is_modifier in sway/input/keyboard.c is overly specific in detecting modifiers; comparing with xmodmap output, I find

shift       Shift_L (0x32),  Shift_R (0x3e)
lock      
control     Control_L (0x25),  Control_R (0x69)
mod1        Alt_L (0x40),  Alt_R (0x6c),  Meta_L (0xcd)
mod2        Num_Lock (0x4d)
mod3      
mod4        Super_L (0x85),  Super_R (0x86),  Super_L (0xce),  Hyper_L (0xcf)
mod5        ISO_Level3_Shift (0x5c),  Mode_switch (0xcb)

so that keysym_is_modifier is most likely missing XKB_KEY_Num_Lock, XKB_KEY_Mode_switch, and XKB_KEY_ISO_Level3_Shift. (Now that I have added these cases to my local version of sway, CapsLock+Enter does launch st.)

It would be nice if sway would identify which keysyms generate modifiers from the xkb API instead of using using a hardcoded list which only works with default keyboards.

emersion commented 6 years ago

We've not (yet) found a way to do this automatically.

xmodmap -pm is implemented here: https://cgit.freedesktop.org/xorg/app/xmodmap/tree/exec.c#n215

emersion commented 6 years ago

From #wayland:

08:38 <daniels> emersion: yeah, keyboard shortcuts are ... exciting. especially when you get to multiple layouts and realise that people want ctrl+w to work regardless of whether they're in cyrillic or latin mode
08:39 <daniels> emersion: anyway, yeah, there's i'm afraid no real connection between keysyms and modifiers, especially as you have things like latching modifiers
frsfnrrg commented 6 years ago

I've made a short script (https://github.com/frsfnrrg/shortcut/blob/master/shortcut.py) with which to compare shortcut implementations. It requires Python3.6 and xev. So,

†(Isn't Unicode case normalization more appropriate? After all, some users might have keyboard states that translate QWERTY to Dvorak, and if they cared for key positions, they'd use bindcode not bindsym) ††Hopefully this would also identify latching modifiers.

martin-braun commented 1 year ago

Thank you for this issue. I wasn't able to bind ISO_Level3_Shift which is the right option key on German Macintosh keyboards, but binding Mod5 worked. This issue was helpful for me.