Correcting iBus/X-Windows compose key conflicts

Paul Cochrane šŸ‡ŖšŸ‡ŗ - May 29 - - Dev Community

Originally published on peateasea.de.

Did you know that iBus can cause the compose key to stop working in X-Windows on Linux? I didnā€™t either. The solution in my situation: if in doubt, leave it out.

Iā€™ve been using Unix and Linux systems since the mid to late 1990s. This is a long time and old habits die hard. Lots of old habits in the Unix world still work today and thus they still have value. As the saying goes, ā€œif it ainā€™t broke, donā€™t fix itā€. Unfortunately, sometimes things break and itā€™s hard to work out why they broke and thus how to fix them.

Today is one case in point. I wanted to create a Euro currency symbol in an email but the compose sequence Compose e = didnā€™t work1. ā€œHuh, thatā€™s weirdā€, I thought. I tried the sequence in a terminal, which had worked up until recently (unfortunately, I donā€™t know exactly when šŸ˜•). It didnā€™t work there either. Very weird. I noticed that when pressing the compose key, a strange symbol, in what looked like a small window, appeared in my terminal. ā€œHang on, whatā€™s that?ā€, I thought.

A couple of hours disappear, my browser history is much longer, and I still donā€™t have that email finished. But I now know what was causing the problem and I have a fix for it. Yay!

Whatā€™s the compose key?

Gollum saying:

But first: whatā€™s this compose key thing heā€™s talking about? This is one way to create characters which might not be available on your keyboard. Being someone from an English-speaking culture, when growing up I didnā€™t need umlauts or accents or Greek characters on my keyboard.2 There are, however, very many other characters one might wish to use. The people who construct computing systems worked out a long time ago (relatively speaking) that a standard keyboard had too few keys for all possible characters one might want to produce. They came up with an elegant solution to this problem: characters could be composed by using a special key in combination with the more basic characters available on a keyboard. This became known as the compose key3 and (at least until the late 90ā€™s and probably early 2000ā€™s) there was a special key on many keyboards specifically for this task.

These days people tend not to use DEC or Sun Microsystems desktop systems (which is where one would have seen such a key) and thus itā€™s not obvious that a compose key could exist let alone realise that there might be a need for one. Since my standard keyboard doesnā€™t have an explicit compose key, I mapped caps lock to compose, because after all, who needs caps lock, right?

It doesnā€™t work! What, exactly, doesnā€™t work?

So, back to the issue at hand: the compose key wasnā€™t working. But what does ā€œnot workingā€ mean in this case? Well, when I pressed the Compose e = key sequence the Euro currency symbol didnā€™t appear as expected. Instead, after pressing the compose key, a white box containing a little symbol appeared under the cursor:

Symbol appearing when compose key was pressed

The image shows my terminal prompt (which starts on the line below the username, hostname and path information that I display in my shell) and the cursor (the tall white box next to the -> arrow). Note that below the cursor, thereā€™s a wide white box, with a grey shaded area to the left and within the white area thereā€™s a symbol of some kind.4 Note how zoomed-in this image is. This is why it was very difficult to work out what the computer was trying to tell me and hence to work out what was going on. It seemed that this little pop-up box was stopping the compose sequence from getting to the shell and hence stopping the desired character from being displayed.5

This, I think, is the fundamental insight here: something was getting in the way and stopping the key presses from reaching the relevant (X-Windows) application. But what?

Trying to google for things like ā€œlittle pop-up window when pressing compose keyā€ led nowhere and served only to confuse me and make my browser history even longer.

ā€¦ I thought something might be wrong with my xmodmap settings. Nope.

ā€¦ I tried setting the XKBOPTIONS variable in/etc/default/keyboard and restarting X-Windows. Also nope.

ā€¦ I even tried using a different windows manager.6 šŸ˜±

ā€¦ I tried rebooting and ā€¦ hang on, what was that? As the windows manager was starting, I noticed a symbol appear in the taskbar that Iā€™d spotted before, but didnā€™t know what what it was. It looked a bit like a picture of a steam iron. It turns out it wasnā€™t a picture of an iron (and I never thought it was, but still). That idea came from either my bad eyesight, the small size of the icon, or my imagination (or a combination of all three). The icon was, in fact, a keyboard with a cable above and a small globe of the earth in the lower left-hand corner.

iBus initial icon in windows manager taskbar

Upon starting my first terminal session, this changed into just the two letters EN; this is because I use an English-based keyboard layout.7

iBus appearing as EN in windows manager taskbar

Iā€™d seen this appear a few times over the years but it never seemed to have had any impact on my ability to enter text into the console or any GUI applications, so I paid it no further attention. I also noticed that the icon would sometimes disappear after a while. You know how one can be too busy to investigate that random thing which appears on oneā€™s computer but later bites one on the proverbial posterior at some inopportune time? This was one of those times.8

