Search code examples
linuxkeyboardkeyboard-shortcutsuser-inputkeyboard-layout

XKB_DEFAULT_OPTIONS=grp:shift_caps_switch with more than two keyboard layouts


This option if set allows me to switch to first (us) and second (ru) layouts by simply pressing CapsLock and Shift+CapsLock respectively.
I'm happy with that behavior, since it's very ergonomic and distraction-free.

However, additionally I need third (pl) and fourth (ua) layouts, and looks like there's no predefined shortcut for them, nor any (documented?) option to enable it.

I don't want to change CapsLock → us, Shift+CapsLock → ru, behavior, ideally Ctrl+CapsLock shortcut should cycle between secondary (pl and ua) layouts.
What's the best way to bind it?


Solution

  • Finally, I've switched to sway WM and got a proper setup with the following config:

    input "1:1:AT_Translated_Set_2_keyboard" {
        xkb_options caps:none,shift:both_capslock,compose:ralt
        xkb_layout us
        xkb_numlock enabled
    }
    
    bindcode Ctrl+Shift+66 \
        input "1:1:AT_Translated_Set_2_keyboard" xkb_layout ua; \
        input "1:1:AT_Translated_Set_2_keyboard" xkb_options caps:none,shift:both_capslock,compose:ralt
    
    bindcode      Shift+66 \
        input "1:1:AT_Translated_Set_2_keyboard" xkb_layout ru; \
        input "1:1:AT_Translated_Set_2_keyboard" xkb_options caps:none,shift:both_capslock,compose:ralt
    
    bindcode       Ctrl+66 \
        input "1:1:AT_Translated_Set_2_keyboard" xkb_layout pl; \
        input "1:1:AT_Translated_Set_2_keyboard" xkb_options caps:none,shift:both_capslock,lv3:ralt_switch_multikey
    
    bindcode            66 \
        input "1:1:AT_Translated_Set_2_keyboard" xkb_layout us; \
        input "1:1:AT_Translated_Set_2_keyboard" xkb_options caps:none,shift:both_capslock,compose:ralt
    

    Here, I've disabled primary CapsLock, so it started to emit 66 keycode which then I've bound to combinations with other keys to corresponding keyboard layouts.

    Also, xkb_options are set alongside just to bind RightAlt as compose key on ua, ru, us and as lv3 symbols access key on pl layout.

    CapsLock functionality is still accessible with shift:both_capslock option.