summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa/qcocoawindow.mm
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2017-02-28 13:03:36 +0100
committerLiang Qi <liang.qi@qt.io>2017-02-28 13:03:36 +0100
commit1a4f0deeb44e2bfb107a22a714df3796ac1d0c20 (patch)
treeb1c8db2d1b742d25106225c80893e0b32f98fb15 /src/plugins/platforms/cocoa/qcocoawindow.mm
parentdb0064b767474a89bc72ea4374f477682983c5f4 (diff)
parent35fa30e65d26b9e4840cfa793ed8369b3475c1fd (diff)
Merge remote-tracking branch 'origin/5.9' into dev
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoawindow.mm')
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindow.mm54
1 files changed, 37 insertions, 17 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm
index 918f376446..75c13d6bbc 100644
--- a/src/plugins/platforms/cocoa/qcocoawindow.mm
+++ b/src/plugins/platforms/cocoa/qcocoawindow.mm
@@ -433,7 +433,7 @@ Q_CONSTRUCTOR_FUNCTION(qRegisterNotificationCallbacks)
const int QCocoaWindow::NoAlertRequest = -1;
-QCocoaWindow::QCocoaWindow(QWindow *tlw)
+QCocoaWindow::QCocoaWindow(QWindow *tlw, WId nativeHandle)
: QPlatformWindow(tlw)
, m_view(nil)
, m_nsWindow(0)
@@ -470,8 +470,9 @@ QCocoaWindow::QCocoaWindow(QWindow *tlw)
QMacAutoReleasePool pool;
- if (tlw->type() == Qt::ForeignWindow) {
- m_view = (NSView *)WId(tlw->property("_q_foreignWinId").value<WId>());
+ if (nativeHandle) {
+ m_view = reinterpret_cast<NSView *>(nativeHandle);
+ [m_view retain];
} else {
m_view = [[QNSView alloc] initWithCocoaWindow:this];
// Enable high-dpi OpenGL for retina displays. Enabling has the side
@@ -562,6 +563,11 @@ void QCocoaWindow::setGeometry(const QRect &rectIn)
setCocoaGeometry(rect);
}
+bool QCocoaWindow::isForeignWindow() const
+{
+ return ![m_view isKindOfClass:[QNSView class]];
+}
+
QRect QCocoaWindow::geometry() const
{
// QWindows that are embedded in a NSView hiearchy may be considered
@@ -941,6 +947,10 @@ NSUInteger QCocoaWindow::windowStyleMask(Qt::WindowFlags flags)
if (m_drawContentBorderGradient)
styleMask |= NSTexturedBackgroundWindowMask;
+ // Don't wipe fullscreen state
+ if (m_nsWindow.styleMask & NSFullScreenWindowMask)
+ styleMask |= NSFullScreenWindowMask;
+
return styleMask;
}
@@ -1363,19 +1373,40 @@ void QCocoaWindow::windowDidDeminiaturize()
reportCurrentWindowState();
}
+void QCocoaWindow::windowWillEnterFullScreen()
+{
+ // The NSWindow needs to be resizable, otherwise we'll end up with
+ // the normal window geometry, centered in the middle of the screen
+ // on a black background. The styleMask will be reset below.
+ m_nsWindow.styleMask |= NSResizableWindowMask;
+}
+
void QCocoaWindow::windowDidEnterFullScreen()
{
Q_ASSERT_X(m_nsWindow.qt_fullScreen, "QCocoaWindow",
"FullScreen category processes window notifications first");
+ // Reset to original styleMask
+ setWindowFlags(m_windowFlags);
+
reportCurrentWindowState();
}
+void QCocoaWindow::windowWillExitFullScreen()
+{
+ // The NSWindow needs to be resizable, otherwise we'll end up with
+ // a weird zoom animation. The styleMask will be reset below.
+ m_nsWindow.styleMask |= NSResizableWindowMask;
+}
+
void QCocoaWindow::windowDidExitFullScreen()
{
Q_ASSERT_X(!m_nsWindow.qt_fullScreen, "QCocoaWindow",
"FullScreen category processes window notifications first");
+ // Reset to original styleMask
+ setWindowFlags(m_windowFlags);
+
Qt::WindowState requestedState = window()->windowState();
// Deliver update of QWindow state
@@ -1869,24 +1900,13 @@ void QCocoaWindow::toggleMaximized()
void QCocoaWindow::toggleFullScreen()
{
- // The NSWindow needs to be resizable, otherwise we'll end up with
- // the normal window geometry, centered in the middle of the screen
- // on a black background.
- const bool wasResizable = m_nsWindow.styleMask & NSResizableWindowMask;
- m_nsWindow.styleMask |= NSResizableWindowMask;
-
- // It also needs to have the correct collection behavior for the
- // toggleFullScreen call to have an effect.
- const bool wasFullScreenEnabled = m_nsWindow.collectionBehavior & NSWindowCollectionBehaviorFullScreenPrimary;
+ // The window needs to have the correct collection behavior for the
+ // toggleFullScreen call to have an effect. The collection behavior
+ // will be reset in windowDidEnterFullScreen/windowDidLeaveFullScreen.
m_nsWindow.collectionBehavior |= NSWindowCollectionBehaviorFullScreenPrimary;
const id sender = m_nsWindow;
[m_nsWindow toggleFullScreen:sender];
-
- if (!wasResizable)
- m_nsWindow.styleMask &= ~NSResizableWindowMask;
- if (!wasFullScreenEnabled)
- m_nsWindow.collectionBehavior &= ~NSWindowCollectionBehaviorFullScreenPrimary;
}
bool QCocoaWindow::isTransitioningToFullScreen() const