summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Arne Vestbø <[email protected]>2024-03-16 11:49:59 +0100
committerQt Cherry-pick Bot <[email protected]>2024-04-03 11:09:09 +0000
commita43d76dcf93ef6a1590d459198bf6d503f8bfe39 (patch)
tree984bbdc8adc8c6ae7d447b36c1c5db462d3540a3
parent8a360aa39b57a3eea71ccf965550e1ff43e895d7 (diff)
iOS: Use UIWindow bounds for fullscreen/maximized geometry on macOS
In modern iPad apps, windows can be moved between screens, just like regular macOS apps, but we don't reflect this as changes to the QWindow's screen, meaning the screen() is not reliable input when computing a window's full screen or maximized geometry. In addition, when running iOS apps on macOS as "Designed for iPad", the system will scale the UI down by 77%, to better match metrics (fonts, sizes) to the macOS environment. Classes like UIView and UIWindow are oblivious to this scaling, and will think they are larger than what they really are on the screen. However, UIScreen, for some reason, reflects the actual screen size, instead of taking part in the "inflated" view of the world. As a result, even if screen() would reflect the correct screen the window is on, we can't use the screen geometry for clamping the window geometry, as the two have separate coordinate systems. We could scale up the QScreen geometry accordingly to work around this, but we don't know if the UIScreen behavior is a bug or not, so instead we skip the screen() as input and use the UIWindow bounds directly. Task-number: QTBUG-121781 Fixes: QTBUG-106709 Change-Id: Ie734fc477b37a7e39e6fb16d7738d3f69731a975 Reviewed-by: Amr Elsayed <[email protected]> Reviewed-by: Doris Verria <[email protected]> Reviewed-by: Timur Pocheptsov <[email protected]> (cherry picked from commit 2da738f03589b2bb53e921b5fec347bdd6b68b16) Reviewed-by: Qt Cherry-pick Bot <[email protected]> (cherry picked from commit 5195c6683d6d1c262227f67c9954e80c21f54156) (cherry picked from commit 0b70ca278a2c3b3005ab4d4601f6b5d6abbee539)
-rw-r--r--src/plugins/platforms/ios/qioswindow.mm40
1 files changed, 25 insertions, 15 deletions
diff --git a/src/plugins/platforms/ios/qioswindow.mm b/src/plugins/platforms/ios/qioswindow.mm
index 912d4fae895..f2d0133aa56 100644
--- a/src/plugins/platforms/ios/qioswindow.mm
+++ b/src/plugins/platforms/ios/qioswindow.mm
@@ -229,22 +229,32 @@ void QIOSWindow::setWindowState(Qt::WindowStates state)
if (state & Qt::WindowMinimized) {
applyGeometry(QRect());
} else if (state & (Qt::WindowFullScreen | Qt::WindowMaximized)) {
- // When an application is in split-view mode, the UIScreen still has the
- // same geometry, but the UIWindow is resized to the area reserved for the
- // application. We use this to constrain the geometry used when applying the
- // fullscreen or maximized window states. Note that we do not do this
- // in applyGeometry(), as we don't want to artificially limit window
- // placement "outside" of the screen bounds if that's what the user wants.
-
QRect uiWindowBounds = QRectF::fromCGRect(m_view.window.bounds).toRect();
- QRect fullscreenGeometry = screen()->geometry().intersected(uiWindowBounds);
- QRect maximizedGeometry = window()->flags() & Qt::MaximizeUsingFullscreenGeometryHint ?
- fullscreenGeometry : screen()->availableGeometry().intersected(uiWindowBounds);
-
- if (state & Qt::WindowFullScreen)
- applyGeometry(fullscreenGeometry);
- else
- applyGeometry(maximizedGeometry);
+ if (NSProcessInfo.processInfo.iOSAppOnMac) {
+ // iOS apps running as "Designed for iPad" on macOS do not match
+ // our current window management implementation where a single
+ // UIWindow is tied to a single screen. And even if we're on the
+ // right screen, the UIScreen does not account for the 77% scale
+ // of the UIUserInterfaceIdiomPad environment, so we can't use
+ // it to clamp the window geometry. Instead just use the UIWindow
+ // directly, which represents our "screen".
+ applyGeometry(uiWindowBounds);
+ } else {
+ // When an application is in split-view mode, the UIScreen still has the
+ // same geometry, but the UIWindow is resized to the area reserved for the
+ // application. We use this to constrain the geometry used when applying the
+ // fullscreen or maximized window states. Note that we do not do this
+ // in applyGeometry(), as we don't want to artificially limit window
+ // placement "outside" of the screen bounds if that's what the user wants.
+ QRect fullscreenGeometry = screen()->geometry().intersected(uiWindowBounds);
+ QRect maximizedGeometry = window()->flags() & Qt::MaximizeUsingFullscreenGeometryHint ?
+ fullscreenGeometry : screen()->availableGeometry().intersected(uiWindowBounds);
+
+ if (state & Qt::WindowFullScreen)
+ applyGeometry(fullscreenGeometry);
+ else
+ applyGeometry(maximizedGeometry);
+ }
} else {
applyGeometry(m_normalGeometry);
}