Activating menu button with key shortcut in GTK 4

How to do this in GTK 4? Like many GNOME apps my GtkHeaderBar has a primary menu (GtkMenuButton) which can be triggered (opened/closed) by a keyboard shortcut, the F10 key.

In GTK 3 I used gtk_widget_add_accelerator() with clicked signal. This function doesn’t exist in GTK 4. And it seems there is no action signal anymore that I could use, for example with GtkShortcut and gtk_signal_action_new(). Neither GtkMenuButton nor its parent GtkWidget have appropriate action signals (clicked or something similar).

The other idea was GtkShortcut with a callback action. gtk_button_clicked() is gone, but there is now gtk_menu_button_popup () or gtk_menu_button_popdown (), however, I don’t see how I can get the current state, whether to call popup or popdown.

So is it possible to find out GtkMenuButton’s state and is GtkShortcut the preferred way for activating it?

For knowing the MenuButton state, I opened this bug some times ago. (Yes, the answer Matthias gave sounds obscure to me too.)

What Matthias meant is that GtkWindow already has a shortcut mapped to F10 to activate any eventual menu bar attached to the window.

Since GtkMenuButton provides the equivalent of a menu bar, GtkWindow should activate the button automatically, without developer intervention.

Since GtkMenuButton provides the equivalent of a menu bar, GtkWindow should activate the button automatically, without developer intervention.

So having a way to say to the app “hey, this is my hamburger menu”? I fear that a semi-automatic handling of this will cause some problems for using the Ctrl + F10 shortcut (in the same way as you cannot easily register Shift + F1 for opening the About window, because F1 is partly managed by Gtk; no, I didn’t open a bug for that, just found a way to make things work); but I’m not opposed to it, it’s always great to have the toolkit push to some more coherence between the apps.

Anyway, I think an active property would be great whether or not the hamburger menu is managed automatically or not. To put a game in pause when the menu is opened, for example. I’ll add that use case to the bug also.

Thank you both for your comments here and at the bug report. I like the linked arnaudb/wip/gtk4 branch in Chess, are you aware of other projects which have public GTK 4 migration branches? I just know of gnome-todo being in master already on GTK 4 and Timm Bäder’s Corebird and Waster.

are you aware of other projects which have public GTK 4 migration branches?

Tetravex, Taquin, Klotski, Mahjongg, Five-or-More, Four-in-a-Row, Swell-Foop, Mines, Robots and Sudoku (and the libgnome-games-support module) have similar branches that worked flawlessly at one point in the two last months. Some need an upgrade now –as Gtk4 continues to be a moving target– but I consider them as a proof an update will be possible for these games.

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