Sway: bindsym does not work in some keyboard layouts

Created on 27 Oct 2018  Â·  13Comments  Â·  Source: swaywm/sway

bindsym bindings with letters (like $mod+w) do not work in some keyboard layouts (e.g. ru).

The issue is in the way these shortcuts are processed. For bindsym, sway compares key syms, and key syms for w are different in these two keyboard layouts (119 for w, 1731 for ц).

Obviously having to switch keyboard layout to use a shortcut is inconvenient. It is possible to workaround this and use bindcode for all bindings, but the config file will become less readable.

I also checked i3, and bindsym worked fine in any keyboard layout.

It seems that the easiest way to fix it is to convert key syms into key codes while reading the config file, and then only check key codes on keyboard events.

If it sounds like a reasonable idea, I could look into this more and probably prepare a pull request, though it may take some time.

enhancement

Most helpful comment

You can use xev to get the keysym name in your ru layout.

I can, but I would expect these shortcuts to work in any layout out of the box. I cannot think of any use case to justify layout-dependent shortcuts.

I'd like not to do this, and anyway I don't think it's possible.

There should be a way to do that, but surely it is not a trivial change. It seems that i3 uses xkb_keymap_key_for_each to iterate through all keycodes in the keymap to create all possible keysyms to compare with, and then stores the matching keycodes with proper modifiers.

All 13 comments

key syms for w are different in these two keyboard layouts

You can use xev to get the keysym name in your ru layout.

convert key syms into key codes

I'd like not to do this, and anyway I don't think it's possible.

You can use xev to get the keysym name in your ru layout.

I can, but I would expect these shortcuts to work in any layout out of the box. I cannot think of any use case to justify layout-dependent shortcuts.

I'd like not to do this, and anyway I don't think it's possible.

There should be a way to do that, but surely it is not a trivial change. It seems that i3 uses xkb_keymap_key_for_each to iterate through all keycodes in the keymap to create all possible keysyms to compare with, and then stores the matching keycodes with proper modifiers.

There should be a way to do that, but surely it is not a trivial change. It seems that i3 uses xkb_keymap_key_for_each to iterate through all keycodes in the keymap to create all possible keysyms to compare with, and then stores the matching keycodes with proper modifiers.

So if your layout happens to be ru while the config is processed (e.g. on reload), none of your bindings will work anymore because no key code will match the keysym? Surely not doing this for all possible keymaps, especially when input config can change at runtime with swaymsg...

So if your layout happens to be ru while the config is processed (e.g. on reload), none of your bindings will work anymore because no key code will match the keysym?

I've checked how some apps on X11 (i3, gedit, gnome-terminal) handle this (setxkbmap ru) — yes, none of the keybindings works (even the predefined ones like ^W in terminal or ^S in gedit).

But using ru layout alone is uncommon, most users use it together with some Latin layout (e.g. setxkbmap us,ru).

any updates on this? it's very annoying

Please help us debug it, find out what's wrong.

This is simple I've got layout en,ru. When I switch to en, all bindings work perfectly. When I switch to ru, all "letter" bindings stop working.

This is simple

Then send a patch.

I could, but I'm not familiar with sway source code (yet?).

I can see two ways of solving this: the first was proposed in PR by @kupospelov - not binding to specific symbols, but to physical keys instead.

The second is using sophisicated logic to determine which symbols in different layouts correspond to each other. i3 seems to use some functions from libxkbcommon-x11 for that. I think, it's not an option for wayland? Maybe there are some alternatives? Needs investigating.

The only thing I want to say - this needs to be fixed. You just cannot leave it as it is.

The only thing I want to say - this needs to be fixed. You just cannot leave it as it is.

We're all volunteers, and we never force anyone to work on anything. We work during our free time. In particular, sentences like "you can't do this, you need to fix this" or "this is the only thing I need to switch to sway" will be ignored.

Instead, please help us!

I can see two ways of solving this: the first was proposed in PR by @kupospelov - not binding to specific symbols, but to physical keys instead.

Have you tried his PR?

this is the only thing I need to switch to sway

I've already switched to sway. And it pretty much satisfies me as it is now. But this problem just annoys me from time to time.

Have you tried his PR?

no, not yet.

Have you tried his PR?

I did, I used it for a bit together with my own PR before returning back to X11. It worked well for me.

Super annoying, unfortunately. Especially for the beginners when I switch to Russian layout none of the keybindings work so I can't even switch back to British layout. Not even mod + enter works so that I could change the layout. I am pretty much locking myself out of the system as soon as I switch to russian.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cauebs picture cauebs  Â·  3Comments

J0nnyMak0 picture J0nnyMak0  Â·  3Comments

emersion picture emersion  Â·  4Comments

StephenBrown2 picture StephenBrown2  Â·  4Comments

mcmfb picture mcmfb  Â·  3Comments