Hide NSToolbar in fullscreen

1.8k Views Asked by At

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

2

There are 2 best solutions below

2
On BEST ANSWER

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.

6
On

I assume what you are looking for is a window condiguration like this.

window!.titleVisibility = .hidden
window!.titlebarAppearsTransparent = true
window!.styleMask = [window!.styleMask,  NSWindow.StyleMask.fullSizeContentView]

You would add this code in your NSWindowControllers windodDidLoad()

In the Mac App Store App I don’t see any toolbar. If you don’t want to display a toolbar you don’t need to add a NSToolbar to the window.

EDIT:

To get the view and change the color you can use the code below in windowDidLoad. Of course there is some more fine-tuning required to get it 100% like the Mac App Store window and its not a good idea to use a fixed color.

let button = window?.standardWindowButton(NSWindow.ButtonType.closeButton)
let containerView = button?.superview?.superview // NSTitlebarContainerView
containerView?.layer?.backgroundColor = CGColor.init(gray: 0.9, alpha: 1.0)

Hope this helps.