How to hide fullscreen window header line in MacOS app?

Viewed 266

My problem is header of window in fullscreen mode.

When I move cursor to the top of screen I see the following:

enter image description here

But I want to see the following:

enter image description here

Hiding of buttons is not a problem:

wnd.standardWindowButton(NSWindow.ButtonType.closeButton)?.isHidden = true
wnd.standardWindowButton(NSWindow.ButtonType.miniaturizeButton)?.isHidden = true
wnd.standardWindowButton(NSWindow.ButtonType.zoomButton)?.isHidden = true

but how to hide the line?

Google say nothing about this =(

Maybe there is some sort of additional "safe zone area" that must be disabled in another way?


WindowGroup {
    SomeView()
        .edgesIgnoringSafeArea(.top)

}
.windowStyle( HiddenTitleBarWindowStyle() )

hides only titlebar from windowed mode, but not from fullscreen

The code:

 NSApp?.mainWindow?.styleMask.insert(NSWindow.StyleMask.unifiedTitleAndToolbar)        
 NSApp?.mainWindow?.styleMask.insert(NSWindow.StyleMask.fullSizeContentView)        
 NSApp?.mainWindow?.styleMask.insert(NSWindow.StyleMask.titled)
NSApp?.mainWindow?.toolbar?.isVisible = false
NSApp?.mainWindow?.titleVisibility = .hidden
NSApp?.mainWindow?.titlebarAppearsTransparent = true

also do nothing with header line in fullscreen mode

2 Answers

This seems to be a bug. There is no workaround found for this issue (just file a bug to Apple), but you might find useful to disable menubar at all by returning only [.fullscreen] in below callback of window delegate (if you have access to NSWindow instance) and add, say, own floating control panel on full-screen (just idea).

class WindowDelegate: NSObject, NSWindowDelegate {
    func window(_ window: NSWindow, willUseFullScreenPresentationOptions proposedOptions: NSApplication.PresentationOptions = []) -> NSApplication.PresentationOptions {
        return [.fullScreen]
    }
}

Note: alternate way to change application options is via NSApp (just in case), like

NSApp.presentationOptions = [.hideMenuBar, .hideDock]

To remove the title bar entirely, use NSWindow.StyleMask.Borderless.

Note, by default this also disables the canBecomeKey and canBecomeMain properties which you will need to change back to true or else various other things won't work properly (for example, keyboard input).

I'm not sure if an existing window can become a borderless window. I vaguely recall something about having to create a new window (or enable the flag in the storyboard).

You also won't have a full screen button anymore, so entering and exiting will have to be done programatically.

Related