Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 640
Colas Avatar asked Oct 29 '22 12:10

Colas


1 Answers

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! :)

like image 52
Shiva Prasad Avatar answered Nov 15 '22 10:11

Shiva Prasad