Преглед на файлове

Unify macOS title bar chrome and remove centered title labels.

Use full-size transparent title bars in the main and browser windows, align top content to safe areas around traffic lights, and rely on hidden window titles without custom centered labels.

Made-with: Cursor
huzaifahayat12 преди 10 часа
родител
ревизия
6374cb9933
променени са 2 файла, в които са добавени 16 реда и са изтрити 62 реда
  1. 1 1
      classroom_app/Base.lproj/Main.storyboard
  2. 15 61
      classroom_app/ViewController.swift

+ 1 - 1
classroom_app/Base.lproj/Main.storyboard

@@ -684,7 +684,7 @@
684 684
             <objects>
685 685
                 <windowController id="B8D-0N-5wS" sceneMemberID="viewController">
686 686
                     <window key="window" title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" id="IQv-IB-iLA">
687
-                        <windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
687
+                        <windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES" fullSizeContentView="YES"/>
688 688
                         <windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
689 689
                         <rect key="contentRect" x="196" y="240" width="480" height="270"/>
690 690
                         <rect key="screenRect" x="0.0" y="0.0" width="1680" height="1027"/>

+ 15 - 61
classroom_app/ViewController.swift

@@ -249,7 +249,6 @@ final class ViewController: NSViewController {
249 249
     private var zoomJoinModeByView = [ObjectIdentifier: ZoomJoinMode]()
250 250
     private var zoomJoinModeViews: [ZoomJoinMode: NSView] = [:]
251 251
     private var settingsActionByView = [ObjectIdentifier: SettingsAction]()
252
-    private weak var centeredTitleLabel: NSTextField?
253 252
     private var paywallWindow: NSWindow?
254 253
     private let paywallContentWidth: CGFloat = 520
255 254
     private let launchWindowLeftOffset: CGFloat = 80
@@ -432,6 +431,8 @@ final class ViewController: NSViewController {
432 431
         applyWindowTitle(for: selectedSidebarPage)
433 432
         guard let window = view.window else { return }
434 433
 
434
+        configureUnifiedTitlebar(for: window)
435
+
435 436
         // Ensure launch size is applied even when macOS tries to restore prior window state.
436 437
         window.isRestorable = false
437 438
         window.setFrameAutosaveName("")
@@ -453,7 +454,6 @@ final class ViewController: NSViewController {
453 454
             }
454 455
 
455 456
             window.minSize = window.frameRect(forContentRect: NSRect(origin: .zero, size: self.launchMinContentSize)).size
456
-            self.installCenteredTitleIfNeeded(on: window)
457 457
         }
458 458
     }
459 459
 
@@ -1876,6 +1876,12 @@ private extension ViewController {
1876 1876
         return b
1877 1877
     }
1878 1878
 
