For whatever reason, I have to adjust the PCM track in order to change volume in GNOME; the Master track does nothing. I suspect it's something specific to my sound card. It isn't especially inconvenient as long as I want to use the volume control built into the GNOME panel. I just right-clicked on the speaker icon, selected Preferences and told it to control the PCM track. Unfortunately adjusting the volume using multimedia keys has proven more difficult.
GNOME 2 provides a utility to bind an action to a key or keys. It can be accessed from the terminal with the command gnome-keybinding-properties or from the GNOME Desktop (System -> Preferences -> Keyboard Shortcuts). However, if you want to perform an unlisted action, you'll have to use the Configuration Editor. In my case, I wanted to adjust the PCM track volume.
The GNOME Configuration Editor can run from the terminal with the command gconf-editor or from the GNOME Desktop (Applications -> System Tools -> Configuration Editor). I used it to set key bindings for Metacity.
Using Xev and Editing Xmodmap
Before I could begin I needed to know if the keys to which I wanted to bind actions already had keysyms—symbolic names for keys on the keyboard—assigned to them. I opened the terminal and entered xev.
Xev prints the contents of X events. According to its manual, "Xev creates a window and then asks the X server to send it events whenever anything happens to the window…" This includes typing. So pressing a multimedia key should return something like this.
KeyPress event, serial 29, synthetic NO, window 0x3000001,
root 0x8e, subw 0x0, time 412303, (-458,206), root:(527,303),
state 0x10, keycode 160 (keysym 0x0, NoSymbol), same_screen YES,
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False
We're interested in the third line. "NoSymbol" indicates that there isn't a keysym assigned to keycode 160. Therefore I had to add them to my X keyboard map. First I exported the existing map to a file in my home directory (/home/josh on my system).
xmodmap -pke > xmodmap.conf
I added the missing keysyms for the corresponding keycodes. There's a specific set of names you must use, listed in /usr/lib/X11/XKeysymDB. I saved and closed the file. Then I applied the changes.
At this point, you could actually read ahead and bind actions to the keysyms to see if they work. Of course, the new keyboard map isn't just for this session. We want to load it when X starts. Following the advice of Corey Burger, I added it to the PostLogin script of gdm.
sudo cp xmodmap.conf /etc/xmodmap.conf
sudo cp Default.sample Default
sudo gedit Default
We need to add the line xmodmap /etc/xmodmap.conf to the end of the file. Now we're ready to use the Configuration Editor.
GNOME Configuration Editor
Run the Configuration Editor and navigate to /apps/metacity/global_keybindings. There should be 12 keys with "run_command" in their names. Right-click on any of them and select "Edit Key…" from the popup menu. Enter the keysym of the desired multimedia key in the "Value" field. Repeat these steps for each multimedia key you want to use. Next we'll tell Metacity which command to run when these keys are pressed.
The ALSA mixer can be controlled from the command line with amixer. To mute/unmute the PCM track, you would enter amixer -q sset PCM,0 toggle. To lower or raise the PCM track volume by 10 percent, you would enter amixer -q sset PCM,0 10%-,10%- unmute or amixer -q sset PCM,0 10%+,10%+ unmute respectively. These commands become the values for the appropriate keys. The changes take effect immediately, so you can verify that the commands work as expected before you close the Configuration Editor. If you used the values I did, you should now be able to control the PCM track volume from your keyboard.