First, it turns out that Logitech keyboards don't all assign the same key code to keys with the same icon on the keyboard; that is, a key with a picture of a home (i.e. your browser's home page) might be scancode 178 on one keyboard (this guy's, for example) but is scancode 130 on my keyboard. The only reason I can imagine that Logitech would do this is to drive people crazy and make them reliant on the Logitech software. Luckily the X.org folks have made lists of known keyboard layouts and put them into a configuration program so you can just pick your layout. Unfortunately for me, my layout wasn't listed so I had to pick a few different Logitech keyboard layouts until I found one that matched mine. I chose the layout from KDE's control center, which you can see in the screenshot below.

In order to fix the bug I had to edit the /usr/share/X11/xkb/symbols/inet file. In this file was a layout definition that is used as the base definition for Logitech keyboards. I snipped out the boring parts, here are the three lines that were wrong:
xkb_symbols "logitech_base" {
key <i21> { [ XF86VendorHome ] };
key <i2f> { [ XF86AudioRaiseVolume ] };
key <i30> { [ XF86AudioRaiseVolume ] };
};
key <i21> { [ XF86VendorHome ] };
key <i2f> { [ XF86AudioRaiseVolume ] };
key <i30> { [ XF86AudioRaiseVolume ] };
};
I made a new definition, with a new name, that contains keycodes for the 8 extra keys on this keyboard:
xkb_symbols "logitech_350" {
key <i01> { [ XF86AudioMedia ] };
key <i02> { [ XF86WWW ] };
key <i20> { [ XF86AudioMute ] };
key <i21> { [ XF86Calculator ] };
key <i22> { [ XF86AudioPlay, XF86AudioPause ] };
key <i2e> { [ XF86AudioLowerVolume ] };
key <i30> { [ XF86AudioRaiseVolume ] };
key <i32> { [ XF86HomePage ] };
key <i6c> { [ XF86Mail ] };
key <i6d> { [ XF86AudioMedia ] };
};
key <i01> { [ XF86AudioMedia ] };
key <i02> { [ XF86WWW ] };
key <i20> { [ XF86AudioMute ] };
key <i21> { [ XF86Calculator ] };
key <i22> { [ XF86AudioPlay, XF86AudioPause ] };
key <i2e> { [ XF86AudioLowerVolume ] };
key <i30> { [ XF86AudioRaiseVolume ] };
key <i32> { [ XF86HomePage ] };
key <i6c> { [ XF86Mail ] };
key <i6d> { [ XF86AudioMedia ] };
};
The reason I made a new definition was to make sure I didn't break anything else. Since I'm not 100% sure how to create a whole new definition from scratch, I just modified the Logitech Ultrix definition, which was just an import of the base definition:
Old:
partial alphanumeric_keys
xkb_symbols "logiultrax" {
include "inet(logitech_base)"
};
xkb_symbols "logiultrax" {
include "inet(logitech_base)"
};
New:
partial alphanumeric_keys
xkb_symbols "logiultrax" {
include "inet(logitech_350)"
};
xkb_symbols "logiultrax" {
include "inet(logitech_350)"
};
This was quick and easy. Once I made the change to this file I simply logged out, logged back in, and the new keys worked as advertised.
Making something interesting happen when the keys were pressed was trivial once the bindings worked. To control the sound volume I set the key bindings in KMix, KDE's volume applet. To launch programs when I press the application starters I used the KDE control center's keyboard shortcuts page; just pick an action or program and assign any key combination to it. In the screenshot you can see Firefox and KMail have their special keys mapped.

No comments:
Post a Comment