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,
|
/// 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.
|
/// not the view under the mouse. It never resets the cursor rects: that would fire new cursor updates.
|
||||||
static func scheduleUpdate(in window: NSWindow?) {
|
static func scheduleUpdate(in window: NSWindow?) {
|
||||||
|
|||||||
@@ -115,6 +115,7 @@ final class WindowCoordinator: NSObject {
|
|||||||
window.tabbingMode = .disallowed
|
window.tabbingMode = .disallowed
|
||||||
// A restored window would be a second project in this process.
|
// A restored window would be a second project in this process.
|
||||||
window.isRestorable = false
|
window.isRestorable = false
|
||||||
|
if let content = window.contentView { PointerPolicy.claimCursorUpdates(of: content) }
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Traffic lights
|
// MARK: Traffic lights
|
||||||
|
|||||||
Reference in New Issue
Block a user