Question

I created my project from the Xcode template for non-document based Cocoa Application.

I have a custom NSWindowController that, after being instantiated on startup, takes possession of the default window (defined in MainMenu.xib).

If I leave the app delegate's window as it is, I can toggle fullscreen mode with command-F (set to -toggleFullscreen: in a menu item), or I can exit from fullscreen by pressing ESC.

Once I set my window controller as the window's delegate (I need this to do some OpenGL adjustments on enter/exit fullscreen, etc.), I can still enter fullscreen by pressing command+F, but I can no longer exit fullscreen (save for command+tab to another app, or command+Q).

Also, the Apple docs mention setting the menu action to -toggleFullscreen: and the target to nil. How is this last part done in Interface Builder? (I connected the action to First Responder's -toggleFullscreen:)

What should I do?

Was it helpful?

Solution

So, I found the problem (posting the question in SO seems to be a condition to finding the solution, always...)

The offending line was not setting the delegate, but what I was doing to the window after entering fullscreen mode. In particular, as soon as I commented out the following line [window setStyleMask:NSBorderlessWindowMask]; in the code below:

- (void) windowDidEnterFullScreen:(NSNotification*) notification
{
    NSWindow* window = [self window];

    NSRect mainDisplayRect = [[NSScreen mainScreen] frame];
    [window setStyleMask:NSBorderlessWindowMask];
    [window setContentSize:mainDisplayRect.size];
    [window setLevel:NSMainMenuWindowLevel + 1];
    [window makeKeyAndOrderFront:self];

    NSRect windowFrame = [window frame];
    windowFrame.origin.x = 0;
    windowFrame.origin.y = 0;
    [window setFrame:windowFrame display:YES];
}

...the expected enter/exit fullscreen mode behaviour was fixed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top