Skip to content
This repository has been archived by the owner on Dec 27, 2019. It is now read-only.

Gnome shortcuts support #43

Open
Lirein opened this issue Mar 29, 2013 · 4 comments
Open

Gnome shortcuts support #43

Lirein opened this issue Mar 29, 2013 · 4 comments

Comments

@Lirein
Copy link

Lirein commented Mar 29, 2013

Please add gnome hotkey support, especially needs for multimedia keys handling, for example from xinput (remote control, LIRC, e.t.c).

@ntadej
Copy link
Owner

ntadej commented Mar 30, 2013

Can you provide me with a documentation or example?

@Lirein
Copy link
Author

Lirein commented Mar 30, 2013

Of course, you can see the code sample in C:

#include <glib.h>
#include <dbus/dbus-glib.h>
#include "marshal.h"

static void media_key_pressed(DBusGProxy *proxy, const char *value1, const char *value2, gpointer user_data) {
g_print("mediakey: %s\n",value2);
}

int main (int argc, char **argv)
{
DBusGConnection *conn;
DBusGProxy *proxy;
GError *error;
GMainLoop *loop;

g_type_init();
error = NULL;

conn = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
if (!conn) {
    g_printerr("Failed to connect to the D-BUS daemon: %s\n", error->message);
    g_error_free(error);

    return 1;
}

loop = g_main_loop_new (NULL, FALSE);
if(!loop) {
    g_printerr("Could not create mainloop\n");

    return 1;
}

proxy = dbus_g_proxy_new_for_name(conn,
                                "org.gnome.SettingsDaemon",
                                "/org/gnome/SettingsDaemon/MediaKeys",
                                "org.gnome.SettingsDaemon.MediaKeys");

if(!proxy) {
    g_printerr("Could not create proxy object\n");
}

error = NULL;
if(!dbus_g_proxy_call(proxy,
                  "GrabMediaPlayerKeys", &error,
                  G_TYPE_STRING, "WebMediaKeys",
                  G_TYPE_UINT, 0,
                  G_TYPE_INVALID,
                  G_TYPE_INVALID)) {
    g_printerr("Could not grab media player keys: %s\n", error->message);
}

dbus_g_object_register_marshaller (
        g_cclosure_user_marshal_VOID__STRING_STRING,
        G_TYPE_NONE,
        G_TYPE_STRING,
        G_TYPE_STRING,
        G_TYPE_INVALID);

dbus_g_proxy_add_signal(proxy,
                      "MediaPlayerKeyPressed",
                      G_TYPE_STRING,
                      G_TYPE_STRING,
                      G_TYPE_INVALID);

dbus_g_proxy_connect_signal(proxy,
                          "MediaPlayerKeyPressed",
                          G_CALLBACK(media_key_pressed),
                          NULL,
                          NULL);

g_print("Starting media key listener\n");
g_main_loop_run (loop);

return 0;

}

To get valid header you must do once:
glib-genmarshal --header --body mediaplayerkeypressed.list > marshal.h

Source example from StackOverflow discussion: http://stackoverflow.com/questions/5744041/cant-get-dbus-signal-listener-to-work-in-c-with-gnome-multimedia-keys

@ntadej
Copy link
Owner

ntadej commented Mar 30, 2013

So you need to listen on dbus? Is there no platform independent solution available?

@Lirein
Copy link
Author

Lirein commented Mar 30, 2013

Unfortunately no, this solution is for Gnome only. Of course you can use X11 keytest interface for X server implementation, but it doesn't work with Wayland server.
Also there are no GNOME for Windows or Mac platform. It's *nix solution only.

UPD: Oh, KDE4 support D-BUS multimedia keys too.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants