Skip to content

Commit

Permalink
Merge pull request #12 from McNight/mcnight/statusBarDoubleClick_zoom…
Browse files Browse the repository at this point in the history
…OrMiniaturize

Make the window zoom or miniaturize when double clicking the status bar
  • Loading branch information
mattmassicotte authored Apr 2, 2024
2 parents 5235562 + b9bfea4 commit 5c2653d
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion Edit/Modules/ProjectWindow/ProjectWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public final class ProjectWindowController: NSWindowController {
self.siblingProvider = siblingProvider
self.model = syncModel

let window = NSWindow(contentViewController: controller)
let window = ProjectWindow(contentViewController: controller)

window.titlebarAppearsTransparent = true
window.styleMask.insert(.fullSizeContentView)
Expand Down Expand Up @@ -111,3 +111,39 @@ 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 5c2653d

Please sign in to comment.