Mousetrap.jl icon indicating copy to clipboard operation
Mousetrap.jl copied to clipboard

MacOS Handles menus differently than Windows and Linux

Open socialmediarefugee opened this issue 2 years ago • 3 comments
trafficstars

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

socialmediarefugee avatar Oct 22 '23 21:10 socialmediarefugee

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 avatar Oct 23 '23 19:10 Clemapfel

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.

Clemapfel avatar Oct 23 '23 19:10 Clemapfel

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

socialmediarefugee avatar Oct 24 '23 22:10 socialmediarefugee