Search code examples
cocoafullscreennswindowswift4.2nstoolbar

Hide NSToolbar in fullscreen


I'm making a Cocoa app, with a hidden unified NSToolbar and Titlebar. I've done so by adding a toolbar in the Window Controller and setting all the options to make this invisible and keep the 3 colored buttons. It works great in a normal window, but if I put this window in fullscreen, it shows an empty Toolbar at the top.

How to make this toolbar also transparent in fullscreen?

It can be possible as it is how it works in the new Mac AppStore in macOS Mojave (there is a hidden toolbar which is still hidden in fullscreen and only appear when the mouse is put at the top of the screen).

Bonus: I have enabled isMovableByWindowBackgroundable but is there an option to toggle the "maximize" action while double clicking on the window background like it normally works for titlebar?

Here's pictures:

How it looks with a transparent toolbar

How it looks in fullscreen, the toolbar is opaque


Solution

  • You can achieve the same effect as the Mac App Store by setting the NSWindow's delegate and implementing:

    func window(_ window: NSWindow, willUseFullScreenPresentationOptions proposedOptions: NSApplication.PresentationOptions = []) -> NSApplication.PresentationOptions {
        return [.autoHideToolbar, .autoHideMenuBar, .fullScreen]
    }
    

    This will hide the toolbar and the menubar while in fullscreen appearing only when the mouse is at the top of the screen. Updates to the view may need to be implemented to update content but that is optional.