Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the window zoom or miniaturize when double clicking the status bar #12

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}
}