Skip to content

Commit

Permalink
Make the window zoom or miniaturize when double clicking the status bar
Browse files Browse the repository at this point in the history
  • Loading branch information
McNight committed Apr 2, 2024
1 parent 9eb4b9c commit b9bfea4
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 b9bfea4

Please sign in to comment.