diff --git a/README.md b/README.md index 35a133f9..298a148e 100644 --- a/README.md +++ b/README.md @@ -169,6 +169,7 @@ information on what to include when reporting a bug. - [Linux] Bugfix: Event processing did not detect joystick disconnection (#932) - [Cocoa] Added support for Vulkan window surface creation via [MoltenVK](https://moltengl.com/moltenvk/) (#870) +- [Cocoa] Added support for loading a `MainMenu.nib` when available - [Cocoa] Bugfix: Disabling window aspect ratio would assert (#852) - [Cocoa] Bugfix: Window creation failed to set first responder (#876,#883) - [Cocoa] Bugfix: Removed use of deprecated `CGDisplayIOServicePort` function diff --git a/docs/intro.dox b/docs/intro.dox index 70ed2d16..57d0da82 100644 --- a/docs/intro.dox +++ b/docs/intro.dox @@ -86,8 +86,9 @@ the application to the `Contents/Resources` subdirectory of the application's bundle, if present. @anchor GLFW_COCOA_MENUBAR -__GLFW_COCOA_MENUBAR__ specifies whether to create a basic menu bar when the -first window is created, which is when AppKit is initialized. +__GLFW_COCOA_MENUBAR__ specifies whether to create a basic menu bar, either from +a nib or manually, when the first window is created, which is when AppKit is +initialized. @subsubsection init_hints_values Supported and default values diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index d6983bcf..65e4a67c 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -2085,10 +2085,12 @@ GLFWAPI void glfwWindowHint(int hint, int value); * [Bundle Programming Guide](https://developer.apple.com/library/mac/documentation/CoreFoundation/Conceptual/CFBundles/) * in the Mac Developer Library. * - * @remark @macos The first time a window is created the menu bar is populated - * with common commands like Hide, Quit and About. The About entry opens - * a minimal about dialog with information from the application's bundle. The - * menu bar can be disabled with the @ref GLFW_COCOA_MENUBAR init hint. + * @remark @macos The first time a window is created the menu bar is created. + * If GLFW finds a `MainMenu.nib` it is loaded and assumed to contain a menu + * bar. Otherwise a minimal menu bar is created manually with common commands + * like Hide, Quit and About. The About entry opens a minimal about dialog + * with information from the application's bundle. Menu bar creation can be + * disabled entirely with the @ref GLFW_COCOA_MENUBAR init hint. * * @remark @macos On OS X 10.10 and later the window frame will not be rendered * at full resolution on Retina displays unless the diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 84c44148..5275a7a3 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -785,6 +785,10 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; //------------------------------------------------------------------------ @interface GLFWApplication : NSApplication +{ + NSArray* nibObjects; +} + @end @implementation GLFWApplication @@ -809,6 +813,17 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; - (void)doNothing:(id)object { } + +- (void)loadMainMenu +{ +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 100800 + [[NSBundle mainBundle] loadNibNamed:@"MainMenu" + owner:NSApp + topLevelObjects:&nibObjects]; +#else + [[NSBundle mainBundle] loadNibNamed:@"MainMenu" owner:NSApp]; +#endif +} @end // Try to figure out what the calling application is called @@ -848,8 +863,7 @@ static NSString* findAppName(void) // Set up the menu bar (manually) // This is nasty, nasty stuff -- calls to undocumented semi-private APIs that // could go away at any moment, lots of stuff that really should be -// localize(d|able), etc. Loading a nib would save us this horror, but that -// doesn't seem like a good thing to require of GLFW users. +// localize(d|able), etc. Add a nib to save us this horror. // static void createMenuBar(void) { @@ -943,7 +957,11 @@ static GLFWbool initializeAppKit(void) // Menu bar setup must go between sharedApplication above and // finishLaunching below, in order to properly emulate the behavior // of NSApplicationMain - createMenuBar(); + + if ([[NSBundle mainBundle] pathForResource:@"MainMenu" ofType:@"nib"]) + [NSApp loadMainMenu]; + else + createMenuBar(); } // There can only be one application delegate, but we allocate it the