2020-12-07

Multiple Keyboards with Different Layouts

linux   keyboard   index

I need to type in multiple languages, each having a different script. So, I have shortcuts set up to change the layout using setxkbmap.

# setxkbmap [ layout [ variant ] ]
setxkbmap us altgr-intl
setxkbmap am western
...

But, sometimes, every other word is in a different language, so it is very cumbersome to switch layouts back and forth for every word.

Turns out, it is possible to add a second keyboard, and assign a persistent layout to it. We simply need to apply setxkbmap on a specific device id.

my second keyboard - Armenian Phonetic layout

my second keyboard - Armenian Phonetic layout

First we need to get the device ID of the second keyboard, which we can do with xinput.

Sometimes, the same keyboard appears multiple times. I couldn’t find a better way, other than trial and error with every device id.

Now, we can set the global layout, and then set an alternative layout for the second keyboard.

# each keyboard gets a different layout
setxkbmap us altgr-intl
setxkbmap am western -device 17

Thankfully, the device id appears to persist through reboots, and stays the same.