Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed bug 4415 - SDL menu bar is nonstandard on Mac
foo.null

I'm on macOS 10.14 and I think I'm using or around SDL 2.0.9. This is about the menu bar that SDL sets up which looks like:

<App Name> <Window> <View>

1. View menu never proceeds after the Window menu in any Mac application (it is always before).
2. For SDL, the only purpose of the View menu is for a single fullscreen menu item, which is not justifiable enough to reserve space for a menu. The View menu should thus be removed, and the full screen menu item should be added at the end inside of Window's menu. See built in apps like Dictionary, Chess, App Store (on 10.14) that do this.
3. SDL should add a "Close" menu item to the Window's submenu, and it should be the first item. Its key equivalent should map to command w. Without this, you cannot close the game window via this shortcut, and you cannot close the app's About window via this shortcut.
4. Apps typically use "Enter Full Screen" or "Exit Full Screen" depending on context, not "Toggle Full Screen" which is less user friendly -- I personally care about this point the least.
  • Loading branch information
slouken committed Dec 8, 2018
1 parent 70ce0f2 commit 1c9595b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
33 changes: 13 additions & 20 deletions src/video/cocoa/SDL_cocoaevents.m
Expand Up @@ -275,7 +275,6 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification
NSMenu *appleMenu;
NSMenu *serviceMenu;
NSMenu *windowMenu;
NSMenu *viewMenu;
NSMenuItem *menuItem;
NSMenu *mainMenu;

Expand Down Expand Up @@ -342,9 +341,22 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification
windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];

/* Add menu items */
[windowMenu addItemWithTitle:@"Close" action:@selector(performClose:) keyEquivalent:@"w"];

[windowMenu addItemWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];

[windowMenu addItemWithTitle:@"Zoom" action:@selector(performZoom:) keyEquivalent:@""];

/* Add the fullscreen toggle menu option, if supported */
if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6) {
/* Cocoa should update the title to Enter or Exit Full Screen automatically.
* But if not, then just fallback to Toggle Full Screen.
*/
menuItem = [[NSMenuItem alloc] initWithTitle:@"Toggle Full Screen" action:@selector(toggleFullScreen:) keyEquivalent:@"f"];
[menuItem setKeyEquivalentModifierMask:NSEventModifierFlagControl | NSEventModifierFlagCommand];
[windowMenu addItem:menuItem];
[menuItem release];
}

/* Put menu into the menubar */
menuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
Expand All @@ -355,25 +367,6 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification
/* Tell the application object that this is now the window menu */
[NSApp setWindowsMenu:windowMenu];
[windowMenu release];


/* Add the fullscreen view toggle menu option, if supported */
if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6) {
/* Create the view menu */
viewMenu = [[NSMenu alloc] initWithTitle:@"View"];

/* Add menu items */
menuItem = [viewMenu addItemWithTitle:@"Toggle Full Screen" action:@selector(toggleFullScreen:) keyEquivalent:@"f"];
[menuItem setKeyEquivalentModifierMask:NSEventModifierFlagControl | NSEventModifierFlagCommand];

/* Put menu into the menubar */
menuItem = [[NSMenuItem alloc] initWithTitle:@"View" action:nil keyEquivalent:@""];
[menuItem setSubmenu:viewMenu];
[[NSApp mainMenu] addItem:menuItem];
[menuItem release];

[viewMenu release];
}
}

void
Expand Down
5 changes: 5 additions & 0 deletions src/video/cocoa/SDL_cocoawindow.m
Expand Up @@ -1356,6 +1356,11 @@ - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent
return SDL_SetError("%s", [[e reason] UTF8String]);
}

/* By default, don't allow users to make our window tabbed in 10.12 or later */
if ([nswindow respondsToSelector:@selector(setTabbingMode:)]) {
[nswindow setTabbingMode:NSWindowTabbingModeDisallowed];
}

if (videodata->allow_spaces) {
SDL_assert(floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6);
SDL_assert([nswindow respondsToSelector:@selector(toggleFullScreen:)]);
Expand Down

0 comments on commit 1c9595b

Please sign in to comment.