diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2021-09-30 17:22:31 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2021-10-14 17:19:38 +0000 |
commit | 74e634d82ced894f235526c7c2b6ac476c93e2bc (patch) | |
tree | d4a824ec11525aaca8fa1f74a40369be1fc0f68a /src/plugins/platforms/cocoa/qcocoawindow.mm | |
parent | e95e9c28f07e22ea76a7a5521c090a785133dbfd (diff) |
macOS: Correctly record normalGeometry in Cocoa plugin
Cocoa sends QWidget the state-change notification after the window has
been resized already, at which point we cannot store the normal geometry
anymore.
Handle zoom and full screen callbacks prior to the state changing
to store the geometry in QCocoaWindow. We do not need to handle
minimized state, as the window will still reflect the original
geometry.
Return the stored value from an override of
QPlatformWindow::normalGeometry so that QWidget gets the correct values
even though the new state is already active.
Fix the tst_QWidget::normalGeometry test to make it pass on all
platforms by waiting for the window to actually have transitioned to
the new state before comparing geometries. Both macOS and Windows fully
pass; on Xcb, deminimizing a window using setWindowState does not work,
which is why the test was partially skipped (confirmed by visual
testing). Move those problematic, complex test cases to the end so
that most cases are covered on Xcb as well.
Done-with: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Pick-to: 6.2
Change-Id: I518a5db9169b80e8fa25fe4fa2b50bd1ea0e6db3
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoawindow.mm')
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoawindow.mm | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index 4450af0500..1bc53bde5c 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -261,6 +261,40 @@ QRect QCocoaWindow::geometry() const return QPlatformWindow::geometry(); } +/*! + \brief the geometry of the window as it will appear when shown as + a normal (not maximized or full screen) top-level window. + + For child windows this property always holds an empty rectangle. + + \sa QWidget::normalGeometry() +*/ +QRect QCocoaWindow::normalGeometry() const +{ + if (!isContentView()) + return QRect(); + + // We only persist the normal the geometry when going into + // fullscreen and maximized states. For all other cases we + // can just report the geometry as is. + + if (!(windowState() & (Qt::WindowFullScreen | Qt::WindowMaximized))) + return geometry(); + + return m_normalGeometry; +} + +void QCocoaWindow::updateNormalGeometry() +{ + if (!isContentView()) + return; + + if (windowState() != Qt::WindowNoState) + return; + + m_normalGeometry = geometry(); +} + void QCocoaWindow::setCocoaGeometry(const QRect &rect) { qCDebug(lcQpaWindow) << "QCocoaWindow::setCocoaGeometry" << window() << rect; @@ -754,6 +788,11 @@ void QCocoaWindow::toggleMaximized() window.styleMask &= ~NSWindowStyleMaskResizable; } +void QCocoaWindow::windowWillZoom() +{ + updateNormalGeometry(); +} + void QCocoaWindow::toggleFullScreen() { const NSWindow *window = m_view.window; @@ -772,6 +811,8 @@ void QCocoaWindow::windowWillEnterFullScreen() if (!isContentView()) return; + updateNormalGeometry(); + // 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. |