user519179
user519179

Reputation:

How to make NSWindow's toggleFullscreen behave synchronously (blocking)

Most NSWindow stuff is blocking except toggleFullScreen (among a few others) which is asynchronous and what's worse, it can fail too. This, coupled with a fact that calling close() on a fullscreen window is buggy[1], makes me want to wait on the window to enter/exit fullscreen before doing anything else (eg. I'd like to wait for the window to exit fullscreen before calling close()).

What would be a good way to do that (without polling on a timer which would be the obvious answer) ?

[1] it doesn't exit fullscreen mode leaving you staring at an empty gray screen, and, if you create another window after the first one is closed it will have the fullscreen flag set -- which surfaces the fact that this is actually a global flag under the hood.

Upvotes: 0

Views: 773

Answers (2)

Daij-Djan
Daij-Djan

Reputation: 50099

how it is:

  1. begin entering fullscreen

  2. windowDidEnterFullScreen is called when it is done

now you want to wait.

1b. have a boolean that keeps the state. (_windowIsInFullscreen). Set it to NO before, and to YES in the delegate message

1c. wait:

 while(!_windowIsInFullscreen) {
                    [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:.5]];
            NSLog(@"Polling...");
 }

this is how modal stuff works too (IMHO this is bad though ;) async rules -- but that is personal preference)

Upvotes: 0

Lucas Derraugh
Lucas Derraugh

Reputation: 7049

Although I'm not sure what the actual issue is, I think I can offer some advice.

If you want to prevent the closing of a window between full screen and windowed mode, you can simply make a check against the delegate methods of NSWindow. NSWindowDelegate provides methods such as -windowDidExitFullScreen: and -windowWillExitFullScreen: that should inform you when the window is going between states. Lastly, you can block the closing of the window with -windowShouldClose:.

Upvotes: 0

Related Questions