Skip to content

Commit

Permalink
🎨 Move display mode code into NSScreen+Extensions.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKai77 committed Jan 10, 2025
1 parent 0b26fa2 commit a91fd3e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 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
12 changes: 1 addition & 11 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 = Self.getCurrentRefreshRate() ?? 60.0
self.frameRate = Float(NSScreen.main?.displayMode?.refreshRate ?? 60.0)
self.animationBlockingMode = .nonblocking
self.lastWindowFrame = originalFrame

Expand Down Expand Up @@ -94,14 +94,4 @@ class WindowTransformAnimation: NSAnimation {
}
}
}

static func getCurrentRefreshRate() -> Float? {
guard let activeScreen = NSScreen.main,
let screenNumber = activeScreen.deviceDescription[NSDeviceDescriptionKey("NSScreenNumber")] as? CGDirectDisplayID,
let displayMode = CGDisplayCopyDisplayMode(screenNumber) else {
return nil
}

return Float(displayMode.refreshRate)
}
}

0 comments on commit a91fd3e

Please sign in to comment.