Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to close a Full-Screen mode NSWindow programmatically?

My application has two windows(main and video) and both can enter the Full-Screen mode independently. And the main window has a button to toggle the video window's visibility. When the video window is visible, the button simply sends close message like this:

[theVideoWindow close];

It works perfectly when the video window is not in the Full-Screen mode.

But when the video window is running in the Full-Screen mode, the window looks like being ordered out (closed), but it is still alive (like an invisible window) and accepts mouse event. The user cannot interact with other applications because the invisible window eats up all the mouse events and cannot close it because the title bar and menu are gone.

Are there any best practices to close a Full-Screen mode window programmatically other than exiting from the Full-Screen mode first and then closing it in NSWindowDidExitFullScreenNotification notification handler?

Thanks in advance.


It seems to be my mistake. The other developer, explicitly send orderFront: in the NSWindowDidExitFullScreenNotification notification handler to make the window visible just after exiting from the Full-Screen mode and it made the window was still alive.

like image 450
YoonHo Avatar asked Dec 21 '15 20:12

YoonHo


People also ask

How do I toggle full screen mode with preferredlaunchwindowingmode?

public: virtual void ExitFullScreenMode () = ExitFullScreenMode; This example shows how to toggle full-screen mode and set the PreferredLaunchWindowingMode property. <Button x:Name="ToggleFullScreenModeButton" Content="Toggle full screen" Click="ToggleFullScreenModeButton_Click">

How to exit full screen mode on Windows 10?

You can also press the F11 key on your keyboard to exit full screen on Windows 10. The F11 key is a function key and is often used to enter and exit full-screen mode. Aside from the function, it can allow you to quickly create a chart from selected data in Microsoft Excel.

How to fix window is open in full screen but not element?

As you can see the window is opened in full screen, but not the element. To fix this, you must add a custom CSS style as follows. This is a hot fix which is applicable only to Google Chrome.

How to preserve full screen mode when user restarts the app?

} } } To preserve full-screen mode when a user restarts the app, set PreferredLaunchWindowingMode to FullScreen if the call to TryEnterFullScreenMode returns true. When you call ExitFullScreenMode, you should set PreferredLaunchWindowingMode back to Auto or PreferredLaunchViewSize.


2 Answers

On my app, I check if window is on Fullscreen and then I use ToogleFullScreen method

- (BOOL)isFullScreen {
     return ((self.window.styleMask & NSFullScreenWindowMask) == NSFullScreenWindowMask);
}

if([self isFullscreen]) {
     [self.window toggleFullScreen:nil];
}
like image 161
93sauu Avatar answered Oct 18 '22 12:10

93sauu


@Saul's solution in Swift 4:

func isFullScreen() -> Bool {
    guard let window = view.window else { return false }
    return window.styleMask.contains(.fullScreen)
}

if isFullscreen() {
    view.window?.toggleFullScreen(nil)
}
like image 33
hyouuu Avatar answered Oct 18 '22 12:10

hyouuu