import AppKit /// Tiny NSView subclass whose only job is to surface mouse-enter / /// mouse-exit transitions through a closure so the popover can /// reveal hover-only chrome (the floating-piano expand button on /// the visualizer bezel, etc.) without each call site having to /// re-implement a tracking area. final class HoverTrackingView: NSView { var onHoverChanged: ((Bool) -> Void)? private var trackingArea: NSTrackingArea? override func updateTrackingAreas() { super.updateTrackingAreas() if let trackingArea { removeTrackingArea(trackingArea) } let area = NSTrackingArea( rect: bounds, options: [.mouseEnteredAndExited, .activeAlways, .inVisibleRect], owner: self, userInfo: nil ) addTrackingArea(area) self.trackingArea = area } override func mouseEntered(with event: NSEvent) { super.mouseEntered(with: event) onHoverChanged?(true) } override func mouseExited(with event: NSEvent) { super.mouseExited(with: event) onHoverChanged?(false) } }