diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2017-02-06 15:28:23 +0100 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2017-02-16 14:32:00 +0000 |
commit | ef32f16fc284e5017da6016f72a17957fa2fef34 (patch) | |
tree | d87fee6aec8e85d55d02730fe117289af4c65a6c /src/plugins/platforms/cocoa/qnswindowdelegate.mm | |
parent | 925a3c65297edc37e394b9837782e79d837d20d1 (diff) |
macOS: Rewrite window state handling
Instead of relying on specific notifications to change the window
state we now evaluate the state based on the current window state.
This allows us to get rid of windowShouldZoom in the window delegate,
making window state handling work for foreign windows as well, and
also allows us to re-evaluate the state in more places, such as
when moving a window, which may bring it out of maximized state.
The full screen state is tracked by a helper category that doesn't
just rely on the styleFlag, but also on the full screen notifications.
This is needed as macOS will complain if you try to go in or out of
fullscreen while a transition is in effect.
The differentiation between performFoo: and foo: has been removed,
as the latter works in both cases and doesn't rely on the button
being visible/enabled.
These changes fixes many observed quirks in the window state handling
that also resulted in making it hard to write tests that relied on
the fullscreen/maximized operations always working.
Change-Id: I0538c42d9223a56f20ec9156f4939288e0750552
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/plugins/platforms/cocoa/qnswindowdelegate.mm')
-rw-r--r-- | src/plugins/platforms/cocoa/qnswindowdelegate.mm | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/plugins/platforms/cocoa/qnswindowdelegate.mm b/src/plugins/platforms/cocoa/qnswindowdelegate.mm index 2d5afa9375..ce74aa9973 100644 --- a/src/plugins/platforms/cocoa/qnswindowdelegate.mm +++ b/src/plugins/platforms/cocoa/qnswindowdelegate.mm @@ -41,6 +41,7 @@ #include "qcocoahelpers.h" #include <QDebug> +#include <qpa/qplatformscreen.h> #include <qpa/qwindowsysteminterface.h> @implementation QNSWindowDelegate @@ -62,13 +63,19 @@ return YES; } - -- (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame +/*! + Overridden to ensure that the zoomed state always results in a maximized + window, which would otherwise not be the case for borderless windows. +*/ +- (NSRect)windowWillUseStandardFrame:(NSWindow *)window defaultFrame:(NSRect)newFrame { Q_UNUSED(newFrame); - if (m_cocoaWindow && !m_cocoaWindow->isForeignWindow()) - [qnsview_cast(m_cocoaWindow->view()) notifyWindowWillZoom:![window isZoomed]]; - return YES; + + // We explicitly go through the QScreen API here instead of just using + // window.screen.visibleFrame directly, as that ensures we have the same + // behavior for both use-cases/APIs. + Q_ASSERT(window == m_cocoaWindow->nativeWindow()); + return m_cocoaWindow->screen()->availableGeometry().toCGRect(); } - (BOOL)window:(NSWindow *)window shouldPopUpDocumentPathMenu:(NSMenu *)menu |