Handling multimedia keys in GNOME 2.18

Published: May 16, 2007

GNOME 2.18 introduced a new way for applications to handle multimedia keys. Previously you have to muck around with X events, while now GNOME does it for you and you can get control of mmkeys by requesting through D-Bus (to GNOME Control Center’s Settings Daemon). All good until you realise that for cross-desktop support you still need the old method anyway—unless, like Rhythmbox and Banshee, your app is GNOME-based.

Few people are aware of this change—most only realised after their mmkeys didn’t work anymore (Rhythmbox, Banshee, Exaile, Quod Libet, Amarok). I couldn’t find any documentation regarding the new method, so I decided to write one to help other media player writers.

  1. Bus name: org.gnome.SettingsDaemon
  2. Object path: /org/gnome/SettingsDaemon
  3. Interface: org.gnome.SettingsDaemon
  4. Methods:
    • GrabMediaPlayerKeys(application, time)
      • application is simply the application name.
      • time determines which application name gets sent with the MediaPlayerKeyPressed signal if multiple applications have registered interest in controlling mmkeys. Rhythmbox uses 0 for time (I think 0 simply pushes your application to a stack), so that’s probably what you should use as well.
    • ReleaseMediaPlayerKeys(application)
  5. Signals:
    • MediaPlayerKeyPressed(application, key)
      • Must check that application is your application name.
      • key can be ‘Play’, ‘Pause’, ‘Stop’, ‘Next’, and ‘Previous’ (at least in current gnomecc).

Exaile’s revision 2255 shows how we added common mmkeys support to Exaile. I have made the MmKeys class generic so other players can also use it if they want to. Note that I’ve added a ‘PlayPause’ key to match the signal from the mmkeys module.

This post has been in my blog queue for some time, and meanwhile in the Quod Libet world, Joe Wreschnig has refused to add GNOME mmkeys support to the core, Facundo Batista created a patch that does it anyway, and Ronny Haryanto created a plugin based on the patch (and blogged about it). The plugin does a few things incorrectly, so I’ll notify I’ve notified Ronny about it.

Acknowledgements:

  • Thanks to Albert Bicchi for alerting me in #exaile to this change.
  • The information here is based on the source codes of GNOME Control Center and Rhythmbox, and also a patch for Banshee.

No thanks to GNOME for being quiet about this mass application breakage.

Update 2007-05-16: Just found out that this has also been fixed in Listen some time ago, yay!

vim tip: Color schemes

Tired of looking at the same colours in Vim all the time? Use the colorscheme (colo) command. For example, try :colorscheme evening (if you want to revert, the default scheme is named “default”). The effects of colour schemes are more noticable when you’re using GVim.

There are a few colour schemes included with Vim, normally located in /usr/share/vim/vimXX/colors/ (XX is 70 if you use Vim 7.0).

Restored from VimTips archive

This article was restored from the VimTips archive. There's probably missing images and broken links (and even some flash references), but it was still important to me to bring them back.


Filed Under: