Connecting to GdkKeymap signals

Hi all, I’m trying to write a little program in which I would like to run a function every time the Caps Lock function is pressed. For that I was attempting to write something like the below code using GdkKeymap and connecting to its signals to smoothly wait for the key-pressed event:

GdkKeymap    *keymap;
keymap = gdk_keymap_get_default();
g_object_connect(keymap, "Gdk.Keymap::state-changed", awesome_function)

However I get a “GLib-GObject-WARNING **: g_object_connect: invalid signal spec “Gdk.Keymap::state-changed”” error. I’ve read the docs 1 and I failed to understand how am I supposed to specify the keymap “state-changed” signal 2. Does anybody how it is done? Or am I completely off-point and should be doing something completely different?

Just as "state-changed".

Hi, thanks for answering back. I’m afraid the code:

GdkKeymap *keymap;
keymap = gdk_keymap_get_default();
g_object_connect(keymap, "state-changed", awesome_function);

Also throws the line: GLib-GObject-WARNING **: 09:43:19.786: g_object_connect: invalid signal spec "state-changed"

You are missing a modifier:

The signal specs expected by this function have the form “modifier::signal_name”, where modifier can be one of the following: - signal […]

So:

g_object_connect(keymap, "signal::state-changed", awesome_function)

Or just use the normal way of g_signal_connect() (tbh I have never seen g_object_connect() before, LOL)

g_signal_connect(keymap, "state-changed", awesome_function)

Right! That works! Thanks! \o/

Please, don’t use g_object_connect() to connect to a single signal: it’s a “magic” C convenience function that only makes sense in the context of creating a new object instance, connecting to a bunch of signals, and setting a bunch of properties, all at the same time.

You should use g_signal_connect().

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.