summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa/qcocoawindow.mm
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@digia.com>2014-03-21 14:31:23 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-03-25 12:44:54 +0100
commita6bf169479df40f489fed549c893958f2519010e (patch)
treeeee487299c1a63c61bf2a2f6d7c1e3bc56e916f9 /src/plugins/platforms/cocoa/qcocoawindow.mm
parentce8271ce051677a90e975db3a3b82b1e9c7261eb (diff)
OSX: make reported window state consistent with reality
You can't always get what you want: if you exit from fullscreen mode via showNormal, it might actually be maximized; or if you exit via showMaximized, it might actually be normal, if that's the mode the NSWindow remembers. We can't set the state, we can only toggle it. But now at least it's predictable, so that if you call showNormal or showMaximized twice, you will definitely get back to that state. Task-number: QTBUG-35166 Change-Id: I7422960a64f624920566c25763f5c3b03a684fb5 Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoawindow.mm')
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindow.mm26
1 files changed, 21 insertions, 5 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm
index c7fba4eef0..f25aea67fa 100644
--- a/src/plugins/platforms/cocoa/qcocoawindow.mm
+++ b/src/plugins/platforms/cocoa/qcocoawindow.mm
@@ -352,6 +352,7 @@ QCocoaWindow::QCocoaWindow(QWindow *tlw)
, m_contentViewIsToBeEmbedded(false)
, m_parentCocoaWindow(0)
, m_isNSWindowChild(false)
+ , m_effectivelyMaximized(false)
, m_synchedWindowState(Qt::WindowActive)
, m_windowModality(Qt::NonModal)
, m_windowUnderMouse(false)
@@ -1436,7 +1437,6 @@ void QCocoaWindow::syncWindowState(Qt::WindowState newState)
{
if (!m_nsWindow)
return;
-
// if content view width or height is 0 then the window animations will crash so
// do nothing except set the new state
NSRect contentRect = [contentView() frame];
@@ -1446,9 +1446,7 @@ void QCocoaWindow::syncWindowState(Qt::WindowState newState)
return;
}
- if ((m_synchedWindowState & Qt::WindowMaximized) != (newState & Qt::WindowMaximized)) {
- [m_nsWindow performZoom : m_nsWindow]; // toggles
- }
+ Qt::WindowState predictedState = newState;
if ((m_synchedWindowState & Qt::WindowMinimized) != (newState & Qt::WindowMinimized)) {
if (newState & Qt::WindowMinimized) {
@@ -1458,12 +1456,26 @@ void QCocoaWindow::syncWindowState(Qt::WindowState newState)
}
}
+ if ((m_synchedWindowState & Qt::WindowMaximized) != (newState & Qt::WindowMaximized) || (m_effectivelyMaximized && newState == Qt::WindowNoState)) {
+ if ((m_synchedWindowState & Qt::WindowFullScreen) == (newState & Qt::WindowFullScreen)) {
+ [m_nsWindow performZoom : m_nsWindow]; // toggles
+ m_effectivelyMaximized = !m_effectivelyMaximized;
+ } else if (!(newState & Qt::WindowMaximized)) {
+ // it would be nice to change the target geometry that toggleFullScreen will animate toward
+ // but there is no known way, so the maximized state is not possible at this time
+ predictedState = static_cast<Qt::WindowState>(static_cast<int>(newState) | Qt::WindowMaximized);
+ m_effectivelyMaximized = true;
+ }
+ }
+
if ((m_synchedWindowState & Qt::WindowFullScreen) != (newState & Qt::WindowFullScreen)) {
bool fakeFullScreen = true;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
if (QSysInfo::QSysInfo::MacintoshVersion >= QSysInfo::MV_10_7) {
if (window()->flags() & Qt::WindowFullscreenButtonHint) {
fakeFullScreen = false;
+ if (m_effectivelyMaximized && m_synchedWindowState == Qt::WindowFullScreen)
+ predictedState = Qt::WindowMaximized;
[m_nsWindow toggleFullScreen : m_nsWindow];
}
}
@@ -1490,8 +1502,12 @@ void QCocoaWindow::syncWindowState(Qt::WindowState newState)
}
}
+#ifdef QT_COCOA_ENABLE_WINDOW_DEBUG
+ qDebug() << "QCocoaWindow::syncWindowState" << newState << "actual" << predictedState << "was" << m_synchedWindowState << "effectively maximized" << m_effectivelyMaximized;
+#endif
+
// New state is now the current synched state
- m_synchedWindowState = newState;
+ m_synchedWindowState = predictedState;
}
bool QCocoaWindow::setWindowModified(bool modified)