I have subclassed NSWindow, and I have a MYWindow class that implements the following method:
-(void)resetCursorRects {
NSImage *image = [NSImage imageNamed:@"cursor.png"];
[image setSize:NSMakeSize(32, 32)];
NSCursor *cursor = [[NSCursor alloc] initWithImage:image hotSpot:NSMakePoint(1, 1)];
[super resetCursorRects];
[self addCursorRect:[self bounds] cursor:cursor];
}
This will change the cursor for the whole window, and I will see cursor.png instead of the default mouse pointer. The problem is that this only works if MYWindow is installed in the key window, which, of course, is not trivial to create it.
At the beginning of my project, I have only one main window, but now I need to have two different MYWindow. The problem with two windows cannot be set as a key window, and therefore, the user mouse pointer appears only in the active window. I need to click another window to display the cursor.
Is there any way around this? So, do I get a custom cursor in both windows?
Edit: tried NSTrackingArea
:
self.trackingArea = [[NSTrackingArea alloc] initWithRect:[self frame] options: (NSTrackingCursorUpdate | NSTrackingActiveAlways | NSTrackingMouseMoved) owner:self userInfo:nil];
[self addTrackingArea:self.trackingArea];
cursorUpdate: :
-(void)cursorUpdate:(NSEvent *)event {
NSLog(@"event : %@", event);
[[NSCursor crosshairCursor] set];
}
crosshairCursor, NSWindow, NSImageView, . NSWindow , . - ?