Clemapfel / Mousetrap.jl

Finally, a GUI Engine made for Julia
https://clemens-cords.com/mousetrap
GNU Lesser General Public License v3.0
384 stars 9 forks source link

MacOS Handles menus differently than Windows and Linux #40

Open socialmediarefugee opened 8 months ago

socialmediarefugee commented 8 months ago

MacOS handles all of the menu functions for applications. Generally, the Cocoa application object is supplied with delegates implementing a command pattern. Gtk has traditionally had difficulties with this, requiring a separate library to fully support it. Now, that library is deprecated because, supposedly, gtk4 handles that. It may be as simple as providing true values for GtkSettings:gtk-shell-shows-app-menu and GtkSettings:gtk-shell-shows-menubar

Clemapfel commented 8 months ago

I don't see how these settings would help but you can set them like this:

using Mousetrap
import GTK4_jll

main() do app::Application

    settings = ccall((:gtk_settings_get_default, GTK4_jll.libgtk4), Ptr{Cvoid}, ())
    @ccall GTK4_jll.libgtk4.g_object_set(settings::Ptr{Cvoid}, "gtk-shell-shows-app-menu"::Cstring, true::Bool, C_NULL::Ptr{Cvoid})::Cint
    @ccall GTK4_jll.libgtk4.g_object_set(settings::Ptr{Cvoid}, "gtk-shell-shows-menubar"::Cstring, true::Bool, C_NULL::Ptr{Cvoid})::Cint

    # your code here
end

You may need to install GTK4_jll with import Pkg; Pkg.add("GTK4_jll")

Clemapfel commented 8 months ago

I've been looking into https://docs.gtk.org/gtk4/method.Application.set_menubar.html which states:

Depending on the desktop environment, this may appear at the top of each window, or at the top of the screen

I don't have a mac to test if this is indeed the thing we are looking for, since there needs to be some kind of function that provides GTK4 a MenuModel, this might be it.

I added this function for 3.1, though it will be reserved to Mousetrap.detail since this function does literally nothing on both Windows and Linux, on those platforms MenuBar should be used instead.

socialmediarefugee commented 8 months ago

No joy as of yet. Today I installed a Linux vm and will test on that to confirm that what I’ve written works. Then I will retest on MaOS. Probably in the next few days