[Scummvm-devel] Issue with menus on OS X with SDL2

Thierry Crozat criezy at scummvm.org
Wed Dec 16 21:30:47 CET 2015

Hi Matt,

Thanks for proposing to test. However I remembered that I had a 10.3 laptop gathering dust in a corner so made some tests myself (and urghhh I hate azerty keyboards to write C++ code - you need a five minutes warm up for your fingers before typing a bracket if you don't want to get injured).
Anyway, I found that the easy solution indeed does not work, which I could easily have found before if I had read the reference documentation (NSMenu removeAllItems made its debut in OS X 10.6) And I found that our current code doesn't work well either (the app menu has no name!) :P

My alternative solution seems works with OS 10.3, 10.9 and 10.10 with SDL1.2 and SDL2 though, so I will commit that.

Also the documentation, once more (I really should read it more often) provided the answer regarding the call to NSApplication setAppleMenu:
In Leopard and earlier, apps that tried to construct a menu bar without a nib would get an undesirable stubby application menu that could not be removed. To work around this problem on Leopard, you can call the undocumented setAppleMenu: method and pass it the application menu, like so:
[NSApp setAppleMenu:[[[NSApp mainMenu] itemAtIndex:0] submenu]];
In SnowLeopard, this workaround is unnecessary and should not be used. Under SnowLeopard, the first menu is always identified as the application menu.

It seems to work (despite the documentation saying it should not be called on 10.6+) so I left that call in there. But maybe we should conditionally do the call depending on the system on which ScummVM is executed.


On 16 Dec 2015, at 00:57, Matthew Hoops <clone2727 at gmail.com> wrote:

> Hey Thierry,
> If you have a branch (or branches), I'd be happy to test on 10.2 and 10.4.
> -Matt
> On Dec 15, 2015 7:49 PM, "Thierry Crozat" <criezy at scummvm.org> wrote:
> Hi all (or at least those who care about the OS X port),
> I noticed yesterday that when using SDL2 the menus in the menubar are incorrect. I get an app menu with a "Fullscreen" item, then a menu without a title that is our app menu and finally our Windows menu. The issue is in the file backends/platform/sdl/macosx/appmenu_osx.mm
> First I should note that we use NSApplication setAppleMenu: to set the app menu. But this call actually doesn't do anything for me. It seems that it just uses whatever is the menu at index 0 as app menu. This might be why setAppleMenu was removed from the header file in OS X 10.4 and maybe we could remove this call and the hack that goes with it.
> // Apple removed setAppleMenu from the header files in 10.4,
> // but as the method still exists we declare it ourselves here.
> // Yes, this works :)
> @interface NSApplication(MissingFunction)
> - (void)setAppleMenu:(NSMenu *)menu;
> @end
> But that is secondary, and this call doesn't seem to do any harm anyway.
> The issue is that in our code we do the following to remove the menus set by SDL:
> 	// For some reason [[NSApp mainMenu] removeAllItems] doesn't work and crashes, so we need
> 	// to remove the SDL generated menus one by one
> 	[[NSApp mainMenu] removeItemAtIndex:0];		// Remove application menu
> 	[[NSApp mainMenu] removeItemAtIndex:0];		// Remove "Windows" menu
> But when using SDL2 we actually have three menus, so what I see as app menu is actually the remaining SDL2 menu ("Views", but renamed as "ScummVM" when used as app menu, and which apparently only contains a "Fullscreen" menu item). I have two alternative code that work with both SDL1 and SDL2 on OS X 10.9 and 10.10. But since I cannot test on old systems I would appreciate any feedback on if I should do a change, and which one. Currently I would tend to just add a comment for now and wait until after the next release (which I assume will be using SDL1.2) to make sure I do not break SCummVM on old systems.
> The first things that works for me is to use:
> 	[[NSApp mainMenu] removeAllItems];
> Indeed for me that works and that does not cause a crash. But the comment in our current code worries me.
> The second things that works is:
> 	while ([NSApp mainMenu].numberOfItems > 0) {
> 		[[NSApp mainMenu] removeItemAtIndex:0];
> 	}
> But I don't know if that works on old system (if removeAllItems crashes, I suppose that code could crash as well).
> So does anybody have any though on that?
> Thierry
> ------------------------------------------------------------------------------
> _______________________________________________
> Scummvm-devel mailing list
> Scummvm-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/scummvm-devel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.scummvm.org/pipermail/scummvm-devel/attachments/20151216/6fbf75b0/attachment.html>

More information about the Scummvm-devel mailing list