1879
+    private func configureUnifiedTitlebar(for window: NSWindow) {
1880
+        window.styleMask.insert(.fullSizeContentView)
1881
+        window.titlebarAppearsTransparent = true
1882
+        window.titleVisibility = .hidden
1883
+    }
1884
+
1879 1885
     private func applyWindowTitle(for page: SidebarPage) {
1880 1886
         let title: String
1881 1887
         switch page {
@@ -1891,32 +1897,6 @@ private extension ViewController {
1891 1897
             title = "Settings"
1892 1898
         }
1893 1899
         view.window?.title = title
1894
-        centeredTitleLabel?.stringValue = title
1895
-    }
1896
-
1897
-    private func installCenteredTitleIfNeeded(on window: NSWindow) {
1898
-        guard centeredTitleLabel == nil else { return }
1899
-        guard let titlebarView = window.standardWindowButton(.closeButton)?.superview else { return }
1900
-
1901
-        let label = NSTextField(labelWithString: window.title)
1902
-        label.translatesAutoresizingMaskIntoConstraints = false
1903
-        label.alignment = .center
1904
-        label.font = NSFont.titleBarFont(ofSize: 0)
1905
-        label.textColor = .labelColor
1906
-        label.lineBreakMode = .byTruncatingTail
1907
-        label.maximumNumberOfLines = 1
1908
-
1909
-        titlebarView.addSubview(label)
1910
-
1911
-        NSLayoutConstraint.activate([
1912
-            label.centerXAnchor.constraint(equalTo: titlebarView.centerXAnchor),
1913
-            label.centerYAnchor.constraint(equalTo: titlebarView.centerYAnchor),
1914
-            label.leadingAnchor.constraint(greaterThanOrEqualTo: titlebarView.leadingAnchor, constant: 90),
1915
-            label.trailingAnchor.constraint(lessThanOrEqualTo: titlebarView.trailingAnchor, constant: -90)
1916
-        ])
1917
-
1918
-        window.titleVisibility = .hidden
1919
-        centeredTitleLabel = label
1920 1900
     }
1921 1901
 
1922 1902
     private func updateSidebarAppearance() {
@@ -2011,7 +1991,7 @@ private extension ViewController {
2011 1991
 
2012 1992
         NSLayoutConstraint.activate([
2013 1993
             titleRow.leadingAnchor.constraint(equalTo: sidebar.leadingAnchor, constant: 16),
2014
-            titleRow.topAnchor.constraint(equalTo: sidebar.topAnchor, constant: 24),
1994
+            titleRow.topAnchor.constraint(equalTo: sidebar.safeAreaLayoutGuide.topAnchor, constant: 24),
2015 1995
             titleRow.trailingAnchor.constraint(lessThanOrEqualTo: sidebar.trailingAnchor, constant: -16),
2016 1996
 
2017 1997
             menuStack.leadingAnchor.constraint(equalTo: sidebar.leadingAnchor, constant: 12),
@@ -2113,7 +2093,7 @@ private extension ViewController {
2113 2093
         NSLayoutConstraint.activate([
2114 2094
             authBar.leadingAnchor.constraint(equalTo: panel.leadingAnchor, constant: 28),
2115 2095
             authBar.trailingAnchor.constraint(equalTo: panel.trailingAnchor, constant: -28),
2116
-            authBar.topAnchor.constraint(equalTo: panel.topAnchor, constant: 26),
2096
+            authBar.topAnchor.constraint(equalTo: panel.safeAreaLayoutGuide.topAnchor, constant: 26),
2117 2097
 
2118 2098
             host.leadingAnchor.constraint(equalTo: panel.leadingAnchor),
2119 2099
             host.trailingAnchor.constraint(equalTo: panel.trailingAnchor),
@@ -6919,11 +6899,13 @@ private final class InAppBrowserWindowController: NSWindowController {
6919 6899
     init() {
6920 6900
         let browserWindow = NSWindow(
6921 6901
             contentRect: NSRect(origin: .zero, size: Self.defaultContentSize),
6922
-            styleMask: [.titled, .closable, .miniaturizable, .resizable],
6902
+            styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView],
6923 6903
             backing: .buffered,
6924 6904
             defer: false
6925 6905
         )
6926 6906
         browserWindow.title = "Browser"
6907
+        browserWindow.titlebarAppearsTransparent = true
6908
+        browserWindow.titleVisibility = .hidden
6927 6909
         browserWindow.isRestorable = false
6928 6910
         browserWindow.setFrameAutosaveName("")
6929 6911
         browserWindow.minSize = browserWindow.frameRect(forContentRect: NSRect(origin: .zero, size: Self.minimumContentSize)).size
@@ -6967,7 +6949,6 @@ private final class InAppBrowserContainerViewController: NSViewController, WKNav
6967 6949
     private var reloadStopButton: NSButton!
6968 6950
     private var goButton: NSButton!
6969 6951
     private var progressBar: NSProgressIndicator!
6970
-    private weak var centeredTitleLabel: NSTextField?
6971 6952
     private weak var titlebarButtonsContainer: NSStackView?
6972 6953
     private weak var titlebarBackButton: NSButton?
6973 6954
     private weak var titlebarForwardButton: NSButton?
@@ -7071,11 +7052,11 @@ private final class InAppBrowserContainerViewController: NSViewController, WKNav
7071 7052
         NSLayoutConstraint.activate([
7072 7053
             toolbar.leadingAnchor.constraint(equalTo: root.leadingAnchor),
7073 7054
             toolbar.trailingAnchor.constraint(equalTo: root.trailingAnchor),
7074
-            toolbar.topAnchor.constraint(equalTo: root.topAnchor),
7055
+            toolbar.topAnchor.constraint(equalTo: root.safeAreaLayoutGuide.topAnchor),
7075 7056
 
7076 7057
             bar.leadingAnchor.constraint(equalTo: root.leadingAnchor),
7077 7058
             bar.trailingAnchor.constraint(equalTo: root.trailingAnchor),
7078
-            bar.topAnchor.constraint(equalTo: root.topAnchor),
7059
+            bar.topAnchor.constraint(equalTo: root.safeAreaLayoutGuide.topAnchor),
7079 7060
             bar.heightAnchor.constraint(equalToConstant: 3),
7080 7061
 
7081 7062
             separator.leadingAnchor.constraint(equalTo: root.leadingAnchor),
@@ -7097,7 +7078,6 @@ private final class InAppBrowserContainerViewController: NSViewController, WKNav
7097 7078
         super.viewDidAppear()
7098 7079
         if let window = view.window {
7099 7080
             installTitlebarButtonsIfNeeded(on: window)
7100
-            installCenteredTitleIfNeeded(on: window)
7101 7081
             syncWindowTitle()
7102 7082
             syncToolbarFromWebView()
7103 7083
         }
@@ -7226,32 +7206,6 @@ private final class InAppBrowserContainerViewController: NSViewController, WKNav
7226 7206
         let host = webView.url?.host ?? ""
7227 7207
         let title = t.isEmpty ? (host.isEmpty ? "Browser" : host) : t
7228 7208
         view.window?.title = title
7229
-        centeredTitleLabel?.stringValue = title
7230
-    }
7231
-
7232
-    private func installCenteredTitleIfNeeded(on window: NSWindow) {
7233
-        guard centeredTitleLabel == nil else { return }
7234
-        guard let titlebarView = window.standardWindowButton(.closeButton)?.superview else { return }
7235
-
7236
-        let label = NSTextField(labelWithString: window.title)
7237
-        label.translatesAutoresizingMaskIntoConstraints = false
7238
-        label.alignment = .center
7239
-        label.font = NSFont.titleBarFont(ofSize: 0)
7240
-        label.textColor = .labelColor
7241
-        label.lineBreakMode = .byTruncatingTail
7242
-        label.maximumNumberOfLines = 1
7243
-
7244
-        titlebarView.addSubview(label)
7245
-
7246
-        NSLayoutConstraint.activate([
7247
-            label.centerXAnchor.constraint(equalTo: titlebarView.centerXAnchor),
7248
-            label.centerYAnchor.constraint(equalTo: titlebarView.centerYAnchor),
7249
-            label.leadingAnchor.constraint(greaterThanOrEqualTo: titlebarView.leadingAnchor, constant: 220),
7250
-            label.trailingAnchor.constraint(lessThanOrEqualTo: titlebarView.trailingAnchor, constant: -90)
7251
-        ])
7252
-
7253
-        window.titleVisibility = .hidden
7254
-        centeredTitleLabel = label
7255 7209
     }
7256 7210
 
7257 7211
     private func installTitlebarButtonsIfNeeded(on window: NSWindow) {