How to put some keyboard layout aside from layout switching ring

gnomekeyboard-layoutxkbxorg

What I need is to

  1. switch between Russian and English layout with my favorite shortcut (namely Shift-CapsLock)
  2. switch to Belarusian layout with another shortcut (say, Ctrl-RightShift, but actual binding doesn't matter)
  3. while Belarusian layout is active, switch back to Russian/English with Shift-CapsLock

Is it possible with xkb at all? If so, how can this be done?

Best Answer

Three useful commands:

1. Get the current keyboard layout, from this topic :

setxkbmap -print | grep xkb_symbols | awk -F"+" '{print $2}'

Returns layout(variant) where variant is optional

2. Know if the current keyboard layout is layout(variant):

 setxkbmap -print | grep "layout(variant)"

Or without "(variant)".

Returns nothing is not.

3. Set the keyboard layout to a specified value:

setxkbmap layout variant

Where variant is optional.

(see man setxkbmap for more informations)

What you can do:

1. Create a simple executable (chmod +x file) script that changes the keyboard layout on the fly, depending on the current one. For instance, if we deal with the first point:

#!/bin/bash

if setxkbmap -print | grep "us"
then
  setxkbmap ru
else
  setxkbmap us
fi

2. With your keyboard shortcuts manager, assign the Shift-CapsLock keys to this script.

Good luck!

Related Question