This is the effect I am after, demonstrated in the QuickTime Player application.
As you move the mouse over the Window. The title bar and controls fade in. When you move away from the Window. The title bar and controls fade out.
Since I am using SwiftUI my original thoughts were to place an onHover action to the ContentView and then use the AppDelegate to get access to the Window and toggle these settings:
window.standardWindowButton(.closeButton)?.isHidden = true
window.standardWindowButton(.miniaturizeButton)?.isHidden = true
window.standardWindowButton(.zoomButton)?.isHidden = true
window.titlebarAppearsTransparent = true
It does not animate, but it will hide and show when moving the cursor in and out of the Window. However. When you move your mouse to the title bar it will register that as hovering out as well. Which will cause the title bar to hide. Which, in turn, fires the hover in event, showing the title bar again. Which, in turn, fires the hover out event, hiding the title bar and this repeat to a glitching effect.
[EDIT: Sat 9 Dec 14:05h]
I now have the effect, but there are two problems:
- When the Window resizes it won't update the tracking rect.
- It does not fade in, fade out.
@Observable class AppDelegate: NSObject, NSApplicationDelegate {
var window: NSWindow?
func applicationDidFinishLaunching(_ notification: Notification) {
self.window = NSApplication.shared.windows.first
if let contentView = window?.contentView {
contentView.addTrackingRect(contentView.bounds, owner: self, userData: nil, assumeInside: false)
}
}
@objc(mouseEntered:) func mouseEntered(with event: NSEvent) {
self.window?.titleVisibility = .visible
self.window?.titlebarAppearsTransparent = false
self.window?.standardWindowButton(.closeButton)?.isHidden = false
self.window?.standardWindowButton(.miniaturizeButton)?.isHidden = false
self.window?.standardWindowButton(.zoomButton)?.isHidden = false
}
@objc(mouseExited:) func mouseExited(with event: NSEvent) {
self.window?.titleVisibility = .hidden
self.window?.titlebarAppearsTransparent = true
self.window?.standardWindowButton(.closeButton)?.isHidden = true
self.window?.standardWindowButton(.miniaturizeButton)?.isHidden = true
self.window?.standardWindowButton(.zoomButton)?.isHidden = true
}
}
