How can I determine if a child window has been moved directly by the user rather than as a result of its parent window being moved?
I get NSWindowDidMoveNotification notifications in both cases.
I figured I could test the parent frame origin in the NSWindowWillMoveNotification handler and compare it against the origin when in the NSWindowDidMoveNotification handler, but is there a better way perhaps?
Here is my current solution:
- (void)windowWillMove:(NSNotification *)notification
{
NSWindow *window = [notification object];
_parentOrigin = [[window parentWindow] frame].origin;
}
- (void)windowDidMove:(NSNotification *)notification
{
NSWindow *window = [notification object];
NSPoint newParentOrigin = [[window parentWindow] frame].origin;
if (_parentOrigin.x == newParentOrigin.x &&
_parentOrigin.y == newParentOrigin.y)
{
// The parent hasn't moved, therefore the user moved the window directly...
[window doThing];
}
}
The window that you click on to move will become the key window, while the child window doesn’t become key if it’s moved as a result of moving the parent window. So, if you test for whether the window sending the notification is the key window, you can tell which was moved by the user.