February 12, 2005

Xkeyboard and Gnome 2.6

Turns out Gnome 2.6 uses the Xkeyboard extension. In the end, this is good thing, but until I figured that out, I was going nuts.

I wanted to run a script when I pressed the "Mute" key on my HP zt3000 notebook. I had used gnome's "Keyboard Shortcuts" GUI to associate actions like "Raise the volume" and "Lower the volume" with the correct multimedia keys, but the "Mute the volume" action wasn't muting the right ALSA channel. My HP has some nice hardware tie-ins when you mute the special channel "External Amplifier". The ti-ins don't work when you mute "Master". So naturally, I wanted to write a mute toggle script myself and have gnome use my script instead of gnome's built-in muting feature.

I found a great article about associating arbitrary commands with hotkeys in Gnome. Hint: It requires setting property values directly using the "Configuration Editor" (a.k.a. gconf). Yeah, that's real user friendly. (Not that I'm saying gconf is bad. I agree with this article, gconf is a good thing.)

Turns out the "multimedia" keys have non-standard key codes, so their symbolic names ("XF86AudioRaiseVolume", "XF86AudioMute", etc) they aren't defined for standard PC keyboard configurations. For some reason, the "Keyboard Shortcuts" GUI was allowing me to use the hex value of the key code without the need for a symbolic name, BUT I could not use the hex value when editing the configuration directly with gconf. Yeah, go figure. Who know's what black magic goes on behind the scenes in gnome. (Yeah, yeah, yeah..."read the source, Luke.")

I searched online to figure out how I could define my key mappings. I was told to use "xmodmap" to associate symbolic names with particular key codes. No sweat. I simply did "xmodmap -pke > .Xmodmap" to get a list of all the keycodes that are defined. I then used "xev" to figure out which keys generated which key codes, and edited ".Xmodmap" to associate the right symbolic names with the key codes. (Search for "xmodmap" on Google for more info.) I then installed the new definitions by hand doing "xmodmap .Xmodmap". This worked great, until I logged out and logged back in.

According to the "way things should be", the definitions in ".Xmodmap" should be loaded automatically. But no, that wasn't working. So, I tried forcing them to load in my ".xprofile". Nope, that didn't work either. I tried having gnome automatically run "xmodmap ~/.Xmodmap" when gnome is starting my session. That didn't work either. Basically, the only thing that worked was loading my custom definitions from a terminal, by hand, after gnome had started. Clearly, that wasn't acceptible.

By this time I got smart enough to search for "xmodmap gnome 2.6" on Google and I discovered that gnome 2.6 use the "new way": the Xkeyboard extension. The Xkeyboard extension supports all sorts of keyboards including so-called "multimedia" and "Internet" keyboards. I grepped around and found the definition for these keyboards is in "/etc/X11/xkb/symbols/inet". And after looking to in "/etc/X11/xkb/keycodes/xfree86" to see the translation between the key code (ex. "160") and the new strange notation (ex. ""), I was able to find the "zt11xx" profile in the "inet" set that had all the keys I needed defined for the right key codes. Horray!

I used gnome's "Keyboard Preferences" GUI to set "HP Pavillion ZT11xx" as my keyboard. (Yes, I own a zt3000, not a zt11xx. I guess HP is somewhat consistent between models.) After logging out and back in, I was able to use gconf to associate my mute key with the "toggle_mute" script I wrote. Horray!

In summary, it was WAY TOO DIFFICULT to associate a command with a multimedia key. This was due to a few things: intentionally hiding features, inconsistency (sometimes hex, sometimes not), and outdated information.

Maybe there should be some sort of "keyboard finder" where you select the special function (such as mute) from a list and press the key on the keyboard. After you do that for all the keys you care about, the "keyboard finder" determines the predefined keymap that fits, and if one doesn't exist, it makes a custom one.

If I only had time to code....

Posted by enigma at February 12, 2005 01:16 PM
Comments
Post a comment









Remember personal info?




Type in the security code: