Browse Source

Fix native traffic light clicks through hidden title bar chrome.

Stop full-size content backgrounds from intercepting close, minimize, and zoom hits, and keep standard window buttons visible with theme-aware chrome.

Co-authored-by: Cursor <cursoragent@cursor.com>
AhtashamShahzad1 1 tháng trước cách đây
mục cha
commit
1200c2791a

+ 4 - 0
gramora/Utilities/AppTheme.swift

@@ -9,6 +9,10 @@ enum AppTheme {
     static let sidebarWidth: CGFloat = 240
     static let headerTopInset: CGFloat = 24
     static let logoMarkSize: CGFloat = 36
+    /// Reserved width for native close / minimize / zoom buttons (top-left).
+    static let trafficLightReservedWidth: CGFloat = 78
+    /// Standard macOS title bar height for hidden-title-bar windows.
+    static let titleBarHeight: CGFloat = 28
     /// Extra top inset so the sidebar logo clears the window traffic lights.
     static let trafficLightClearance: CGFloat = 16
     static let contentPadding: CGFloat = 40

+ 4 - 0
gramora/Utilities/WindowChromeConfigurator.swift

@@ -53,6 +53,10 @@ private struct WindowChromeAccessor: NSViewRepresentable {
             window.title = ""
             window.appearance = NSAppearance(named: isDark ? .darkAqua : .aqua)
             window.backgroundColor = NSColor(AppTheme.background)
+
+            for buttonType: NSWindow.ButtonType in [.closeButton, .miniaturizeButton, .zoomButton] {
+                window.standardWindowButton(buttonType)?.isHidden = false
+            }
         }
 
         private func setupObservers(for window: NSWindow) {

+ 22 - 0
gramora/Utilities/WindowTitleBarAccessory.swift

@@ -0,0 +1,22 @@
+import SwiftUI
+
+/// Lets native window traffic lights receive clicks through SwiftUI layers above them.
+struct WindowTrafficLightPassthrough: View {
+    var body: some View {
+        Color.clear
+            .frame(
+                width: AppTheme.trafficLightReservedWidth,
+                height: AppTheme.titleBarHeight
+            )
+            .allowsHitTesting(false)
+    }
+}
+
+extension View {
+    /// Keeps native traffic lights clickable through full-size content views.
+    func windowTitleBarAccessory() -> some View {
+        overlay(alignment: .topLeading) {
+            WindowTrafficLightPassthrough()
+        }
+    }
+}

+ 7 - 2
gramora/Views/MainView.swift

@@ -41,8 +41,11 @@ struct MainView: View {
             }
             .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
             .frame(maxWidth: .infinity, maxHeight: .infinity)
-            .background(AppTheme.background)
-            .ignoresSafeArea(edges: .top)
+            .background {
+                AppTheme.background
+                    .ignoresSafeArea(edges: .top)
+                    .allowsHitTesting(false)
+            }
             .environment(\.onSettingsTapped, viewModel.showSettings)
             .environment(\.requirePremiumAccess, {
                 if subscriptions.hasPremiumAccess { return true }
@@ -53,7 +56,9 @@ struct MainView: View {
         .background {
             AppTheme.background
                 .ignoresSafeArea(edges: .top)
+                .allowsHitTesting(false)
         }
+        .windowTitleBarAccessory()
         .overlay {
             if viewModel.isShowingPaywall {
                 PaywallView(onClose: viewModel.hidePaywall)

+ 1 - 0
gramora/Views/SidebarView.swift

@@ -42,6 +42,7 @@ struct SidebarView: View {
         .background {
             AppTheme.sidebarBackground
                 .ignoresSafeArea(edges: .top)
+                .allowsHitTesting(false)
         }
     }