6

I'm trying to listen for MediaKey events under Gnome 3 (Gnome Shell). All the examples I find refer to using DBus to connect to org.gnome.SettingsDaemon.MediaKeys. This service doesn't seem to exist on my platform.

I'm trying to do this using Python via GObject-Introspection. The examples say do something like this

from gi.reposiotry import Gio

connection = Gio.bus_get_sync(Gio.BusType.SESSION, None)
proxy = Gio.DBusProxy.new_sync(connection, 0, None, 'org.gnome.SettingsDaemon', '/org/gnome/SettingsDaemon/MediaKeys', 'org.gnome.SettingsDaemon.MediaKeys', None)

This fails, unsurprisingly. Am I missing an install which provides this service, or do I have to do this another way?

UPDATE

This is for a media key listener, which listens for key events no matter which window has the focus. It's meant for an app which doesn't even have it's own GUI, and is Desktop wide. That's why I tried the Mediakeys DBus service, only to find it is missing from my Desktop.

UPDATE 2

I should be clear, the MediaKeys service is not present. I can't event connect to the service and create the proxy as it's not there. What I'm wanting to know is, am I missing an install, or was this service removed in one of the Gnome 3 updates? If it was removed, then how can I listen for Media Keys in this new environment? I'm running Gnome 3.8.2.

UPDATE 3

Sorry should have mentioned this in the first place. I'll perfect my question asking one day :-}. I'm running Gentoo.

James Hurford
  • 2,018
  • 19
  • 40
  • I am not sure about where you get event(intercepted or direct) but the classic connect("key-press-event", myfunc) don't send an event to myfunc, with event.key = ...? – cox Sep 29 '13 at 21:51
  • Sorry, I'm not sure I understand what you're saying. What I'm wanting is to know when any of the media keys are pressed, no matter which window has the focus, or if I have no windows open at all, just the desktop. – James Hurford Sep 29 '13 at 22:09
  • @JamesHurford Can you confirm if the media keys dbus service file exists in the system? You could search under `/usr/share/dbus-1/services/`. – Nikhil Oct 01 '13 at 05:37
  • On Debian based systems, the `gnome-settings-daemon` package provides this functionality and should be installed. `apt-get install gnome-settings-daemon`. Your example code has a couple of typos, eg it should be `/org/gnome...`, rather than `org/gnome...`. You can use the `d-feet` app to browse the dbus hierarchy. – Austin Phillips Oct 01 '13 at 05:51
  • I have gnome-settings-daemon installed. It's version 3.8.4. I can't find the dbus service file for this service. I've searched the entire system for this. And yes there is a typo, but that's only in the question, not my code. And yes I do use d-feet, that's how I discovered the service wasn't even running. Thanks – James Hurford Oct 01 '13 at 06:08
  • `dpkg -L gnome-settings-daemon` should give you a list of all files installed for that package. If the `org.gnome.SettingsDaemon.service` file is listed in the `dpkg -L` output but the file isn't on your system, you've got a failed install. – Austin Phillips Oct 01 '13 at 06:12
  • Sorry I seem to be full of fail when it comes to laying out the problem :-(. I should point out I'm running Gentoo. The comment about gnome-setting-daemon was helpful, as there is a package by that name for Gentoo, which I've installed, but I can't use dpkg -L as for obvious reasons. Thanks anyway. I was actually hoping it was a Gnome decision to remove this service, and that there was a new way of doing it. – James Hurford Oct 02 '13 at 10:03

1 Answers1

5

Have you actually seen this question? can't get dbus signal listener to work in C with gnome multimedia keys

The questioner said this code works:

#!/usr/bin/env python
"""Printing out gnome multi media keys via dbus-python.
"""
import gobject
import dbus
import dbus.service
import dbus.mainloop.glib


def on_mediakey(comes_from, what):
    """ gets called when multimedia keys are pressed down.
    """
    print ('comes from:%s  what:%s') % (comes_from, what)
    if what in ['Stop','Play','Next','Previous']:
        print ('Got a multimedia key!')
    else:
        print ('Got a multimedia key...')

# set up the glib main loop.
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.Bus(dbus.Bus.TYPE_SESSION)
bus_object = bus.get_object('org.gnome.SettingsDaemon', 
                            '/org/gnome/SettingsDaemon/MediaKeys')

# this is what gives us the multi media keys.
dbus_interface='org.gnome.SettingsDaemon.MediaKeys'
bus_object.GrabMediaPlayerKeys("MyMultimediaThingy", 0, 
                               dbus_interface=dbus_interface)

# connect_to_signal registers our callback function.
bus_object.connect_to_signal('MediaPlayerKeyPressed', 
                             on_mediakey)

# and we start the main loop.
mainloop = gobject.MainLoop()
mainloop.run()

Update:

It seems that your problem is with your Gnome distribution, as someone else had encountered previously in this bug report. So probably you should upgrade your distribution.

Community
  • 1
  • 1
justhalf
  • 8,960
  • 3
  • 47
  • 74
  • If only it were that simple. thanks, but as I said, the MediaKeys service is missing completely. There is no MediaKeys service, or I would not have this problem. Sorry it's probably my fault, I should be clearer about what I'm asking for. – James Hurford Oct 01 '13 at 05:23
  • Have you tried installing `gstreamer-dbus-media-service` or `gnome-settings-daemon`? What distro are you using? – justhalf Oct 01 '13 at 06:06
  • 1
    You can check this bug report: https://bugs.launchpad.net/ubuntu/+source/checkbox/+bug/967211 – justhalf Oct 01 '13 at 06:12
  • 1
    Thanks the bug report helped. It's telling me I should upgrade and it may just resolve itself. You get a point just for that last helpful comment, thanks :-) – James Hurford Oct 02 '13 at 09:58
  • 1
    Thanks, but I don't have the time to try this, before the bounty expires. I'll give it to you anyway, as I think you might just be right. – James Hurford Oct 02 '13 at 12:15
  • Thanks, did an update and now it works. Must have been something missing somewhere, who can tell, as it should have worked even under the old version. Oh and MediaKeys are a service defined entirely in code in gnome-settings-daemon. C in fact. There is no service file to start or stop it, in terms of the media keys service. – James Hurford Oct 07 '13 at 12:31