From ddf643f0f7d509be275b7fb4f1fa18d31c1263fd Mon Sep 17 00:00:00 2001 From: Adam McNight Date: Tue, 4 Jun 2024 19:40:52 +0200 Subject: [PATCH] Use TitlebarClickAwareWindow from WindowTreatment library --- Edit.xcodeproj/project.pbxproj | 6 +-- .../xcshareddata/swiftpm/Package.resolved | 8 ++-- .../ProjectWindowController.swift | 38 +------------------ 3 files changed, 8 insertions(+), 44 deletions(-) diff --git a/Edit.xcodeproj/project.pbxproj b/Edit.xcodeproj/project.pbxproj index bad8c30..612bf25 100644 --- a/Edit.xcodeproj/project.pbxproj +++ b/Edit.xcodeproj/project.pbxproj @@ -4983,10 +4983,10 @@ }; C9FE53372A75A75400CACA1A /* XCRemoteSwiftPackageReference "WindowTreatment" */ = { isa = XCRemoteSwiftPackageReference; - repositoryURL = "https://github.com/ChimeHQ/WindowTreatment.git"; + repositoryURL = "https://github.com/McNight/WindowTreatment"; requirement = { - kind = upToNextMajorVersion; - minimumVersion = 2.3.0; + branch = main; + kind = branch; }; }; C9FE53AE2A7677D100CACA1A /* XCRemoteSwiftPackageReference "ScrollViewPlus" */ = { diff --git a/Edit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Edit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 86f843a..fc0401c 100644 --- a/Edit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Edit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "5a57c719e79b0a39e32c853b3d8e18f925cbf132ebb27828399c403312eb262e", + "originHash" : "61cb567e32cf9c67b9f29b2c794cd7443e88bbe043909522ca1a34fd574197ad", "pins" : [ { "identity" : "asyncxpcconnection", @@ -288,10 +288,10 @@ { "identity" : "windowtreatment", "kind" : "remoteSourceControl", - "location" : "https://github.com/ChimeHQ/WindowTreatment.git", + "location" : "https://github.com/McNight/WindowTreatment", "state" : { - "revision" : "3ab18f6df0a69b63cef1d158c47da3992e89b733", - "version" : "2.3.0" + "branch" : "main", + "revision" : "d1ae68ccf3ad488bccd9deab679d88c67d41cb7d" } } ], diff --git a/Edit/Modules/ProjectWindow/ProjectWindowController.swift b/Edit/Modules/ProjectWindow/ProjectWindowController.swift index 34a5f06..189573a 100644 --- a/Edit/Modules/ProjectWindow/ProjectWindowController.swift +++ b/Edit/Modules/ProjectWindow/ProjectWindowController.swift @@ -52,7 +52,7 @@ public final class ProjectWindowController: NSWindowController { self.siblingProvider = siblingProvider self.model = model - let window = ProjectWindow(contentViewController: controller) + let window = TitlebarClickAwareWindow(contentViewController: controller) window.titlebarAppearsTransparent = true window.styleMask.insert(.fullSizeContentView) @@ -107,39 +107,3 @@ extension ProjectWindowController { openQuicklyWindowController.showWindow(parent: window) } } - -private final class ProjectWindow: NSWindow { - override func mouseDown(with event: NSEvent) { - if event.clickCount > 1, isEventLocationEligible(event.locationInWindow) { - zoomOrMiniaturize(self) - } - super.mouseDown(with: event) - } - - private func isEventLocationEligible(_ location: CGPoint) -> Bool { - guard let windowFrame = contentView?.frame else { - return false - } - var titleBarRect = contentLayoutRect - titleBarRect.origin.y += contentLayoutRect.height - titleBarRect.size.height = windowFrame.height - contentLayoutRect.height - return titleBarRect.contains(location) - } - - private static let actionOnDoubleClickKey: String = "AppleActionOnDoubleClick" - private static let zoomActionOnDoubleClickValue: String = "Maximize" - private static let miniaturizeActionOnDoubleClickValue: String = "Minimize" - - func zoomOrMiniaturize(_ sender: Any?) { - let actionOnDoubleClickValue = UserDefaults.standard.string(forKey: Self.actionOnDoubleClickKey) - - switch actionOnDoubleClickValue { - case Self.zoomActionOnDoubleClickValue: - zoom(sender) - case Self.miniaturizeActionOnDoubleClickValue: - miniaturize(sender) - default: - zoom(sender) - } - } -}