Adding a "Full Screen" menu item on Mac OS X?

Ask for help with ScummVM problems

Moderator: ScummVM Team

Post Reply
User avatar
eisnerguy1
Got a warning
Posts: 42
Joined: Mon Feb 27, 2012 10:06 am

Adding a "Full Screen" menu item on Mac OS X?

Post by eisnerguy1 »

So, I was wondering if there was a way to add a "Full Screen" menu item on Mac OS X? I know that the file I would need to edit is:
/backends/platform/sdl/macosx/appmenu_osx.mm

but, every thing I've tried only produces a greyed-out menu item. Here's a few examples of the code I've tried:

Code: Select all

    // Add "Full Screen" menu item
    nsString = constructNSStringFromCString(_("Full Screen"), stringEncoding);
    menuItem = [[NSMenuItem alloc] initWithTitle:nsString action:@selector(fullscreen:) keyEquivalent:@"\r"];
    [setKeyEquivalentModifierMask:NSAlternateKeyMask | NSCommandKeyMask];
    [windowMenu addItem:menuItem];
    [nsString release];



    // Add "Full Screen" menu item
	nsString = constructNSStringFromCString(_("Full Screen"), stringEncoding);
	menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:nsString action:@selector(fullscreen:) keyEquivalent:@“\r”];
	[menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask)];
Any help/suggestions would be greatly appreciated.
User avatar
criezy
ScummVM Developer
Posts: 950
Joined: Sat Sep 23, 2006 10:41 am
Location: West Sussex, UK

Post by criezy »

I can see several issues with your code. The first one is that the action 'fullscreen:' does probably not exist. If you look at the documentation of NSWindow you will see there is one called 'toggleFullScreen:' but if you try to use it you will also need to enable fullscreen for the NSWindow (because SDL does not do it) as otherwise the menu item will still be disabled. Here is a code example to do that, but it probably does not work in this case:

Code: Select all

NSWindow* window = [NSApp mainWindow];
NSWindowCollectionBehavior behavior = [window collectionBehavior];
behavior = behavior | NSWindowCollectionBehaviorFullScreenPrimary;
[window setCollectionBehavior:behavior];

nsString = constructNSStringFromCString(_("Fullscreen"), stringEncoding);
menuItem = [[NSMenuItem alloc] initWithTitle:nsString action:@selector(toggleFullScreen:) keyEquivalent:@""];
[windowMenu addItem:menuItem];
[nsString release];
There are two reasons why I don't think it will work:
1- Setting the NSWindowCollectionBehaviorFullScreenPrimary when creating the menu is probably too early. We would need to do it a bit later.
2- Using the NSWindow toggleFullScreen is unlikely to be what you want.

What you probably need is to use the SDL fullscreen toggle, which is abstracted in the SCummVM class OSystem. To do that you will need to declare a new action that toggles the fullscreen using the OSystem API. Below is a code example where I do that by declaring a new class that inherit from NSMenuItem and contains the action we need. Hopefully that code should work.

First toward the top of the file (for example just after the NSApplication(MissingFunction) hack) declare the new class:

Code: Select all

@interface FullscreenMenuItem : NSMenuItem {
}
- (IBAction) ToggleFullScreenMode;
@end

@implementation FullscreenMenuItem
- (IBAction) ToggleFullScreenMode {
	g_system->beginGFXTransaction();
	g_system->setFeatureState(OSystem::kFeatureFullscreenMode, !g_system->getFeatureState(OSystem::kFeatureFullscreenMode));
	g_system->endGFXTransaction();
}
@end
And now you can create the menu item this way:

Code: Select all

nsString = constructNSStringFromCString(_("Fullscreen"), stringEncoding);
menuItem = [[FullscreenMenuItem alloc] initWithTitle:nsString action:@selector(ToggleFullScreenMode) keyEquivalent:@""];
[menuItem setTarget:menuItem];
[windowMenu addItem:menuItem];
[nsString release];
Note that I create the menu item as a FullscreenMenuItem (the class I defined) and not as a NSMenuItem, and that I set itself as a target so that when triggered it look for the action in the FullscreenMenuItem.

If something is not clear in my explanations, don't hesitate to ask.
And out of curiosity, why are you trying to add this menu item?
lillemask
Posts: 21
Joined: Thu Jan 23, 2014 2:05 pm

Post by lillemask »

It would perhaps make more sense to make the fullscreen (green) window button work properly. At least for me on El Capitan it tends to crash Scummvm.
User avatar
criezy
ScummVM Developer
Posts: 950
Joined: Sat Sep 23, 2006 10:41 am
Location: West Sussex, UK

Post by criezy »

I agree with you.
But sadly I don't know any easy way to properly handle the fullscreen mode on recent OS X systems with SDL 1.2. I just did a test on OS X 10.9 and I get a crash as well when trying to go fullscreen (which was what I expected). However the green button works and does not crash (but on that OS it does not go fullscreen - it merely maximises the window keeping the title bar and menu visible).

I also made a quick test with SDL 2 on my OS X 10.10 laptop (and with this one the green button does go fullscreen) and it works properly for me, without crashing. I even get a Fullscreen menu item without changing anything in the code (however our custom menu has some issue - so we would need to fix that). So hopefully this issue will be solved once we switch to SDL 2 for ScummVM releases. However don't hold your breath, as far as I know there is no plan to do it in the near future (for official releases that it - you can already compile yourself ScummVM with SDL2).
User avatar
rootfather
ScummVM Lead
Posts: 181
Joined: Tue Mar 31, 2015 11:59 am
Location: Germany
Contact:

Post by rootfather »

Slightly off topic, but regarding the transition to SDL2 in a "future far, far away":

Are there any plans to set up SDL2 targets for Win32/64, Mac and Linux on the ScummVM Buildbot?
User avatar
LordHoto
ScummVM Developer
Posts: 1029
Joined: Sun Oct 30, 2005 3:58 pm
Location: Germany

Post by LordHoto »

rootfather wrote:Slightly off topic, but regarding the transition to SDL2 in a "future far, far away":

Are there any plans to set up SDL2 targets for Win32/64, Mac and Linux on the ScummVM Buildbot?
Yes.
Post Reply