question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Global menu bar support

See original GitHub issue

Currently 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:closed
  • Created 7 years ago
  • Comments:12 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
kekekekscommented, Dec 3, 2018

Mkay, since this feature is getting a lot of interest lately, here is a proposal:

General export procedure

We introduce SimpleMenuItem class derived from AvaloniaObject with following properties:

  • string Header
  • SimpleMenuItemToggleType ToggleType
  • bool IsToggled
  • Bitmap Image
  • AvaloniaList<ISimpleMenuItem> Children

SimpleMenuItemToggleType enum: None, Checkbox, Radio. It maps directly to toggle-type from dbus-menu. On OSX Checkbox maps to the default onStateImage while Radio maps to a custom image. At first we can only implement None and Checkbox, but this should be an enum to provide backwards compatibility when we add Radio.

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 with T GetFeature<T>() approach for optional features, so exporter would be obtained by PlatformImpl.GetFeature<ISimpleMenuExporterSink>().

Then we would have SimpleMenuExporter class (internal to Avalonia.Controls) that syncs AvaloniaList<ISimpleMenuItem> to ISimpleMenuExporterSink. The proposed API is public 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 have ApplicationMenuItems property that gets prepended to each MainMenu control’s items.

@danwalmsley @grokys

1reaction
kekekekscommented, Dec 3, 2018

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Global Menus and Linux : r/linux
KDE has a decent implementation of global menu bars. ... that issue a long time ago and so can any Linux DE that...
Read more >
How to implement global menu support in C++ on Linux?
A global menu is a compromise between a client application and a server application, where both must previously agree on what a menu...
Read more >
Global Menu — helloSystem documentation
Menu: The application in helloSystem that shows the global menubar ... D-Bus needed to support sending menus of AppKit applications to the global...
Read more >
Global menu not working properly - Support & Help Requests
I notice global menu does not work perfectly. Some software's menu bar setup on own bar. I want menu bar works to global...
Read more >
helloSystem/Menu: Global menu bar written in Qt
Menu Build Status Translation status Help Wanted Issues. Global menu bar written in Qt with as few Kf5 dependencies as possible. On FreeBSD:....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found