Sway gets layout-independent bindsym command

The default behavior of the bindsym command in Sway is a major pain point for users with several configured keyboard layouts. The command literally binds actions to keysyms, which means that your shortcuts constantly change their position or may not work at all.

What makes it look even more weird is that in i3 bindsym does work consistently in any layout, because i3 simply translates the specified keysyms into keycodes. You can even specify which layout should be used for the translation using Group[1-4].

The topic of input processing is far more complex than I could imagine, mostly because different people have very different opinions about how it should be implemented. The very idea to change the meaning of the bindsym command triggered a lot of back-and-forth discussion with quite a few people involved.

The process took some time, but in the end we finally got a solution that should work for everyone. With the new --to-code flag, the behavior of Sway’s bindsym becomes roughly equivalent to that of i3. This is not as tedious as you might think, because you can specify the flag only once per block of bindings:

bindsym --to-code {
    $mod+Return exec $term
    $mod+Shift+c reload
    # etc
}

A few points regarding the current implementation:

The feature will appear in Sway 1.1, which is going to be released soon. You can also get an RC build and try it out now.