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

Add support for loading menus from a nib/xib instead of building a hardcoded minimum set #3461

Closed
SDLBugzilla opened this issue Feb 11, 2021 · 0 comments

Comments

@SDLBugzilla
Copy link
Collaborator

This bug report was migrated from our old Bugzilla tracker.

These attachments are available in the static archive:

Reported in version: HG 2.1
Reported for operating system, platform: Mac OS X (All), x86

Comments on the original bug report:

On 2019-11-26 14:47:01 +0000, Eric Shepherd (:sheppy) wrote:

Created attachment 4071
Patch to support optional MainMenu nib file

Currently, SDL on Cocoa macOS creates a rudimentary menu bar programmatically if none is already present when the app is registered during setup.

SDL could be much more easily and flexibly used on macOS if upon finding that no menus are currently in place, it first looked for the application's main menu nib or xib file and, if found, loaded that instead of programmatically building the menus.

This would then let developers simply drop in a nib file with a menu bar defined in it and it would be installed and used automatically.

Attached is a patch that does just this. It changes the SDL_cocoaevents.m file to:

  • In Cocoa_RegisterApp(), before calling CreateApplicationMenus(), it calls a new function, LoadMainMenuNibIfAvailable(), which attempts to load and install the main menu nib file, using the nib name fetched from the Info.plist file. If that succeeds, LoadMainMenuNibIfAvailable() returns true; otherwise false.
  • If LMMNIA() returns false, CreateApplicationMenus() is called to programmatically build the menus as before.
  • Otherwise, we're done, and using the menus from the nib/xib file!

I made these changes to support a project I'm working on, and felt they were useful enough to be worth offering them for uplift. They should have zero impact on existing projects' behavior, but make Cocoa SDL development miles easier.

On 2019-12-03 15:13:14 +0000, Sam Lantinga wrote:

This is a great change, thanks!
https://hg.libsdl.org/SDL/rev/a72231930f12

On 2020-09-25 22:50:05 +0000, Ozkan Sezer wrote:

loadNibNamed:owner:topLevelObjects is available on 10.8 and newer.
There is an issue report here about an app failing to function on
10.7 and earlier: https://discourse.libsdl.org/t/28179

On 2020-09-25 23:10:02 +0000, Ozkan Sezer wrote:

Maybe something like the following??

diff a/src/video/cocoa/SDL_cocoaevents.m b/src/video/cocoa/SDL_cocoaevents.m
--- a/src/video/cocoa/SDL_cocoaevents.m
+++ b/src/video/cocoa/SDL_cocoaevents.m
@@ -33,6 +33,9 @@
#ifndef kIOPMAssertPreventUserIdleDisplaySleep
#define kIOPMAssertPreventUserIdleDisplaySleep kIOPMAssertionTypePreventUserIdleDisplaySleep
#endif
+#ifndef NSAppKitVersionNumber10_8
+#define NSAppKitVersionNumber10_8 1187
+#endif

@interface SDLApplication : NSApplication

@@ -306,7 +309,10 @@ LoadMainMenuNibIfAvailable(void)
NSDictionary *infoDict;
NSString *mainNibFileName;
bool success = false;

  • if (floor(NSAppKitVersionNumber) < NSAppKitVersionNumber10_8) {
  •    return false;
    
  • }
    infoDict = [[NSBundle mainBundle] infoDictionary];
    if (infoDict) {
    mainNibFileName = [infoDict valueForKey:@"NSMainNibFile"];

On 2020-09-27 10:30:06 +0000, Ozkan Sezer wrote:

Reopening for comment # 2

On 2020-10-04 15:03:04 +0000, Ozkan Sezer wrote:

PING?

On 2020-10-09 01:01:12 +0000, Ozkan Sezer wrote:

Applied https://hg.libsdl.org/SDL/rev/d04d0a1e9caf
Re-closing as fixed.

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

No branches or pull requests

1 participant