diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2024-03-16 11:49:59 +0100 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2024-03-19 23:04:46 +0100 |
commit | 2da738f03589b2bb53e921b5fec347bdd6b68b16 (patch) | |
tree | fe0bf7bdaecca954d2446447fdc2fd0f370f4230 /src/plugins/platforms | |
parent | 4662e80755b3002585280cfe9076d2c6c14f1e5b (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
Pick-to: 6.7 6.6 6.5
Change-Id: Ie734fc477b37a7e39e6fb16d7738d3f69731a975
Reviewed-by: Amr Elsayed <amr.elsayed@qt.io>
Reviewed-by: Doris Verria <doris.verria@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'src/plugins/platforms')
-rw-r--r-- | src/plugins/platforms/ios/qioswindow.mm | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/src/plugins/platforms/ios/qioswindow.mm b/src/plugins/platforms/ios/qioswindow.mm index 3a4048a49b..3631d6be70 100644 --- a/src/plugins/platforms/ios/qioswindow.mm +++ b/src/plugins/platforms/ios/qioswindow.mm @@ -251,22 +251,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); } |