Categories
Software

Using multimedia keys in GDM

I currently use MPD as my preferred media player, as it runs on my central machine, and I can easily control it from any other machine on our home network.

Now, occasionally, one wishes to just turn on the computer, and without logging in and doing all that admin, get some music playing / skip a song or two and adjust the volume to the correct settings.

The problem is that the first thing that loads up is GDM, which does not know what to do when you press one of the multimedia key on a multimedia keyboard.

Fortunately, this can be fixed easily using the accessibility framework built into GDM.

Edit the following lines in /etc/gdm/gdm.conf:

AddGtkModules=true
GtkModulesList=/usr/lib/gtk-2.0/modules/libkeymouselistener

Next, you need to add entries for each of your multimedia keys in /etc/gdm/modules/AccessKeyMouseEvents.

The entry format is as follows:

keycode num_keypresses keypress_duration timeout command command_args

Where, the command with it’s arguments is executed when the key given by keycode is depressed as many times as specified by the number of keypresses for longer than the keypress duration. Note, the command will be run as root, so be sure that it can’t do anything destructive!!

For example, my configuration which uses the mpc command to control the mpd daemon is as follows:

XF86AudioNext 1 0 1000 /usr/bin/mpc next
XF86AudioPrev 1 0 1000 /usr/bin/mpc prev
XF86AudioStop 1 0 1000 /usr/bin/mpc stop
XF86AudioPlay 1 0 1000 /usr/bin/mpc toggle
XF86AudioLowerVolume 1 0 1000 /usr/bin/mpc volume -2
XF86AudioRaiseVolume 1 0 1000 /usr/bin/mpc volume +2
XF86AudioMute 1 0 1000 /usr/bin/mpc volume 0

Then restart gdm by executing /etc/init.d/gdm restart

Voila, your multimedia keys should work in GDM!!