Skip to content

Commit

Permalink
🔀 Merge pull request #667 from zenangst/improve/window-animations
Browse files Browse the repository at this point in the history
Improve window animations
  • Loading branch information
MrKai77 authored Jan 10, 2025
2 parents 9107745 + a91fd3e commit 82aac46
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
11 changes: 11 additions & 0 deletions Loop/Extensions/NSScreen+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ extension NSScreen {
return deviceDescription[key] as? CGDirectDisplayID
}

var displayMode: CGDisplayMode? {
guard
let id = displayID,
let displayMode = CGDisplayCopyDisplayMode(id)
else {
return nil
}

return displayMode
}

static var screenWithMouse: NSScreen? {
let mouseLocation = NSEvent.mouseLocation
let screens = NSScreen.screens
Expand Down
20 changes: 13 additions & 7 deletions Loop/Window Management/WindowTransformAnimation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class WindowTransformAnimation: NSAnimation {
self.bounds = bounds
self.completionHandler = completionHandler
super.init(duration: 0.3, animationCurve: .easeOut)
self.frameRate = 60.0
self.frameRate = Float(NSScreen.main?.displayMode?.refreshRate ?? 60.0)
self.animationBlockingMode = .nonblocking
self.lastWindowFrame = originalFrame

Expand Down Expand Up @@ -57,10 +57,10 @@ class WindowTransformAnimation: NSAnimation {
let value = CGFloat(1.0 - pow(1.0 - currentValue, 3))

var newFrame = CGRect(
x: originalFrame.origin.x + value * (targetFrame.origin.x - originalFrame.origin.x),
y: originalFrame.origin.y + value * (targetFrame.origin.y - originalFrame.origin.y),
width: originalFrame.size.width + value * (targetFrame.size.width - originalFrame.size.width),
height: originalFrame.size.height + value * (targetFrame.size.height - originalFrame.size.height)
x: round(originalFrame.origin.x + value * (targetFrame.origin.x - originalFrame.origin.x)),
y: round(originalFrame.origin.y + value * (targetFrame.origin.y - originalFrame.origin.y)),
width: round(originalFrame.size.width + value * (targetFrame.size.width - originalFrame.size.width)),
height: round(originalFrame.size.height + value * (targetFrame.size.height - originalFrame.size.height))
)

// Keep the window inside the bounds
Expand All @@ -78,8 +78,14 @@ class WindowTransformAnimation: NSAnimation {
}
}

window.position = newFrame.origin
window.size = newFrame.size
if lastWindowFrame.origin != newFrame.origin {
window.position = newFrame.origin
}

if lastWindowFrame.size != newFrame.size {
window.size = newFrame.size
}

lastWindowFrame = window.frame

if currentProgress >= 1.0 {
Expand Down

0 comments on commit 82aac46

Please sign in to comment.