Register system wde shortkey

H, ALL,

Is it possible to create a tray like application which will show window when the user presses some hot key combination?

If it is - how do I create a register such key combination?

I know both Windows and OSX have an API for that - does GTK have an equivalent?

Thank you.

Hi, guys,

I just found this: Gtk.Shortcut, but it does not say what version it was implemented. And neither is for Gtk.ShortcutController.

I think that’s what I will need to implement what I need but I need the info about when (what version) implements it.

Thank you.

They are part of the GTK 4 API; if you don’t see a “Since” annotation, then it means the API has been available since the first release of GTK4, i.e. 4.0.

But GtkShortcut is for application-specific shortcuts, not system-wide. There is no system-wide API to register a shortcut. There is some internal API that you can use to tell GNOME Shell to monitor key combinations, and call a binary, but nothing public. It’ll also not work for sandboxed applications.

There’s an open issue for creating a portal to allow registering session-wide shortcuts, but no implementation yet, as far as I know

Hi, Emmanuelle,
Maybe I didn’t express it properly.

What im looking for is following:

When my application starts it will run in background.
When the user presses some key - the window will show up.

So what i am looking for is some kind of global hot key, which will tell the wm that the window from my app should be shown.

So, are you saying that this API is not yet ready? Or i can use the manager?

Thank you.

Yes, I understood exactly what you wanted to achieve.

There is currently no API that allows you to do that reliably. The portal issue I linked in my reply contains the proposed solution, but it hasn’t been implemented yet.

Also, I think I can register this with controller…

Thank you.

I already told you: GtkShortcutController is for shortcuts inside the application. You need to show the application’s window in order for shortcuts to work. You cannot use this API to activate your application and show the main window.

Emmanuelle,
I was referring to the gtk_shortcut_controller_set_scope() whose documentation states:

The scope allows shortcuts to be activated outside of the normal event propagation. In particular, it allows installing global keyboard shortcuts that can be activated even when a widget does not have focus.

With `GTK_SHORTCUT_SCOPE_LOCAL`, shortcuts will only be activated when the widget has focus.

So I naturally thought that if I call this function it will work.

But I trust you judgement.

Thank you and sorry about the confusion.

You can also trust the docs!

Name Description
GTK_SHORTCUT_SCOPE_LOCAL Shortcuts are handled inside the widget the controller belongs to.
GTK_SHORTCUT_SCOPE_MANAGED Shortcuts are handled by the first ancestor that is a GtkShortcutManager
GTK_SHORTCUT_SCOPE_GLOBAL Shortcuts are handled by the root widget.

Where “root” is Gtk.Widget:root (a Gtk.Root) aka your window

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