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.
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.
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.