perf: better caanimation batching
This commit is contained in:
1 parent
305870b3ee
commit
016052ca14
5 files changed
+38
-29
No files matched your search
@@ -2,6 +2,24 @@ import Cocoa
|
||||
import Darwin
|
||||
import Carbon.HIToolbox.Events
|
||||
|
||||
class NoAnimationDelegate: NSObject, CALayerDelegate {
|
||||
static let shared = NoAnimationDelegate()
|
||||
func action(for layer: CALayer, forKey event: String) -> (any CAAction)? { NSNull() }
|
||||
}
|
||||
|
||||
func noAnimation<T: CALayer>(_ make: () -> T) -> T {
|
||||
let layer = make()
|
||||
layer.delegate = NoAnimationDelegate.shared
|
||||
return layer
|
||||
}
|
||||
|
||||
func caTransaction(_ body: () -> Void) {
|
||||
CATransaction.begin()
|
||||
defer { CATransaction.commit() }
|
||||
CATransaction.setDisableActions(true)
|
||||
body()
|
||||
}
|
||||
|
||||
extension NSAppearance {
|
||||
func getThemeName() -> AppearanceThemePreference {
|
||||
if #available(macOS 10.14, *) {
|
||||
|
||||
@@ -22,13 +22,7 @@ class LightImageView: NSView {
|
||||
layer!.minificationFilter = .trilinear
|
||||
layer!.minificationFilterBias = 0.0
|
||||
layer!.shouldRasterize = false
|
||||
// disable implicit animations
|
||||
layer!.actions = [
|
||||
"contents": NSNull(),
|
||||
"bounds": NSNull(),
|
||||
"position": NSNull(),
|
||||
"contentsScale": NSNull()
|
||||
]
|
||||
layer!.delegate = NoAnimationDelegate.shared
|
||||
layerContentsRedrawPolicy = .never
|
||||
setupOutlineLayer()
|
||||
setupHandRaisedLayer()
|
||||
|
||||
@@ -146,8 +146,6 @@ class ThumbnailView: FlippedView {
|
||||
let shouldShow = shouldShowWindowControls && !Preferences.hideColoredCircles && !Appearance.hideThumbnails
|
||||
guard isShowingWindowControls != shouldShow else { return }
|
||||
isShowingWindowControls = shouldShow
|
||||
CATransaction.begin()
|
||||
CATransaction.setDisableActions(true)
|
||||
for icon in windowControlIcons {
|
||||
let shouldHide = !shouldShow
|
||||
|| (icon.type == .quit && !(window_?.application.canBeQuit() ?? true))
|
||||
@@ -159,7 +157,6 @@ class ThumbnailView: FlippedView {
|
||||
icon.needsDisplay = true
|
||||
}
|
||||
}
|
||||
CATransaction.commit()
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -33,14 +33,13 @@ class ThumbnailsPanel: NSPanel {
|
||||
}
|
||||
|
||||
func updateContents() {
|
||||
CATransaction.begin()
|
||||
defer { CATransaction.commit() }
|
||||
CATransaction.setDisableActions(true)
|
||||
thumbnailsView.updateItemsAndLayout()
|
||||
guard App.app.appIsBeingUsed else { return }
|
||||
setContentSize(thumbnailsView.contentView.frame.size)
|
||||
guard App.app.appIsBeingUsed else { return }
|
||||
NSScreen.preferred.repositionPanel(self)
|
||||
caTransaction {
|
||||
thumbnailsView.updateItemsAndLayout()
|
||||
guard App.app.appIsBeingUsed else { return }
|
||||
setContentSize(thumbnailsView.contentView.frame.size)
|
||||
guard App.app.appIsBeingUsed else { return }
|
||||
NSScreen.preferred.repositionPanel(self)
|
||||
}
|
||||
}
|
||||
|
||||
override func orderOut(_ sender: Any?) {
|
||||
|
||||
@@ -291,8 +291,10 @@ class ScrollView: NSScrollView {
|
||||
}
|
||||
|
||||
override func mouseExited(with event: NSEvent) {
|
||||
previousTarget = nil
|
||||
resetHoveredWindow()
|
||||
caTransaction {
|
||||
previousTarget = nil
|
||||
resetHoveredWindow()
|
||||
}
|
||||
}
|
||||
|
||||
override func mouseMoved(with event: NSEvent) {
|
||||
@@ -300,16 +302,15 @@ class ScrollView: NSScrollView {
|
||||
let location = documentView.convert(App.app.thumbnailsPanel.mouseLocationOutsideOfEventStream, from: nil)
|
||||
let newTarget = findTarget(location)
|
||||
guard newTarget !== previousTarget else { return }
|
||||
CATransaction.begin()
|
||||
CATransaction.setDisableActions(true)
|
||||
if let newTarget {
|
||||
previousTarget?.showOrHideWindowControls(false)
|
||||
newTarget.mouseMoved()
|
||||
} else {
|
||||
resetHoveredWindow()
|
||||
caTransaction {
|
||||
if let newTarget {
|
||||
previousTarget?.showOrHideWindowControls(false)
|
||||
newTarget.mouseMoved()
|
||||
} else {
|
||||
resetHoveredWindow()
|
||||
}
|
||||
previousTarget = newTarget
|
||||
}
|
||||
previousTarget = newTarget
|
||||
CATransaction.commit()
|
||||
}
|
||||
|
||||
private func findTarget(_ location: NSPoint) -> ThumbnailView? {
|
||||
|
||||
Reference in new issue
Block a user