One thing I really don't like about how the universe works is how becoming frustrated with trying to do something seems to be the only way an open mind can conspire to learn something new and do something useful.
Today, that frustration was the inability to type in lat-long coordinates in Google Maps. I type a location that should be in Illinois, and Google thinks I mean a street in Cancun. Google is perfectly happy with signed-decimal coordinates (positive degrees for North latitude and East longitude, negative degrees for South latitude and West longitude), but it hasn't got a clue about coordinates entered in degrees-minutes-seconds (D-M-S) unless the Unicode degree sign is used, along with the ASCII single- and double-quotes for minutes and seconds. The main problem with entering a degree sign is that, on American keyboards, it's extremely inconvenient and unintuitive at best.
In Linux, or at least in X11, any Unicode character can be entered by typing Control+Shift+u, the Unicode character's hexadecimal value (267b for the black generic recycle symbol ♻, for example), and a space. But that doesn't help because I'd still have to memorize more hex values.
The trick, I learned, is to enable the Compose key on my keyboard. Most how-tos for it use the right Windows key as the compose key, but most laptops don't have two Windows keys. (Some don't even have the one Windows key in the main typewriter keypad.) The best substitution is the right Alt key, often used as the AltGr key.
One how-to says that /etc/X11/xorg.conf should be edited, but that's outdated. Debian has split xorg.conf into multiple dot-conf files under /usr/share/X11/xorg.conf.d/, and Ubuntu uses HAL and /etc/defaults/console-setup to configure the keyboard in X11. Nevertheless, it can be done.
The secret is to enable the XKB option "compose:ralt" (use the right Alt key as the Compose key).
First was to try it out and make sure it did what I wanted:
- setxkbmap -model pc105 -layout us -variant dvorak-classic -option compose:ralt
- This is specific to my setup: I touch-type Dvorak, and I prefer the classic layout which rearranges the number keys as well. I copied all but the -option from my keyboard configuration in /etc/defaults/console-setup.
- For people who expect the standard QWERTY layout on a PC, the command would be: setxkbmap -model pc104 -layout us -option compose:ralt
I was then able to type a degree sign by pressing Compose+o, o. That makes loads more sense, and I could still type as normal. Next was to make the change permanent.
If you use KDE or GNOME (the two major Linux desktop environments), there should be a regional/language settings section in the control center or desktop configuration tool. Under that is keyboard settings, and under that is XKB options, and theoretically under that is Compose key position. (Both major desktops are resource hogs that get in my way, so this wasn't an option for me.)
If you use /etc/X11/xorg.conf or if you have a keyboard section in one of the /usr/share/X11/xorg.conf.d/*.conf files, then you can edit the option in. As a sample I found elsewhere, with the relevant line boldfaced:
- # Your section in xorg.conf about the keyboard looks similar to this:
- Section "InputDevice"
- Identifier "Keyboard0"
- Driver "kbd"
- Option "XkbModel" "pc104"
- Option "XkbLayout" "us"
- Option "XkbOptions" "compose:ralt"
You have to do this as root, because regular users can't change this file. Look up the su, sudo, gksu, and kdesu commands. On some systems, you have to log in as root and give root's password, but on others root is disabled, so you have to be a sudoer and give your own password instead.
Anyway, this wasn't relevant in my case because the whole keyboard section of my xorg.conf was commented out during my last upgrade. The comments said:
- # commented out by update-manager, HAL is now used and auto-detects devices
- # Keyboard settings are now read from /etc/default/console-setup
I do have to give props for at least being commented in a useful manner, but the whole reason I wrote this entry is because I didn't find it elsewhere on the 'Net. So here it is; we come to it at last.
- Type cookie you idiot.
In the file /etc/defaults/console-setup (which can only be edited by root), I have this block of text:
- # The following variables describe your keyboard and can have the same
- # values as the XkbModel, XkbLayout, XkbVariant and XkbOptions options
- # in /etc/X11/xorg.conf.
- (This is because, again, I touch-type Dvorak. I don't expect many folks would have this.)
This change doesn't take effect until restarting X (logging out and back in), but at last, it's easy to type the most common special characters.
I hope one of you out there in Internet land finds this useful.