Disable cursor change while inside tracking area in swift

308 Views Asked by At

I'm trying to change cursor while the cursor is inside a view. The problem is that the cursor resets to its default automatically sometimes(for example when a notification popup shows up.)

class DrawingView : NSView{

    override func draw(_ dirtyRect: NSRect) {
        super.draw(dirtyRect)
        
        // Drawing code here.
    }

   override func updateTrackingAreas() {
        let area = NSTrackingArea(rect: self.frame, options: [.cursorUpdate,.activeAlways,.inVisibleRect], owner: self, userInfo: nil)
        self.addTrackingArea(area)
    }

    override func cursorUpdate(with event: NSEvent) {
        NSCursor.crosshair.set()
        NSApp.keyWindow?.disableCursorRects()
    }
        
}

To my knowledge NSWindow's disableCursorRects() is supposed to stop the cursor from changing due to other processes. Maybe I'm using it wrong?

0

There are 0 best solutions below