Best way to make menu item accelerators application-global while menubar is hidden?

I’m working on a project (gomics, a comic book viewer) that has a menubar, with various accelerators for menu items. The application has a fullscreen mode that hides everything except the current page, including the menubar. Since the menubar is hidden in fullscreen mode, the accelerators directly attached to the menu items do not work.

My first approach was capturing key events for the top level window that mirror the accelerators, only respond in fullscreen mode. This added a lot of code duplication and didn’t directly support accelerator maps.

I also tried having just a single top-level accelerator group, but then the accelerator mapping labels do not appear on the menu items, since they aren’t attached to them.

In the current iteration I have two mirrored accel groups, one for fullscreen attached to the top-level window, and one for non-fullscreen attached to the menu items. The groups are swapped out depending on which mode is active.

What would be the best way to solve this problem? Ideally I’d also like the accelerators to be user remappable via accelerator maps.

A small test case is at:

Have you tried GMenu with GActions?

I recently wrote an example for Nim language, I would think that it will work fine in fullscrenn mode:

I agree that you should consider using GtkApplication, GAction, and GMenu.

You can set accels for actions and the menu will show them automatically (except when the menu model is bound to a GtkPopover). There is also GtkShortcutsWindow, which will display the active accels if you set the action-name property on each GtkShortcutsShortcut.

The gtk example application bloatpad demonstrates all of this, plus a basic accel editor. You can use a TreeView with GtkCellRendererAccel if you want a nicer editing dialog.

According to the close message on my issue filed against Gnome Terminal, about menu accelerators not working with a hidden menubar:

That is impossible with current gtk+

Appreciate the advice everyone. GMenu/GAction seem like what I am looking for, and at first glance gotk3 (go GTK bindings) supports them. I’ll see if those work, if not I’ll fall back on having duplicate accelerators attached to the top-level window.

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