summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/ios/qiosglobal.mm
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2024-04-10 11:45:39 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2024-04-19 18:03:55 +0200
commit76ebf51bc08f6af624a8540e7af88b9129b22ae1 (patch)
tree5e7c46864288e6e977e3652f519158b01fb62b89 /src/plugins/platforms/ios/qiosglobal.mm
parent409dd9688d37dfe27691b1c5bde993c4512e612e (diff)
iOS: Decouple UIWindow management from QIOSScreen
We now adopt the UIScene lifecycle, where we react to iOS creating UIWindowScenes for connected screens, which we then configure with a single instance of our QUIWindow, that in turn contains the QIOSViewController and QIOSDesktopManagerView that we depend on for our window management. As a result, we can now create and show QWindows on visionOS, which doesn't have UIScreen and hence failed with our old strategy managing our UIWindow via UISScreen. We still do not declare a UIApplicationSceneManifest in our Info.plist, or report UIApplicationSupportsMultipleScenes, as this adds another level to the window management that we're not ready for yet. Task-number: QTBUG-121781 Change-Id: Ic02f43aa6b205289a3f3c8e72c2a6ef575031d9a Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/plugins/platforms/ios/qiosglobal.mm')
-rw-r--r--src/plugins/platforms/ios/qiosglobal.mm27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/plugins/platforms/ios/qiosglobal.mm b/src/plugins/platforms/ios/qiosglobal.mm
index eb9e713b0d..25ccf2961b 100644
--- a/src/plugins/platforms/ios/qiosglobal.mm
+++ b/src/plugins/platforms/ios/qiosglobal.mm
@@ -13,6 +13,7 @@ QT_BEGIN_NAMESPACE
Q_LOGGING_CATEGORY(lcQpaApplication, "qt.qpa.application");
Q_LOGGING_CATEGORY(lcQpaInputMethods, "qt.qpa.input.methods");
Q_LOGGING_CATEGORY(lcQpaWindow, "qt.qpa.window");
+Q_LOGGING_CATEGORY(lcQpaWindowScene, "qt.qpa.window.scene");
bool isQtApplication()
{
@@ -109,6 +110,32 @@ UIWindow *presentationWindow(QWindow *window)
return uiWindow;
}
+UIView *rootViewForScreen(QScreen *screen)
+{
+ const auto *iosScreen = static_cast<QIOSScreen *>(screen->handle());
+ for (UIScene *scene in [qt_apple_sharedApplication().connectedScenes allObjects]) {
+ if (![scene isKindOfClass:UIWindowScene.class])
+ continue;
+
+ auto *windowScene = static_cast<UIWindowScene*>(scene);
+
+#if !defined(Q_OS_VISIONOS)
+ if (windowScene.screen != iosScreen->uiScreen())
+ continue;
+#else
+ Q_UNUSED(iosScreen);
+#endif
+
+ UIWindow *uiWindow = windowScene.keyWindow;
+ if (!uiWindow && windowScene.windows.count)
+ uiWindow = windowScene.windows[0];
+
+ return uiWindow.rootViewController.view;
+ }
+
+ return nullptr;
+}
+
QT_END_NAMESPACE
// -------------------------------------------------------------------------