I've got a problem here. I'm creating a NSTrackingArea
like this:
NSTrackingArea *area = [[NSTrackingArea alloc] initWithRect:[self frame] options:NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways owner:self userInfo:nil];
[self addTrackingArea:area];
[area release];
This works quite fine. However, here's a problem. I have it set up like this:
-(void)mouseEntered:(NSEvent *)event {
[self toggleDetail];
}
-(void)mouseExited:(NSEvent *)event {
[self toggleDetail];
}
And toggleDetail
is basically like this:
- (void)toggleDetail {
if (!attachedWindow) {
NSPoint buttonPoint = NSMakePoint(NSMidX([conditionImage frame]),
NSMidY([conditionImage frame]));
attachedWindow = [[MAAttachedWindow alloc] initWithView:view
attachedToPoint:buttonPoint
inWindow:[self window]
onSide:12
atDistance:10.0];
//config removed because of irrelevance
[[self window] addChildWindow:attachedWindow ordered:NSWindowAbove];
} else {
[[self window] removeChildWindow:attachedWindow];
[attachedWindow orderOut:self];
[attachedWindow release];
attachedWindow = nil;
}
}
Now here's my problem. When my MAAttachedWindow
is closed, and I move my mouse over the window, it opens. Dandy. However, it's only good when I keep my mouse away from the MAAttachedWindow
. As soon as I move my mouse over it (while still over the main window) it starts to violently open and close the MAAttachedWindow
.
Here's why: As soon as the window opens, the tracking area believes that my mouse isn't over the window anymore because the popup is in front of it. However, as soon as it removes the popup, then it thinks that my mouse is over it again, thus creating and showing the popup once more. Thus it's an endless loop.
My question is if there's a way around this, where it can not close the window unless my mouse is outside both the window and the popup or something similar. Is there a way to do this?
See -[NSWindow setIgnoresMouseEvents:].
By the way, be very careful with overlay windows. The difficulty with them is that you have to give it absolute coordinates when you create it and there’s a small race—the parent window can be moved between the time that you get its frame, and the time that you create the child window. Window moving is done by the Window Server and can be done independently of the application (that's why you can move a window when the application is beach balling). Now it’s very rare that this would be an issue, but it is possible and quite hard to fix it properly. It’s more of a problem if you’re trying to resize or move a child window when the parent window resizes.
Now I realise that none of this might apply to you, but if it does, and you can think of an alternative to using child windows, I would advise you to go with it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With