Colas
Colas

Reputation: 3573

How to change NSCursor globally?

I am developing an application with several windows and views (NSTextView, etc.).

I would like to change the cursor globally in my application, so that even if the cursor enters the trackingRect of (for instance) an NSTextView it does not change.

Is this possible?


PS: I need also to revert back to the usual behaviour.

Upvotes: 5

Views: 417

Answers (1)

Shiva Prasad
Shiva Prasad

Reputation: 106

Yes this is possible. I had an almost similar requirement, and here is how I solved it:

When creating a window, create a transparent view with the same frame as that of the window. Then add a cursor rect to the view (that extends to the latter's bounds) for your specific cursor. Finally add it as the last subview of the window's contentView, so that it acts as an overlay. When this overlay is present, cursor rects of underlying views are not activated.

See https://stackoverflow.com/a/43886799/7908996 for detailed instructions and working code (read the window's contentView instead of WebView). It also describes how to revert back to the usual behaviour.

Hope that helps! :)

Upvotes: 2

Related Questions