iOS: Report inverted screen orientations via windowScene orientation

In bc014d5fc705e95bb34b7729b2c3bb5f9539d777 we stopped using the device
orientation as source for the QScreen orientation, as the former reports
the orientation independently of any locked orientation, while QScreen
is supposed to reflect the logical window-manager orientation.

However in doing that we lost the inverse orientations, which can be
useful in some cases.

We now use UIWindowScene.interfaceOrientation as input, and fall back
to the primary orientation only if we can't resolve the window scene's
orientation.

Interestingly, for visionOS, UIWindowScene.interfaceOrientation reports
portrait orientation, which should be investigated further, but for now
we trust what the system gives us.

[ChangeLog][iOS] QScreen::orientation() now reflects the inverse
portrait and landscape orientations, as long as system allows
rotating the UI to those orientations.

Fixes: QTBUG-137249
Pick-to: 6.10 6.9 6.8
Change-Id: I8d20f05e72abcec446fd39342c8632960337943a
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Doris Verria <doris.verria@qt.io>
This commit is contained in:
Tor Arne Vestbø 2025-06-02 13:20:30 +02:00
parent 5618710d63
commit a8dab6eb65

View File

@ -408,8 +408,32 @@ Qt::ScreenOrientation QIOSScreen::orientation() const
// even if the orientation of the UI was locked to a subset
// of the possible orientations via the app's Info.plist or
// via [UIViewController supportedInterfaceOrientations].
return m_geometry.width() >= m_geometry.height() ?
Qt::LandscapeOrientation : Qt::PortraitOrientation;
auto *windowScene = rootViewForScreen(this).window.windowScene;
auto interfaceOrientation = windowScene ?
windowScene.interfaceOrientation : UIInterfaceOrientationUnknown;
// FIXME: On visionOS the interface orientation is reported
// as portrait, which seems strange, but at least it matches
// what we report as the native orientation.
switch (interfaceOrientation) {
case UIInterfaceOrientationPortrait:
return Qt::PortraitOrientation;
case UIInterfaceOrientationPortraitUpsideDown:
return Qt::InvertedPortraitOrientation;
case UIInterfaceOrientationLandscapeLeft:
return Qt::LandscapeOrientation;
case UIInterfaceOrientationLandscapeRight:
return Qt::InvertedLandscapeOrientation;
case UIInterfaceOrientationUnknown:
default:
// Fall back to the primary orientation, but with a concrete
// orientation instead of Qt::PrimaryOrientation, as when we
// report orientation changes the primary orientation has not
// been updated yet, so user's can't query it in response.
return m_geometry.width() >= m_geometry.height() ?
Qt::LandscapeOrientation : Qt::PortraitOrientation;
}
}
QPixmap QIOSScreen::grabWindow(WId window, int x, int y, int width, int height) const