visionOS: Report size of root view as screen size

Even though we've decoupled QIOSScreen from managing UIWindows, we still
have one UIWindow per screen, so we can pull out the bounds of that root
view to determine Qt's screen geometry.

Change-Id: I05993ad6d629dd2158681dd17355b7e216bfbb49
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
(cherry picked from commit 16483487c4e37546cf296a72e137d49d28b55e05)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Tor Arne Vestbø 2024-07-04 19:43:18 +02:00 committed by Qt Cherry-pick Bot
parent 63ad52d991
commit ea1978c7f9
4 changed files with 8 additions and 6 deletions

View File

@ -39,7 +39,7 @@ int infoPlistValue(NSString* key, int defaultValue);
class QWindow;
class QScreen;
UIWindow *presentationWindow(QWindow *);
UIView *rootViewForScreen(QScreen *);
UIView *rootViewForScreen(const QPlatformScreen *);
QT_END_NAMESPACE

View File

@ -108,9 +108,11 @@ UIWindow *presentationWindow(QWindow *window)
return uiWindow;
}
UIView *rootViewForScreen(QScreen *screen)
UIView *rootViewForScreen(const QPlatformScreen *screen)
{
const auto *iosScreen = static_cast<QIOSScreen *>(screen->handle());
Q_ASSERT(screen);
const auto *iosScreen = static_cast<const QIOSScreen *>(screen);
for (UIScene *scene in [qt_apple_sharedApplication().connectedScenes allObjects]) {
if (![scene isKindOfClass:UIWindowScene.class])
continue;

View File

@ -209,7 +209,7 @@ void QIOSScreen::updateProperties()
#if defined(Q_OS_VISIONOS)
// Based on what iPad app reports
m_geometry = QRect(0, 0, 1194, 834);
m_geometry = QRectF::fromCGRect(rootViewForScreen(this).bounds).toRect();
m_depth = 24;
#else
m_geometry = QRectF::fromCGRect(m_uiScreen.bounds).toRect();
@ -377,7 +377,7 @@ QPixmap QIOSScreen::grabWindow(WId window, int x, int y, int width, int height)
return QPixmap();
UIView *view = window ? reinterpret_cast<UIView *>(window)
: rootViewForScreen(screen());
: rootViewForScreen(this);
if (width < 0)
width = qMax(view.bounds.size.width - x, CGFloat(0));

View File

@ -298,7 +298,7 @@ void QIOSWindow::setParent(const QPlatformWindow *parentWindow)
if (parentWindow)
superview = reinterpret_cast<UIView *>(parentWindow->winId());
else if (isQtApplication() && !isForeignWindow())
superview = rootViewForScreen(window()->screen());
superview = rootViewForScreen(window()->screen()->handle());
if (superview)
[superview addSubview:m_view];