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 committed Jun 19, 2024
1 parent 8171a41 commit ddf643f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 44 deletions.
6 changes: 3 additions & 3 deletions Edit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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" */ = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "5a57c719e79b0a39e32c853b3d8e18f925cbf132ebb27828399c403312eb262e",
"originHash" : "61cb567e32cf9c67b9f29b2c794cd7443e88bbe043909522ca1a34fd574197ad",
"pins" : [
{
"identity" : "asyncxpcconnection",
Expand Down Expand Up @@ -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"
}
}
],
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 ddf643f

Please sign in to comment.