diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2017-08-17 19:01:40 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2017-08-24 23:54:43 +0000 |
commit | a980250a666bc87e5db006b8668c6af9340915f2 (patch) | |
tree | d9c3f6eca8a9941cf734dca4deea07f272515835 /src/plugins/platforms/cocoa/qcocoawindow.mm | |
parent | f537dc0da288949c4df903c1f2b21156e62fbae5 (diff) |
macOS: Deduplicate QNSWindow/QNSPanel code
By sharing the implementations of the methods between QNSWindow and
QNSPanel we don't need a helper, and can remove duplicated code. This
duplication would expand in the future, as for each method added to
the QNSWindowProtocol, we would have to add forwarding functions
in both QNSWindow and QNSPanel, forwarding to QNSWindowHelper, and
then two more functions in QNSWindow and QNSPanel in case we wanted
to call super from the helper, similar to [QNSWindow superSendEvent].
The only snag is that calls to super are hard-coded to a specific
superclass during complication, so we provide our wrapper for
objc_msgSendSuper that resolves the superclass at runtime.
The helper class QSendSuperHelper provides compile time implicit
instantiation of the right template without having to provide
the return type as a template argument, via operator T and
a fallback for the case of no return type via the destructor.
Change-Id: Iaf13f27675d90f884470f5005270ea0d9d0316f3
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoawindow.mm')
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoawindow.mm | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index d3f26df6c5..e906f0fd1c 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -210,7 +210,6 @@ QCocoaWindow::~QCocoaWindow() QMacAutoReleasePool pool; [m_nsWindow makeFirstResponder:nil]; [m_nsWindow setContentView:nil]; - [m_nsWindow.helper detachFromPlatformWindow]; if ([m_view superview]) [m_view removeFromSuperview]; @@ -1279,10 +1278,34 @@ QCocoaNSWindow *QCocoaWindow::createNSWindow(bool shouldBePanel) // Create NSWindow Class windowClass = shouldBePanel ? [QNSPanel class] : [QNSWindow class]; QCocoaNSWindow *nsWindow = [[windowClass alloc] initWithContentRect:frame - screen:cocoaScreen->nativeScreen() styleMask:windowStyleMask(flags) qPlatformWindow:this]; + styleMask:windowStyleMask(flags) + // Deferring window creation breaks OpenGL (the GL context is + // set up before the window is shown and needs a proper window) + backing:NSBackingStoreBuffered defer:NO + screen:cocoaScreen->nativeScreen()]; + Q_ASSERT_X(nsWindow.screen == cocoaScreen->nativeScreen(), "QCocoaWindow", "Resulting NSScreen should match the requested NSScreen"); + nsWindow.delegate = [[QNSWindowDelegate alloc] initWithQCocoaWindow:this]; + + // Prevent Cocoa from releasing the window on close. Qt + // handles the close event asynchronously and we want to + // make sure that NSWindow stays valid until the + // QCocoaWindow is deleted by Qt. + [nsWindow setReleasedWhenClosed:NO]; + + if (alwaysShowToolWindow()) { + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; + [center addObserver:[QNSWindow class] selector:@selector(applicationActivationChanged:) + name:NSApplicationWillResignActiveNotification object:nil]; + [center addObserver:[QNSWindow class] selector:@selector(applicationActivationChanged:) + name:NSApplicationWillBecomeActiveNotification object:nil]; + }); + } + if (targetScreen != window()->screen()) QWindowSystemInterface::handleWindowScreenChanged(window(), targetScreen); |