Global menu bar support
See original GitHub issueCurrently there are at least two global menubars that we need to support: OS X and Ubuntu ones.
Preferably we should synchronize items from our own menubar. To do that we probably want to create a property for that menu bar in Window
and alter Window
’s template.
GTK has various ways of submitting items to the menu bar.
For OS X there is gtk_mac_menu_set_menu_bar that should be followed by gtk_mac_menu_sync
calls when toplevel menu item list is changed.
Ubuntu provides GtkMenuProxy
module that does some voodoo to detect window’s menu, hide it and offload contents to system menubar. That voodoo doesn’t always properly work, so it’s disabled for some applications (notable example is MonoDevelop).
Starting from GTK3 there is gtk_application_set_app_menu which sets “application” menu, which seems to be shown before any other menu items (at least on Ubuntu, according to docs).
We might want to stick to using gtk_application_set_app_menu
, since on OS X gtk_mac_menu_set_menu_bar
operates on application level anyway. In this scenario we need to update menubar on window activation.
Issue Analytics
- State:
- Created 7 years ago
- Comments:12 (9 by maintainers)
Top GitHub Comments
Mkay, since this feature is getting a lot of interest lately, here is a proposal:
General export procedure
We introduce
SimpleMenuItem
class derived fromAvaloniaObject
with following properties:string
Header
SimpleMenuItemToggleType
ToggleType
bool
IsToggled
Bitmap
Image
AvaloniaList<ISimpleMenuItem>
Children
SimpleMenuItemToggleType
enum:None
,Checkbox
,Radio
. It maps directly totoggle-type
from dbus-menu. On OSXCheckbox
maps to the defaultonStateImage
whileRadio
maps to a custom image. At first we can only implementNone
andCheckbox
, but this should be an enum to provide backwards compatibility when we addRadio
.We make SimpleMenuItem and Separator implement a “marker” interface
ISimpleMenuItem
.SimpleMenuItem
could later be used for “system-tray” menus for OSX and various Linux distros.Then we add
MainMenu
control for the window that shows a MenuBar with items or/and (APPMENU_SHOW_BOTH=1 environment should force us to show both) exports the items to the system.IWindowImpl should now have
IMenuBarExporterSink MenuBarExporter { get; }
optional property. We might also go withT GetFeature<T>()
approach for optional features, so exporter would be obtained byPlatformImpl.GetFeature<ISimpleMenuExporterSink>()
.Then we would have
SimpleMenuExporter
class (internal to Avalonia.Controls) that syncsAvaloniaList<ISimpleMenuItem>
toISimpleMenuExporterSink
. The proposed API ispublic static IDisposable Sync(AvaloniaList<ISimpleMenuItem> items, ISimpleMenuExporterSink sink)
A separate exporter class is needed for implementing exported tray icon menus later.
Application-global menu
Later we can make
App
class to haveApplicationMenuItems
property that gets prepended to eachMainMenu
control’s items.@danwalmsley @grokys
It seems that Linux global menu is still alive alive and well across non-Unity desktop environments. Here is the definition file for DBus interface: https://git.launchpad.net/ubuntu/+source/libdbusmenu/tree/libdbusmenu-glib/dbus-menu.xml?h=debian/sid