IBus: Bind Keyboard Layout To Engine

Posted on:

I’ve been using ibus under Linux for about 6 months now. The everyday languages that I use are English, German, and Chinese. There’s a slight problem with rime, the Chinese input engine I’ve been using. When I switch to it, it doesn’t change the keyboard layout. I’m used to type Pinyin with the US QWERTY layout, which I thought should be the default option for this language(spoiler, it’s not). It’s pretty annoying when I type “y” it came out as “z”(German layout) and I have to delete everything, switch to English, then switch back to rime to get the correct input. It turns out that you can fix this with a one-line configuration change.

tldr

Change $.component.engines.engine[0].layout in /usr/share/ibus/component/rime.xml to us or the layout that you’re used to.

<?xml version="1.0" encoding="utf-8"?>
<!-- filename: rime.xml -->
<component>
        <name>im.rime.Rime</name>
        <description>Rime Component</description>
        <exec>/usr/lib/ibus-rime/ibus-engine-rime --ibus</exec>
        <version>1.0</version>
        <author>GONG Chen &lt;chen.sst@gmail.com&gt;</author>
        <license>GPL</license>
        <homepage>https://rime.im</homepage>
        <textdomain>ibus-rime</textdomain>
        <engines>
                <engine>
                        <name>rime</name>
                        <language>zh</language>
                        <license>GPL</license>
                        <author>GONG Chen &lt;chen.sst@gmail.com&gt;</author>
                        <icon>/usr/share/ibus-rime/icons/rime.png</icon>
                        <!-- Previously "default" -->
                        <layout>us</layout>
                        <longname>Rime</longname>
                        <description>Rime Input Method Engine</description>
                        <rank>0</rank>
                        <symbol>&#x37A2;</symbol>
                </engine>
        </engines>
</component>

Finding the layout name

IBus uses the kbd package to handle different key layouts. Use localectl list-keymaps to list all available keyboard layouts supported by your system.

localectl list-keymaps | grep -i us
amiga-us
atari-us
br-latin1-us
cz-us-qwertz
is-latin1-us
mac-us
sunt5-cz-us
sunt5-us-cz
us
us-acentos
us1

In terms of these names, I think they are confusing to say the least. Some of them are actually relics of time used by vintage computers(made by SUN, IBM etc.)

Resources

https://github.com/ibus/ibus/issues/2378#issuecomment-1031020813

https://github.com/rime/ibus-rime/issues/15#issuecomment-232886563

From the second issue, we can know the layout setting used to be set to us. But someone apparently uses US+Dvorak to type Chinese, so the developers changed it to default, which tells ibus to keep the keyboard layout when changing engines. Not saying that this is wrong, but how many people type Chinese or Pinyin with non-QWERTY layout anyway? Guess I’ll never know.