Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Add mac_default_menu #631

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

geekynils
Copy link

@geekynils geekynils commented Feb 14, 2022

Hi Floooh,

Here is a proposal for a default menu on the Mac that includes hiding / showing and quitting!

image

Thanks again for the amazing sokol library!

resolves #362, resolves #265

@meshula
Copy link

meshula commented Feb 15, 2022

FWIW, I always hack something like this in, otherwise people complain about cmd-Q not working. I always have to remember to do it, so I'd be in favor of having something like this in the lib.

@floooh
Copy link
Owner

floooh commented Feb 25, 2022

Just copying my replies from Twitter :)

"The PR has a few problems, like hardwired non-localized strings and hotkeys. TBH I would prefer to add the necessary hooks so that user-code can setup the menu outside sokol_app.h (it might even work already since NSApp is a globally visible singleton)."

"...I'll try to prioritize this after I'm done with the current WebGPU update though, I'm thinking about one or a handful macOS specific functions or sapp_desc items to setup a minimal main menu on macOS with user-provided strings."

"(e.g. I realize that user-side code is a problem because of the ObjC requirement)"

1 similar comment
@floooh
Copy link
Owner

floooh commented Feb 25, 2022

Just copying my replies from Twitter :)

"The PR has a few problems, like hardwired non-localized strings and hotkeys. TBH I would prefer to add the necessary hooks so that user-code can setup the menu outside sokol_app.h (it might even work already since NSApp is a globally visible singleton)."

"...I'll try to prioritize this after I'm done with the current WebGPU update though, I'm thinking about one or a handful macOS specific functions or sapp_desc items to setup a minimal main menu on macOS with user-provided strings."

"(e.g. I realize that user-side code is a problem because of the ObjC requirement)"

@geekynils
Copy link
Author

Thx for the quick replay! If I understood correctly you would rather not have a default menu but an easy way to hook up Mac specific things such as the menu. Could we not have both? A default menu unless the user overwrites the default one? But the default one would not be localized then (otherwise I would have to add localization in all the major languages I think).

So far I just added it to NSApp.mainMenu in the init_cb which works but is probably not the proper way to do it.

@floooh
Copy link
Owner

floooh commented Feb 26, 2022

Could we not have both?

Yes ideally. Every sokol_app.h application should have at least a default menu with Quit, Hide, etc... but the strings must be provided externally, not hardwired to English, maybe in sapp_desc.h. For more advanced stuff the user needs to 'fall back' to ObjC outside sokol_app.h (by directly setting NSApp.mainMenu)

@meshula
Copy link

meshula commented Feb 26, 2022

The precise moment in an NSApp when you can successfully create menus is at the top of this function:

@implementation _sapp_macos_app_delegate
- (void)applicationDidFinishLaunching:(NSNotification*)aNotification {

before then, setting the menus won't work. This function creates windows and sets timers, and so setting menus after it finishes introduces a small indeterminancy as to when the menus will be created. For my own purposes, a callback in this function where I can poke in my own menus, and do other mac specific initialization is ideal. I think the best place would be after the sapp is fully initialized and the metal device is created, but before any deferred mechanisms, such as timers are started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sokol_app: Command+Q quit event on macOS
3 participants