|
@@ -0,0 +1,26 @@
|
|
|
|
|
+import AppKit
|
|
|
|
|
+import SwiftUI
|
|
|
|
|
+
|
|
|
|
|
+private enum TrafficLightHitRegion {
|
|
|
|
|
+ static let size = NSSize(width: 78, height: 32)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/// Passes mouse events in the traffic-light region through to the native window controls.
|
|
|
|
|
+final class MainHostingView<Content: View>: NSHostingView<Content> {
|
|
|
|
|
+ override func hitTest(_ point: NSPoint) -> NSView? {
|
|
|
|
|
+ if isTrafficLightPoint(point) {
|
|
|
|
|
+ return nil
|
|
|
|
|
+ }
|
|
|
|
|
+ return super.hitTest(point)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private func isTrafficLightPoint(_ point: NSPoint) -> Bool {
|
|
|
|
|
+ let trafficLightArea = NSRect(
|
|
|
|
|
+ x: 0,
|
|
|
|
|
+ y: isFlipped ? 0 : bounds.height - TrafficLightHitRegion.size.height,
|
|
|
|
|
+ width: TrafficLightHitRegion.size.width,
|
|
|
|
|
+ height: TrafficLightHitRegion.size.height
|
|
|
|
|
+ )
|
|
|
|
|
+ return trafficLightArea.contains(point)
|
|
|
|
|
+ }
|
|
|
|
|
+}
|