[ home | blog home | recent activity | guestbook | plugins i'm using (19) ]
Spent a while figuring out how to get Miro to handle media keys in Gnome. My current understanding (and this could be entirely wrong) is that as of 2.18, Gnome handles the multimedia keys. In order for your application to respond to multimedia keys, you have to connect to the signal through dbus.
My biggest problem is that my web searching revealed a lot of bugs, but no documentation. I did finally find Handling multimedia keys in GNOME 2.18 and then worked out the rest. I still have no clue where to find the documentation for it.
Here's what I got working:
import logging
import dbus
from miro import app
class MediaKeyHandler(object):
def __init__(self):
self.bus = dbus.Bus(dbus.Bus.TYPE_SESSION)
self.bus_object = self.bus.get_object(
'org.gnome.SettingsDaemon', '/org/gnome/SettingsDaemon/MediaKeys')
self.bus_object.GrabMediaPlayerKeys(
"Miro", 0, dbus_interface='org.gnome.SettingsDaemon.MediaKeys')
self.bus_object.connect_to_signal(
'MediaPlayerKeyPressed', self.handle_mediakey)
def handle_mediakey(self, *mmkeys):
for key in mmkeys:
if key == "Play":
app.widgetapp.on_play_clicked()
elif key == "Stop":
app.widgetapp.on_stop_clicked()
elif key == "Next":
app.widgetapp.on_forward_clicked()
elif key == "Previous":
app.widgetapp.on_previous_clicked()
def get_media_key_handler():
try:
return MediaKeyHandler()
except dbus.DBusException:
logging.exception("cannot load MediaKeyHandler")
If you see problems with this, let me know so I can ammend the code.
Please keep comments appropriate. I reserve the right to remove anonymous comments, flames, spammy, inappropriate, and other comments that I deem to be worth removing.
Note: New comments get placed in a "draft" status and will NOT show up on the site until I explicitly approve it. Usually that happens within 24 hours, but sometimes I go away and it takes a day or two.
Note 2: There is now a preview button for those of you who want to see a preview! However, it doesn't quite work the way you'd think it should work. I'll look into adjusting it some day.
Note 3: If you can't for some reason post a comment, send me an email: willg at bluesock dot org.
All contents Copyright 1996 to 2010 Will Guaraldi Kahn-Greene.
This work is licensed under a
Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.