Hide Traffic Light Buttons in NSWindow Without Removing Resize Functionality
I noticed that in macOS’s dark mode, a window without a visible title bar won’t draw a light border. It will draw a dark/black border, unlike all the other windows, and thus be a lot less visible than it needs to be.
So for a floating helper window, I had to make the title bar visible, and then hide all traffic light buttons in the window’s top-left corner:
class WindowController: NSWindowController {
override func windowDidLoad() {
super.windowDidLoad()
// Hide the textual window title.
self.window?.titleVisibility = .hidden
self.window?.styleMask = []
// We need a textured window to get the correct border color.
self.window?.styleMask.insert(.texturedBackground)
// Making the window resizable will show the traffic lights automatically ...
self.window?.styleMask.insert(.resizable)
// ... so hide all traffic light buttons manually:
self.window?.standardWindowButton(.closeButton)?.isHidden = true
self.window?.standardWindowButton(.miniaturizeButton)?.isHidden = true
self.window?.standardWindowButton(.zoomButton)?.isHidden = true
self.window?.standardWindowButton(.fullScreenButton)?.isHidden = true
}
}
Until today, I didn’t know that NSWindow
even has standardWindowButton(_:)
that you can use to get to the traffic lights!
With this setup, you get resizability of the window, which would usually result in at least 1 traffic light to show, and a full-sized content view without any visible title bar at all.