2
votes

I'm trying to go fullscreen with a second window on a second screen, tho I'm still seeing the menu bar.

This is my code:

let second_screen = NSScreen.screens()?[1]
let window = NSWindow(contentRect: (second_screen?.frame)!, styleMask: .fullScreen, backing: .buffered, defer: true, screen: second_screen)
self.window_controller = NSWindowController(window: window)
window.collectionBehavior = .fullScreenAuxiliary
window_controller?.showWindow(self)
window.toggleFullScreen(true)

Has anyone had any luck with this?

Edit 1:

I added this line:

NSApp.presentationOptions = [.fullScreen, .hideDock, .autoHideMenuBar]

and I got this warning:

setPresentationOptions called with NSApplicationPresentationFullScreen when there is no visible fullscreen window; this call will be ignored.

Edit 2:

I switched to this method:

HOWTO: Create a Locked Down Fullscreen Cocoa Application and Implement NSLayoutConstraints using Swift

let presOptions: NSApplicationPresentationOptions = [.hideDock, .hideMenuBar]
let optionsDictionary = [NSFullScreenModeApplicationPresentationOptions: NSNumber(value: presOptions.rawValue)]
self.fullscreen_view?.enterFullScreenMode((NSScreen.screens()?[1])!, withOptions: optionsDictionary)

The view goes fullscreen tho not showing the content, just grey.

Edit 3:

I turned NSFullScreenModeAllScreens off and now it kinda works:

let optionsDictionary = [NSFullScreenModeApplicationPresentationOptions: NSNumber(value: presOptions.rawValue), NSFullScreenModeAllScreens: false]

The only thing now is that the menu bar and dock don't show up on the first screen.

1
tried all the answers there without luck on 10.12Heestand XYZ

1 Answers

0
votes

For me, enterFullScreenMode seems to only work properly if called after the view "is shown" already.

It works if I call it inside the func applicationDidBecomeActive(_ notification: Notification) { /* here */ } (or also by using a Timer.scheduledTimer).