emoon / rust_minifb

Cross platfrom window and framebuffer crate for Rust
MIT License
980 stars 92 forks source link

Menus do not Work on macOS Before Reselecting Window #334

Closed thisjaiden closed 6 months ago

thisjaiden commented 6 months ago

Issue

When running cargo run --example menu or writing code that uses menu functionality, menus do not work until the window is deselected and re-selected. Specifically, menus show up but clicking on them does nothing. This includes both the 🍎 menu, about menu, and any user menus.

Environment

Things I have Found

This StackOverflow post seems to describe this issue (though not for this library or even Rust) and suggests that it's the underlying NSApp/AppKit not getting fully initialized.

I have a little experience with Rust and macOS FFIs, but looking at how this library and rust-windowing/raw-window-handle manage making an NSWindow I have no clue how the NSApp context is created, managed, ect. If all of that is implied by some higher level shortcut in the FFI, then it may be a macOS bug. If it's not, it may be a bug with this library or any of its dependencies. I was unsuccessful in digging any further.

I'm happy to help with any hardware testing needed, and taking it to any dependencies' projects. If some indication of exactly where this initialization happens is pointed to I may be able to make a PR.

Thanks much for the great crate! :)

emoon commented 6 months ago

Hi,

Thanks :)

Thanks for the report. The macOS backend is actually not implemented in Rust but in ObjC (of course there is a layer to talk with Rust) but all setup is here https://github.com/emoon/rust_minifb/tree/master/src/native/macosx

If you would be willing to have a look at this code in order to do a PR that would be awesome!

Edit: NSApp is created here https://github.com/emoon/rust_minifb/blob/master/src/native/macosx/MacMiniFB.m#L158 to get you started.

thisjaiden commented 6 months ago

Made a quick PR, thankfully just a two line change. Thanks for the pointer!

emoon commented 6 months ago

fixed by #335