my two cents about using different approaches, integrating the previous nice solution from "shufflingb".
Googling around and making some tests, I assemble another solution based on AppDelegate method.
Hoping can help, I did prepare a project in gitHub with both approaches using a "const" (see below "let") to switch between approaches,
(https://github.com/ingconti/HideMacOsWindowButtons)
Here just some code for AppDelegate approach:
As a last side note, you cannot in any way to use it under Catalyst.
class MyAppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ aNotification: Notification) {
// 1st method:
if USE_APP_DELEGATE{
customize(window: NSApplication.shared.windows.first)
}
}
}
@main
struct HideMacOsWindowButtonsApp: App {
@NSApplicationDelegateAdaptor private var appDelegate: MyAppDelegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
customise will do as per previous code:
//let USE_APP_DELEGATE = true
let USE_APP_DELEGATE = false
import AppKit
let ActiveNotif = NSApplication.didBecomeActiveNotification
typealias Window = NSWindow
fileprivate var count = 0
func customize(window: Window?) {
count+=1
print(USE_APP_DELEGATE ? "using App delegate" : "using notification", count)
guard let window = window else{
return
}
//window.titleVisibility = .hidden
//window.titlebarAppearsTransparent = true
window.isOpaque = false
window.backgroundColor = NSColor.green
window.standardWindowButton(.zoomButton)?.isHidden = true
window.standardWindowButton(.closeButton)?.isHidden = true
window.standardWindowButton(.miniaturizeButton)?.isHidden = true
}
I did add:
fileprivate var count = 0
just to verify no multiple calls (onlyy for debug).