My current keyboard config is quite complex, but the relevant line is:

setxkbmap -option -option 'grp:rshift_toggle, compose:rctrl' dmru,ru,ua &  

Rshift now cycles through dmru, ru, and ua. When my screen gets locked, I have no way of knowing which layout am I using to type my password, and in general it would be awesome to have a shortcut which takes me back to english. (dmru in this case, it's a custom layout.) I can't run setxkbmap $language at every switch because it breaks my xcape and xmodmap settings; running them every time takes a couple of seconds and is not practical.

Would it be possible to switch to a particular language, without running setxkbmap every time?


The group-switch options operate with 4 keysyms: ISO_First_Group, ISO_Last_Group, ISO_Next_Group, and ISO_Prev_Group. The option you use, grp:rshift_toggle, only provides ISO_Next_Group, so cycling through the layouts is all you're seeing.

The behavior you're looking for (select a specific layout) exists on the ISO_First_Group or ISO_Last_Group keysyms. You want to find an existing (or write a new) option that supplies at least one of those keysyms.

Looking quickly through man xkeyboard-config, these existing options appear to include ISO_First_Group:

  • grp:shift_caps_switch: Caps Lock to first layout; Shift+Caps Lock to last layout
  • grp:win_menu_switch: Left Win to first layout; Right Win/Menu to last layout
  • grp:lctrl_rctrl_switch: Left Ctrl to first layout; Right Ctrl to last layout
  • grp:lctrl_lwin_rctrl_menu: Left Ctrl+Left Win to first layout; Right Ctrl+Menu to second layout

These options are defined in /usr/share/X11/xkb/symbols/group. One of them may be acceptable for your use. If they don't provide exactly what you want, you can use the definitions to tailor your keymap to your needs.

| improve this answer | |
  • Thank you, this is exactly what I was looking for! I didn't know similar options can be combined, two group-switches in my case. – pchr8 Jun 17 '18 at 8:45
  • you do have to watch out for conflicts with other options -- the grp:lctrl_rctrl_switch option would conflict with your compose:rctrl option, and whichever you applied last would overwrite the other. – quixotic Jun 17 '18 at 21:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.