glitching of the cursor is fixed
This commit is contained in:
@@ -242,6 +242,22 @@ extension PointerPolicy {
|
||||
}
|
||||
}
|
||||
|
||||
private static var claimedClasses: Set<ObjectIdentifier> = []
|
||||
|
||||
/// Gives the window's hosting view a `cursorUpdate:` that asks the policy. AppKit calls it directly on every display
|
||||
/// cycle that moves a tracking area, outside any event the monitor sees, and the hosting view's own answer is the arrow.
|
||||
static func claimCursorUpdates(of view: NSView) {
|
||||
guard let viewClass = object_getClass(view), claimedClasses.insert(ObjectIdentifier(viewClass)).inserted else { return }
|
||||
let block: @convention(block) (AnyObject, NSEvent) -> Void = { object, _ in
|
||||
MainActor.assumeIsolated {
|
||||
scheduleUpdate(in: (object as? NSView)?.window)
|
||||
}
|
||||
}
|
||||
let selector = #selector(NSResponder.cursorUpdate(with:))
|
||||
let types = method_getTypeEncoding(class_getInstanceMethod(NSView.self, selector)!)
|
||||
class_replaceMethod(viewClass, selector, imp_implementationWithBlock(block), types)
|
||||
}
|
||||
|
||||
/// Runs `updateCursor` once, after the current event. Inside an event SwiftUI's hit test returns its root view,
|
||||
/// not the view under the mouse. It never resets the cursor rects: that would fire new cursor updates.
|
||||
static func scheduleUpdate(in window: NSWindow?) {
|
||||
|
||||
Reference in New Issue
Block a user