xmonad: Bind XF86Audio keys with EZConfig

I used to just run gnome-settings-daemon to handle my media keys, but as of Ubuntu 14.10 it’s stopped working. I figured that it was about time that I managed them properly by binding keys in my Xmonad config.

myBindings =
    [ ("<XF86AudioMute>"  , spawn "amixer -q -D pulse sset Master toggle")
    , ("<XF86AudioRaiseVolume>"  , spawn "amixer -q -D pulse sset Master 2000+ unmute")
    , ("<XF86AudioLowerVolume>"  , spawn "amixer -q -D pulse sset Master 2000- unmute")
    , ("<XF86AudioPlay>"  , spawn "dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause")
    ]

There are other bindings in there too, but these are the ones we’re interested in. We use amixer to set the volume on our audio device. It’s all fairly straightforward, but you might have to work out what your output device is called if you have multiple. For me, it was called Master (which is the default).

As a little bonus, I even managed to get the play/pause button to control Spotify via dbus. To achive this, we use dbus-send and send the PlayPause command

dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause

Published:
November 19, 2014

Category
How To