Xorg: Using the US International (altgr-intl variant) Keyboard Layout

TL;DR: If you want to sanely type French, German, Spanish, or other European languages on a standard US keyboard (101 or 104 keys), your only real option is the us layout with the (relatively new) altgr-intl variant.

I like to type in French and German sometimes because I study these languages for fun. For some time, I had used the fr and de X keyboard layouts to input special characters from these languages. However, it wasn’t until recently that I realized how most European layouts, such as fr and de, require that you have a 105-key keyboard. A 105-key keyboard looks exactly like the standard, full-sized IBM-style 104-key keyboard (i.e., IBM Model “M” 101-key keyboard plus 2 Windows keys and 1 “Menu entry” key on the bottom row), except that it has 1 more extra key on the row where the Shift keys are (and also has a “tall” Enter key with some of the existing keys on the right side rearranged a bit).

I personally use a 104-key keyboard (a Unicomp Space Saver 104, because that’s how I roll). Now, when I switched to the fr layout the other day, I wanted to type the word âme. Unfortunately, the circumflex dead key was not where it was supposed to be. This was because I only had 104 keys instead of 105, and during the process of switching forcibly to the fr layout, there was a malfunction in the conversion (rightfully so).

Now, the choice was to either buy a 105-key keyboard or just find an alternative 104-key layout that had dead keys. I didn’t want to buy a new 105-key keyboard because (1) the extra 1 key results in a squished, “square” looking left-Shift key and (2) the tall Enter key would make it more difficult for me to keep my fingers happy on the home row, since I’d have to stretch my pinky quite a bit to reach it, and (3) I just didn’t feel like spending another ~$100 for a keyboard (my Unicomp is still in excellent condition!).

