macOS problems with the Gtk4 Application menu
Since Gtk4 removed gtk_application_set_app_menu
and the commit 75868dfe the Application menu is behaving oddly and lost parts of it functionality.
Through the Application menu you have a submenu in the macOS Desktop menu bar under the name of the Application before the usual menus (File, Edit...).
In Gtk3 you could either do nothing and Gtk3 would populate the Application menu with defaults (see /org/gtk/libgtk/ui/gtkapplication-quartz.ui
) or you could use gtk_application_set_app_menu
to setup your own Application menu. On the menu bar the menu set up with gtk_application_set_menubar
appended.
In Gtk4 this got more dificult with the removal of gtk_application_set_app_menu
and 75868dfe which aimed to fix some of the issues caused by the removal, see #3967 (closed).
- the default Application menu from
/org/gtk/libgtk/ui/gtkapplication-quartz.ui
is only being used when NO menu is set up viagtk_application_set_menubar
- when a menubar is set up the first submenu of the menubar is being used for the Application menu. This messes up the look of the menu because in most cases the File menu is now the Application menu. AFAIU this also means that on Gnome it also looks weird because the menu is now "Application, Edit,..." but I have no first hand confirmation.
So there are three ways around this that I could think of with my limited knowledge:
-
Leave it as it is and require applications to add their own Application menu
-
restore that on macOS the
gtkapplication-quartz.ui
is back to always being used for the Application menu. Pro: this will not affect any other system. Con: Applications like Gimp or Inkscape are using the Application menu for more things than the default. There is no way around this anymore unless they add code similar to what gtkapplication-quartz.c does. -
bring back something like
gtk_application_set_app_menu
For 1 this patch adds an Applications menu and fixes the current behaviour of placing Files into the Applications menu. gtk4-demo-application is an example.
Problem: (fixed in the new patch)g_menu_prepend_submenu (menubar, "Application", appmenu);
produces a compile warning about incompatible pointers - so that needs a fix by someone who knows what he is doing.
(patch 1 removed, added new one in reply)
For 2 this patch restores the default Application menu on macOS to always show. The example gtk4-demo-application has the Application menu replacement code commented because this code does not replace the default Application menu but places the extra menu before File. Again someone else must fix this (if that is possible). (fixed in the new patch)
(patch 2 removed, added new one in reply)
I have no idea what the best course of action is, perhaps option 1 after all.
gtk_application_set_app_menu
was way better for this but there are surely good reasons you got rid of that.
This issue was brought on by examining #6524 (closed) but due to it being more complicated and probably needs discussion I created a new issue. I hope that is alright.
Edit: changed patches for gtk4-demo-application to use gtkapplication-quartz.ui
for the Application menu
Edit2: in patch 1 the aforementioned edit didn't work, patch 2 is very simpler now.