diff --git a/src/plugins/platforms/cocoa/qcocoawindow.h b/src/plugins/platforms/cocoa/qcocoawindow.h index 0f08cd18fb..67cac41383 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.h +++ b/src/plugins/platforms/cocoa/qcocoawindow.h @@ -69,10 +69,14 @@ typedef NSWindow QCocoaNSWindow; { QCocoaNSWindow *_window; QCocoaWindow *_platformWindow; + BOOL _grabbingMouse; + BOOL _releaseOnMouseUp; } @property (nonatomic, readonly) QCocoaNSWindow *window; @property (nonatomic, readonly) QCocoaWindow *platformWindow; +@property (nonatomic) BOOL grabbingMouse; +@property (nonatomic) BOOL releaseOnMouseUp; - (id)initWithNSWindow:(QCocoaNSWindow *)window platformWindow:(QCocoaWindow *)platformWindow; - (void)handleWindowEvent:(NSEvent *)theEvent; diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index 65e2a15cec..f1f88a13dd 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -103,6 +103,8 @@ static bool isMouseEvent(NSEvent *ev) @synthesize window = _window; @synthesize platformWindow = _platformWindow; +@synthesize grabbingMouse = _grabbingMouse; +@synthesize releaseOnMouseUp = _releaseOnMouseUp; - (id)initWithNSWindow:(QCocoaNSWindow *)window platformWindow:(QCocoaWindow *)platformWindow { @@ -142,6 +144,17 @@ static bool isMouseEvent(NSEvent *ev) } } + if (theEvent.type == NSLeftMouseDown) { + self.grabbingMouse = YES; + } else if (theEvent.type == NSLeftMouseUp) { + self.grabbingMouse = NO; + if (self.releaseOnMouseUp) { + [self detachFromPlatformWindow]; + [self.window release]; + return; + } + } + [self.window superSendEvent:theEvent]; if (!self.window.delegate) @@ -234,9 +247,14 @@ static bool isMouseEvent(NSEvent *ev) - (void)closeAndRelease { - [self.helper detachFromPlatformWindow]; [self close]; - [self release]; + + if (self.helper.grabbingMouse) { + self.helper.releaseOnMouseUp = YES; + } else { + [self.helper detachFromPlatformWindow]; + [self release]; + } } - (void)dealloc