Modifying GLFW window menu bar


#1

Hi there - I presume I already know the answer to this question (unsupported since it can’t be done in a generic/cross-platform way), but wanted to double-check to confirm.

I’m porting an application to GLFW, which I am finding to be great. Thanks for this excellent framework! On Mac, the window that is created seems to by default have in its menu-bar a “Window” menu which includes a “Minimize” option with the “command-M” shortcut.

My application formerly used “command-M” for another behavior, within a windowing framework that didn’t have that default “Window” menu. If it comes down to it, I can resort to changing my application’s shortcut-command. But I’d prefer to just ditch this menu-bar if I can.

Question: is there any way to get access to this menu bar and modify it? I know I can use glfwGetCocoaWindow() to get the raw Cocoa window handle. Then I suppose I could dig into using that somehow to modifying the window (I am not familiar with the Cocoa APIs).

Is there any other approach here? Anyone tried to do this type of menu-bar modification in a GLFW application before? Any recommendations?

Thanks in advance!


#2

Using Cocoa to modify the menu will definitely work. Have a look at the NSApplication, NSMenu and NSMenuItem classes.

You could modify the function in src/cocoa_window.m that creates the menu item and remove the m from the key equivalent and then recompile. The name of the function depends on the version of GLFW but search for addItemWithTitle:@"Minimize".

Current GLFW on GitHub also supports loading a MainMenu.nib file specifically for menu customization. The menu from the file will wholly replace the one created manually in code by GLFW. This is a little more work up front but will let you use an unmodified GLFW in case you need that.


#3

Huge thanks for this. I just generated my own MainMenu.nib, packaged it with my app bundle and it worked perfectly. This is an excellent solution, glad to not have to hack up a modified version of GLFW. Please mark me as a +1 vote for retaining this custom nib option in future versions - seems like an elegant way of offering deeper platform-specific customization with minimal impact/bloat to the core GLFW API.

Really appreciate the quick reply. Thank you!