macOS: Report compound window state when state changes

Otherwise we lose the fact that the window is both maximized and
minimized, if the minimize transition is asynchronous, as it is
on macOS 13.

Task-number: QTBUG-104210
Change-Id: I76199e98927e6e4a0f379d78db0603faa80aa4b0
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
(cherry picked from commit 55a7385296a516ce3532f24053b0dc37a1c974f0)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Tor Arne Vestbø 2022-09-13 15:42:55 +02:00 committed by Qt Cherry-pick Bot
parent 5d23caf776
commit 0b04f858f8
2 changed files with 17 additions and 13 deletions

View File

@ -189,7 +189,7 @@ protected:
void recreateWindowIfNeeded();
QCocoaNSWindow *createNSWindow(bool shouldBePanel);
Qt::WindowState windowState() const;
Qt::WindowStates windowState() const;
void applyWindowState(Qt::WindowStates newState);
void toggleMaximized();
void toggleFullScreen();

View File

@ -658,7 +658,7 @@ void QCocoaWindow::applyWindowState(Qt::WindowStates requestedState)
if (!isContentView())
return;
const Qt::WindowState currentState = windowState();
const Qt::WindowState currentState = QWindowPrivate::effectiveState(windowState());
const Qt::WindowState newState = QWindowPrivate::effectiveState(requestedState);
if (newState == currentState)
@ -727,23 +727,27 @@ void QCocoaWindow::applyWindowState(Qt::WindowStates requestedState)
}
}
Qt::WindowState QCocoaWindow::windowState() const
Qt::WindowStates QCocoaWindow::windowState() const
{
// FIXME: Support compound states (Qt::WindowStates)
Qt::WindowStates states = Qt::WindowNoState;
NSWindow *window = m_view.window;
if (window.miniaturized)
return Qt::WindowMinimized;
if (window.qt_fullScreen)
return Qt::WindowFullScreen;
if ((window.zoomed && !isTransitioningToFullScreen())
|| (m_lastReportedWindowState == Qt::WindowMaximized && isTransitioningToFullScreen()))
return Qt::WindowMaximized;
states |= Qt::WindowMinimized;
// Full screen and maximized are mutually exclusive, as macOS
// will report a full screen window as zoomed.
if (window.qt_fullScreen) {
states |= Qt::WindowFullScreen;
} else if ((window.zoomed && !isTransitioningToFullScreen())
|| (m_lastReportedWindowState == Qt::WindowMaximized && isTransitioningToFullScreen())) {
states |= Qt::WindowMaximized;
}
// Note: We do not report Qt::WindowActive, even if isActive()
// is true, as QtGui does not expect this window state to be set.
return Qt::WindowNoState;
return states;
}
void QCocoaWindow::toggleMaximized()
@ -872,7 +876,7 @@ void QCocoaWindow::windowDidDeminiaturize()
void QCocoaWindow::handleWindowStateChanged(HandleFlags flags)
{
Qt::WindowState currentState = windowState();
Qt::WindowStates currentState = windowState();
if (!(flags & HandleUnconditionally) && currentState == m_lastReportedWindowState)
return;