Fortunately, this time, I decided I wanted to work out what this thing was and ended up right-clicking on the symbol, which greeted me with a context menu:

iBus context menu from windows manager taskbar

Clicking on the ā€œAboutā€ menu item showed this window

iBus

Aha! Now I know what this thing is and can now create a more sensible Google query.

Extending my browser history (and the number of open tabs) further, I learned that the icon belonged to iBus, the ā€œIntelligent Input Busā€. This is an

input method (IM) framework for multilingual input in Unix-like operating-systems.

In other words, one can use iBus to swap between, say, a German layout and an English layout.9 Since Iā€™d already integrated umlauts and the sharp S into my keyboard layout via xmodmap, I didnā€™t need a system to handle more layouts. I thus tried simply quitting iBus from the ā€œQuitā€ context menu item.

And then compose key sequences started working again! Yay!

Ok, now that I know how to solve the problem, how do I make sure that it doesnā€™t return?

Stomping on a bug

This wasnā€™t a bug in the sense that this was an error in code somewhere. It was, however, a behaviour that I didnā€™t want to have. Thus I could still use the same strategy as when confronted with a bug: after finding the root cause, ensure that the issue never resurfaces.

So whatā€™s the long-term solution in this case? More stumbling through information on the internet showed that

ibus is the default input method (IM) for GNOME desktop. It allows a user to enter characters of a different language. E.g. entering Chinese while your system generally uses a German keyboard layout.

and that

im-config will set up [the] required environment variable and also take care starting of daemon program.

The im-config program configures the input method,10 of which iBus is one possibility. One configures im-config via the /etc/default/im-config file. The first few lines of this file look like the following:

# Default im-config mode (see im-config(8))

# This im-config helps to start best available input method (IM)

# Always start highest priority IM
IM_CONFIG_DEFAULT_MODE=auto
# Start or not to start IM dynamically under CJKV/desktop environment
#IM_CONFIG_DEFAULT_MODE=cjkv
# Never start IM by im-config (Leave it to desktop system)
#IM_CONFIG_DEFAULT_MODE=none

<snip>
Enter fullscreen mode Exit fullscreen mode

Isnā€™t it wonderful to read such a well-documented configuration file? It makes life so much easier.

Anyway, we can see that, by default, the highest priority input manager (IM) is started automatically.

# Always start highest priority IM
IM_CONFIG_DEFAULT_MODE=auto
Enter fullscreen mode Exit fullscreen mode

Further down, we can see that if we want to ā€œLeave it to [the] desktop systemā€, we should change the IM_CONFIG_DEFAULT_MODE setting to none. Since we want to use the desktop system and not an intermediary, we comment out the line

IM_CONFIG_DEFAULT_MODE=auto
Enter fullscreen mode Exit fullscreen mode

so that it reads

# Always start highest priority IM
#IM_CONFIG_DEFAULT_MODE=auto
Enter fullscreen mode Exit fullscreen mode

and activate the line

#IM_CONFIG_DEFAULT_MODE=none
Enter fullscreen mode Exit fullscreen mode

(by removing the comment character) so that it reads like this:

# Never start IM by im-config (Leave it to desktop system)
IM_CONFIG_DEFAULT_MODE=none
Enter fullscreen mode Exit fullscreen mode

Saving the file and restarting X-Windows showed that iBus didnā€™t start, i.e. its icon doesnā€™t appear in the taskbar:

iBus deactivated after windows manager startup

Great! Problem solved! And I learned something!

Now I can close all of my browser tabs and finally finish writing that email. šŸ˜

  1. Compose = e also works. See https://github.com/kragen/xcompose for a good .XCompose configuration. ā†©

  2. And the Euro hadnā€™t been invented yet! Yes, fellow kids, Iā€™m getting long in the tooth. ā†©

  3. Also known as the Multi-Key. ā†©

  4. It turns out that the symbol is the ISO composition symbol. I only worked this out much later though, basically because the symbol was so small when displayed on my screen. ā†©

  5. My guess is that this is also why my email program wasnā€™t printing the Euro symbol: something was getting in the way of the compose sequence getting through to the email program. ā†©

  6. My windows manager is awesome. No really, I mean it, itā€™s awesome. ā†©

  7. I use an English layout on a German keyboard. I tend to confuse people who want to use my computer. ā†©

  8. Perhaps my general disdain for ironing clothes had held me back from investigating what this icon was sooner. ā†©

  9. The common iBus use case is to allow Japanese, Chinese and Korean (CJK) languages to enter non-ASCII native characters. ā†©

  10. Thatā€™s the ā€œimā€ in im-config. ā†©

. . . . . . . . . . . . . .