So, I had to find a new keyboard layout that could process accented/non-English Latin characters better. The Canadian Multilingual Standard keyboard layout (http://en.wikipedia.org/wiki/Keyboard_layout#Canadian_Multilingual_Standard) looked very, very cool, but it was only for a 105-key keyboard. I then discovered a layout called the US International Standard keyboard layout, which enables you to type all the cool accented letters from French or German (and other European languages) while still retaining a QWERTY, 101/104 key design. This sounded great, until I realized that the tilde (~), backtick (`), single quote (‘) and other keys were dead keys. I.e., to type ‘~’ in this layout, you have to type ‘~’ followed by a space. This is horrible for programmers in Linux because the ~ key comes up everywhere (it’s a shell shortcut for the $HOME directory). To type a single quote character, you have to type (‘) followed by a space! Ugh. I’m sorry, but whoever designed this layout was obviously a European non-programmer who wanted to type English easier.

But then, all hope was not lost. When browsing all of the choices for the us keyboard layout variant under X (/usr/share/X11/xkb/rules/base.lst), I found a curious variant called altgr-intl. A quick google search turned up this page, an email from the creator of this layout to the X developers: http://lists.x.org/archives/xorg/2007-July/026534.html. Here was a person whose desired usage fit perfectly with my own needs! Here’s a quote:

I regularly write four languages (Dutch, English, French and German)
on a US keyboard (Model M – © IBM 1984).

I dislike the International keyboard layout. Why do I have to press
two keys for a single quote (‘ followed the spacebar) just because the
‘ key is a dead-key that enables me to type an eacute (é)?

I decided to ‘hide’ the dead-keys behind AltGr (the right Alt key).
AltGr+’ followed by e gives me eacute (é). It also gives me
m² (AltGr+2).

Excellent! Apparently, this layout was so useful that it became included eventually into the upstream X codebase, as the altgr-intl variant for the standard us (QWERTY) keyboard layout. The most compelling feature of this layout is that all of the non-US keys are all hidden behind a single key: the right Alt key. If you don’t use the right Alt key, this layout behaves exactly the same as the regular plain us layout. How cool is that?! And what’s more, this layout makes it compatible with the standard 101-key or 104-key IBM-styled keyboards!

This variant deserves much more attention. Unfortunately, there seems to be little or no information about it other than the above-quoted email message. Also, I’ve noticed that it is capable of generating Norse characters as well, like þ and ø. There does not seem to be a simple keyboard layout picture on the internet to show all the keys. Anyway, I’ve been using it recently and it really does work great. There is no need for me to switch between the us, fr, and de layouts to get what I want. I just use this layout and that’s it. Take that, Canadian Multilingual Standard!

Here’s how to set it up: use either the setxkbmap program like this:

setxkbmap -rules evdev -model evdev -layout us -variant altgr-intl

in a script called by ~/.xinitrc, or use it directly in your keyboard xorg settings:

Section "InputClass"
    Identifier "Keyboard Defaults"
    MatchIsKeyboard "yes"
    Option  "XkbLayout" "us"
    Option  "XkbVariant" "altgr-intl"
EndSection

I personally prefer the script method because you can tweak it easily and reload it without restarting X. For me, I had to use the -rules evdev -model evdev options because -model pc104 would mess things up (probably due to an interaction with xmodmap and such in my ~/.xinitrc). Whatever you do, make sure everything works by testing out the AltGr (right Alt) key. For example, AltGr+a should result in ‘á’.

A couple caveats: Some keys like â and è (which are AltGr+6+a and AltGr+`+e (i.e., uses dead keys)) do not show up at all on urxvt. I’m guessing that the dead keys are broken for urxvt (or maybe it’s a bug with this layout; who knows). Luckily, I can just use a non-console app (like GVIM) to do my Euro-language typing, so it’s OK (although, eventually, I’ll run into this bug again when I start typing French emails from within mutt inside urxvt 20 years later… but by then it will be fixed, I’m sure.) Also, the nifty xkbprint utility can generate nice pictures of keyboard layouts (just do a google image search on it), but it’s currently missing (https://bugs.archlinux.org/task/17541) from Arch Linux’s xorg-xkb-utils package. So, if you’re on Arch, you’ll have to experiment a bit to figure out the various AltGr+, and AltGr+Shift+ key combinations.

See also: Xorg: Switching Keyboard Layouts Consistenly and Reliably from Userspace

UPDATES:

  • October 30, 2011: I just found out that the dead keys bug in urxvt is actually a bug in ibus/SCIM (I use ibus, which relies on SCIM, to enter Japanese/Korean characters when I need to). I tried out uim, which is a bit more complicated (much less user friendly, although there are no technical defects, from what I can tell), and with uim, the dead keys work properly in urxvt. The actual bug report for ibus is here.
    So, use uim if you want to use the altgr-intl layout flawlessly, while still retaining CJK input functionality. Of course, if you never needed CJK input methods in the first place, this paragraph shouldn’t concern you at all.
  • December 7, 2011: Fix typo.
  • January 24, 2012: Fix grammar.

Linux Mint Elyssa – How to Enable Korean + Japanese + French and German (Updated for Arch Linux)

Please see my latest update on May 13, 2011, below!

I like foreign languages. They are always entertaining, and remind me to respect those who have a hard time learning English as a second language. Since some people are stumbling onto this blog in search of a way to enable Japanese support in Mint, I will write down how I set it up to work on both my laptop and desktop (even though I did mention my setup very briefly in one of my earlier posts). By the way, this guide is 100% compatible with Daryna and not just Elyssa. This means you Ubuntu Gutsy and Hardy people should listen up as well.

First, how to install Japanese/Korean/Chinese support:

  • Get “scim-bridge” from the repositories/Synaptic if you don’t have it already.
  • Open up /etc/X11/xinit/xinput.d/scim with root access with any text editor. E.g., something like this: gksudo gedit /etc/X11/xinit/xinput.d/scim.
  • Make the file look like this (the lines that start with # are all “comments” and do not affect anything at all):
XIM=SCIM
XIM_PROGRAM=/usr/bin/scim
XIM_ARGS="-d"
XIM_PROGRAM_SETS_ITSELF_AS_DAEMON=yes
GTK_IM_MODULE="scim-bridge"
QT_IM_MODULE="scim-bridge"
DEPENDS="scim,scim-anthy|scim-canna|scim-chewing|scim-pinyin|scim-hangle|scim-prime|scim-skk|scim-tables-additional|scim-m17n|scim-uim|scim-tables-ja|scim-tables-ko|scim-tables-zh"
  • Now, keep these values for these variables in mind. You can open up a blank gedit document and copy/paste the stuff above into it for reference, because you’ll need it for the following step.
  • Make /etc/X11/xinput.d/none and /etc/X11/xinput.d/default the same as the file we just edited. But, for extra safety, only copy/paste over the values for the variables that are in the /etc/X11/xinput.d/scim file (the ones shown up above in code font). There are other variables with values (or no values) in the none and default files that you do not need to touch, so leave these as is.
  • Now, restart X. (X is the graphical window manager for Linux. It runs everything you see, and it also handles fonts and such, so you need to restart. Either log out and log back in (shortcut key for this is CTRL + ALT + BACKSPACE) or just reboot if you really feel like it.
  • Now, there should be a little keyboard icon on the system tray/Panel. Right-click on it, and click on SCIM Setup.
  • For FrontEnd -> Global Setup, choose English as your default keyboard layout.
  • Update the hotkeys for FrontEnd -> Global Setup -> Hotkeys -> Next input method. The default hotkeys are a bit annoying for me. I like to set up a custom hotkey that is Control+Control_R+KeyRelease; so, when I press both CTRL keys, and then release the Right CTRL key, the input method changes to Japanese. If I do it again, the input method changes to Korean. Doing it again takes me back to my default English layout.
  • In IMEngine -> Global Setup, uncheck the Other boxes. You don’t need these (uncheck both the English/European box and the RAW CODE box) as they are clutter and get cycled into your custom hotkey you set up above.
  • Right-click on the keyboard in the system tray/Panel again, and this time, click on Reload Configuration. (I think you might have been prompted earlier when you made the changes I described above; but do it again just for good measure.)
  • Again, restart X.
  • Done! Now, you have a global hotkey of Control+Control_R+KeyRelease that works in ANY program — gedit, Firefox, and even the terminal!!! (The keyboard icon in the system tray will update whenever you press the hotkey to reflect your current selection.) Control+Spacebar switches between your Japanese or Korean input back to your English layout. (NOTE: If you never saw any keyboard icon in your system tray, then this is because you don’t have the Notification Area item added to your Panel. Do so, and it will show up.)

For French and German:

  • In Start -> Preferences -> Keyboard, click on the Layouts tab and click on Add. Add the French layout and German layout, both with their default variants (unless you want Dvorak or something).
  • In the same tab, click on the Layout Options button. Click on Layout switching, which should be bolded by default on Elyssa/Daryna. Now, for some reason, the default hotkey does not work for me on my basic QWERTY keyboard (no success on my laptop’s keyboard, either). Also, as much as I like the Both Alt keys together change layout option, it doesn’t work for me. But this one does: Right Win-key changes layout. So click this one. Try other ones if you really hate using the right windows key.
  • Right-click on your Panel, and click Add to Panel. Click on the Keyboard Indicator item and add it.
  • Restart X? I don’t remember. But it should be working right away, if I recall correctly. Notice how each time you press the hotkey, the indicator changes from “USA” to “Fra” to “Deu” and back again. Neat!

I hope you find these things useful. がんばって!

UPDATE July 12, 2008: For some reason, the Layout switching options for switching between English, French, and German input as described above does not work properly. It only works right after you set the shortcut key. After a reboot, it will not work. I think this is a bug, but it may be just my system.

UPDATE July 25, 2008: The Layout switching option not working is a bug present in Ubuntu Hardy. Details here.

UPDATE September 24, 2008: In Xubuntu 8.04.1, you can at least get the Keyboard Layout Switcher (an item that you can add to the Panel) to work properly by going into /etc/X11/xorg.conf, and adding the names of the layouts for the “XkbLayout” option, as well as updating the settings ins Keyboard Preferences to reflect whatever is defined for “XkbLayout”. So, for me, this setting was set to simply “us” before, for US English. I changed it to look like “us,fr,de”; then, I went into Menu -> Settings -> Settings Manager -> Keyboard -> Layouts, and added the proper US, FR, and DE layouts, in that order (although I doubt this proper order is necessary). Then, I also unchecked the “Use X configuration” setting as well in the same dialog box (I know, this is odd, considering how we want the changes reflected in xorg.conf to take effect). Now, after these two changes, the Keyboard Layout Switcher works correctly, even after a reboot. FYI, in the Keyboard Preferences dialog box mentioned above, I use the olpc2, oss_nodeadkeys, and nodeadkeys variants for the us, fr, and de layouts, respectively, and my keyboard model is Generic 105-key (Intl) PC.

Unfortunately, making it switch layouts via a keyboard hotkey, à la SCIM, is beyond me. Clicking on the flag icon in my Panel will do for now.

Also, as for the Korean + Japanese, as of Xubuntu 8.04.1, you’ll have to install the scim-hangul and anthy and scim-anthy packages to get the two languages to show up in your SCIM setup dialog box (my apologies for not mentioning this if this was also the case before).

UPDATE February 22, 2009 (on Arch Linux): I don’t use Xubuntu anymore — I use Arch Linux + Xmonad (no XFCE, no KDE, no Gnome, just Xmonad). From my experience on 2 installations of Arch (one on my desktop and one on my laptop), the layout switching between us, fr, and de all work with the following xorg.conf:

Section "InputDevice"
    Identifier     "Keyboard0"
    Driver         "kbd"
    Option "XkbModel" "pc104"
    Option "XkbLayout" "us,fr,de"
    Option "XkbOptions" "grp:rctrl_toggle"
EndSection

That’s right — you can get layout switching functionality with just a couple lines in your xorg.conf file. The only quirk is that when I do press the right CTRL key to toggle between us, fr, and de layouts, the “us” layout is actually in there twice — i.e., I have to press the right CTRL key two times to switch from us to fr. (This quirk has been fixed now — see update on June 16, 2010 below.) But cycling between all of these layouts work all the time, and consistently, even after reboot! It’s just one more reason to switch to Arch Linux. BTW, scim works perfectly fine in Arch Linux — just put the following in your ~/.xinitrc file, BEFORE “exec xmonad” if you’re using Xmonad:

export XMODIFIERS=@im=SCIM
export GTK_IM_MODULE="scim"
export QT_IM_MODULE="scim"
scim -d

Just follow the Arch wiki on SCIM for more details. Press CTRL+Space to bring up the scim pop-up window (assuming you’ve installed at least one input method, like scim-anthy or scim=hangul), and from there you can right-click on it to bring up the scim configuration window, for all your tweaking/hotkey customizations.

UPDATE March 26, 2009: You might want to be interested in this post I just wrote as well, for displaying good-looking Korean and Japanese fonts in your terminal/console.

UPDATE June 16, 2010: The quirky behavior of the layout “us” being there twice is now gone — I think the latest xorg updates (1.7 series, probably) have fixed that bug.

UPDATE May 13, 2011: I now use the setxkbmap program to do all my layout switching. As for Korean/Japanese input, I use ibus (SCIM is supposedly not maintained anymore).

UPDATE August 24, 2011: I don’t use multiple xorg keyboard layouts any more; see this post.