Skip to content

Commit

Permalink
Use TitlebarClickAwareWindow from WindowTreatment library
Browse files Browse the repository at this point in the history
  • Loading branch information
McNight authored and mattmassicotte committed Jul 9, 2024
1 parent 9118ca0 commit 0d2e8e9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 40 deletions.
6 changes: 3 additions & 3 deletions Edit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -4969,10 +4969,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" */ = {
Expand Down
38 changes: 1 addition & 37 deletions Edit/Modules/ProjectWindow/ProjectWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}
}

0 comments on commit 0d2e8e9

Please sign in to comment.