XKB_DEFAULT_OPTIONS=grp:shift_caps_switch 有两种以上的键盘布局

XKB_DEFAULT_OPTIONS=grp:shift_caps_switch with more than two keyboard layouts

这个选项如果设置允许我通过简单地分别按下 CapsLock 和 Shift+CapsLock 来切换到第一个 (us) 和第二个 (ru) 布局。
我对这种行为很满意,因为它非常符合人体工程学并且不会分心。

但是,我还需要第三个 (pl) 和第四个 (ua) 布局,看起来它们没有预定义的快捷方式,也没有任何(记录?)选项来启用它。

我不想更改 CapsLock → us,Shift+CapsLock → ru,行为,理想情况下 Ctrl+CapsLock 快捷键应该在辅助(pl 和 ua)布局之间循环。
最好的绑定方式是什么?

我相信您正在寻找 toggle 选项。

XKB_DEFAULT_OPTIONS=grp:shift_caps_toggle 

您也可以将其传递给 setxkb 命令

setxkbmap -rules xorg -model $model -layout "us,ru,pl,ua" \
 -option "grp:shift_caps_toggle"

文档参差不齐,但您可以使用 the xorg documentation or source description

诚然,如评论中所述,这不太理想,但是设置两个密钥组应该是微不足道的。

# This is the primary set
setxkbmap -rules xorg -model $model -layout "us,ru" \
 -option "grp:shift_caps_toggle"
# This is the secondary 
setxkbmap -rules xorg -model $model -layout "pl,ua" \
 -option "grp:ctrl_caps_toggle"

最后,我切换到 sway WM 并使用以下配置进行了正确设置:

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

在这里,我禁用了主要的 CapsLock,因此它开始发出 66 个键码,然后我将其与其他键的组合绑定到相应的键盘布局。

此外,xkb_options 设置为将 RightAlt 绑定为 uaruus 上的 compose 键以及lv3 pl 布局上的符号访问键。

CapsLock 功能仍然可以通过 shift:both_capslock 选项访问。