Global keybindings in GTK+

Dear lazy web,

How can I add some global keybindings in a GTK+ application? Something like GNOME-do does…

Tags: , ,

14 Responses to “Global keybindings in GTK+”

  1. Ian says:

    I don’t know, but the answer lies in the gnome-do source, which you are allowed to read. :) Tomboy, too.

  2. John says:

    Read the GNOME-do source code…

  3. Rno says:

    Hello,

    Gnome-Do use a lib: libdo which does, I think, what you’re looking for. Check this file: http://bazaar.launchpad.net/~do-core/do/trunk/annotate/628?file_id=keybinder.c-20080218143923-igx29g94mjn48las-5

    Hopes it helps.

    Rno

  4. Alex Launi says:

    Why don’t you grab the gnome-do source code and see for yourself? It’s in libdo, you might also want to take a look at tomboy’s they do it too.

  5. Johan Svedberg says:

    The “correct” way is to register them in gnome-keybindings-properties like detailed in http://live.gnome.org/ControlCenter/ApplicationDefinedKeybindings

    Please write a patch for gnome-do while you’re at it. :-)

  6. Anders says:

    Hmm. Imagine if we could somehow see the source code of GNOME-do… That would be awesome! :)

  7. I wrote a library to do exactly this. GtkHotkey: https://launchpad.net/gtkhotkey

  8. There’s no good way to do this, your two bizarre hack-ish solutions are:
    1. Use gconf and steal one of the metacity keybindings (like Automatix does)
    2. Use Tomboy’s .so file (I forget the name), like gnome-do

    1. Means that you potentially steamroller over user preferences unless you’re very careful, and you have a (small) chance of not being able to register a keybinding at all. 2. means that you need to depend on code from Tomboy, so you either have to depend on Tomboy directly (like gnome-do used to) or copy code from them and keep it updated manually (like gnome-do now does).

  9. Filippo says:

    Probably a bit rough but the only thing that I can think of:
    make the application remote controllable with libunique or dbus, provide it with some command line option to do what you want and bind those to metacity global keybindings setting the relevant keys in /apps/metacity/global_key_bindings and /apps/metacity/keybinding_commands.
    Any better idea?

  10. Bastien says:

    http://live.gnome.org/ControlCenter/ApplicationDefinedKeybindings
    Then there’s some copy-paste code available for actually capturing the key, look for tomboykeybinder.c

  11. Kind of irrelevant, but one thing I don’t get is how Gnome’s keyboard shortcuts completely fail at using the super keys, but both Compiz Fusion and Gnome Do don’t have any trouble at all…

  12. Luca Bruno says:

    Thanks for this post! I discovered gnome-keybindings which right what I’m looking for.

  13. Luca Bruno says:

    No well, that wasn’t what I was looking for really. It’s only an entry in gnome-control-center, nothing more. I think i’ll go for the egg!