Xkb: how toggle keyboard layout with win + capslock

keyboard shortcutskeyboard-layoutxkb

I want to set custom shortcut to change keyboard layout using setxkbmap. For example win_caps (Win+CapsLock). This option is not listed in /usr/share/X11/xkb/rules/base.lst

How can I achieve this?

Best Answer

You'll have to define a custom option e.g. win_caps_toggle.
Add the following definition to your /usr/share/X11/xkb/symbols/group:

// toggle using win + capslock as combo
partial modifier_keys
xkb_symbols "win_caps_toggle" {
    key <CAPS> {
        type[Group1]="PC_SUPER_LEVEL2",
        symbols[Group1] = [ Caps_Lock, ISO_Next_Group ]
    };
};

and the following description to your usr/share/X11/xkb/rules/evdev.lst:

grp:win_caps_toggle Win+Caps Lock

anywhere under the grp section (e.g. under grp:caps_toggle).
You can then run

setxkbmap -option grp:win_caps_toggle

to set Win+CapsLock as the shortcut that changes the keyboard layout.


Note: this solution doesn't work with gnome 3. I think in order to make it work some stuff has to be disabled in gnome; I've tried disabling gnome-settings-daemon keyboard plugin and mutter overview key but no go. Works fine with other DE's though.