From 913552ad0b895581b9842849d7525b5049a8b30b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 4 Jul 2024 13:28:47 +0200 Subject: [PATCH] Android: Create QtWindow before applying QWindow geometry during init During QAndroidPlatformWindow::initialize() we call setGeometry, which may end up in QAndroidPlatformWindow::setNativeGeometry() via one of the QAndroidPlatformWindow subclasses, i.e. GL, Vulkan, or foreign window. We currently bail out from setNativeGeometry if !m_surfaceCreated, but this is only a workaround for the m_nativeQtWindow not being alive yet. As long as we have a m_nativeQtWindow, we should be able to set the layout parameters of that QtWindow, independently of whether it has a QtSurface or is hosting a foreign Android view. As a start, move the QtWindow initialization earlier in initialize(). The isEmbeddingContainer() check can go at the top, as we shouldn't do any modifications to a window that's purely used to act as a container when embedding Qt in native Android apps. Change-Id: Ia3f0b33e6729f5399946d86799f39877d058511b Reviewed-by: Assam Boudjelthia Reviewed-by: Petri Virkkunen (cherry picked from commit e2ce1f724f56db8072033665d066ad34f4d4c702) Reviewed-by: Qt Cherry-pick Bot --- .../android/qandroidplatformwindow.cpp | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/plugins/platforms/android/qandroidplatformwindow.cpp b/src/plugins/platforms/android/qandroidplatformwindow.cpp index 8f68d04849a..b8d9351e87c 100644 --- a/src/plugins/platforms/android/qandroidplatformwindow.cpp +++ b/src/plugins/platforms/android/qandroidplatformwindow.cpp @@ -30,8 +30,27 @@ QAndroidPlatformWindow::QAndroidPlatformWindow(QWindow *window) void QAndroidPlatformWindow::initialize() { + if (isEmbeddingContainer()) + return; + QWindow *window = QPlatformWindow::window(); + if (parent()) { + QAndroidPlatformWindow *androidParent = static_cast(parent()); + if (!androidParent->isEmbeddingContainer()) + m_nativeParentQtWindow = androidParent->nativeWindow(); + } + + AndroidBackendRegister *reg = QtAndroid::backendRegister(); + QtJniTypes::QtInputConnectionListener listener = + reg->callInterface( + "getInputConnectionListener"); + + m_nativeQtWindow = QJniObject::construct( + QNativeInterface::QAndroidApplication::context(), + isForeignWindow(), m_nativeParentQtWindow, listener); + m_nativeViewId = m_nativeQtWindow.callMethod("getId"); + m_windowFlags = Qt::Widget; m_windowState = Qt::WindowNoState; // the surfaceType is overwritten in QAndroidPlatformOpenGLWindow ctor so let's save @@ -57,25 +76,6 @@ void QAndroidPlatformWindow::initialize() setGeometry(finalNativeGeometry); } - if (isEmbeddingContainer()) - return; - - if (parent()) { - QAndroidPlatformWindow *androidParent = static_cast(parent()); - if (!androidParent->isEmbeddingContainer()) - m_nativeParentQtWindow = androidParent->nativeWindow(); - } - - AndroidBackendRegister *reg = QtAndroid::backendRegister(); - QtJniTypes::QtInputConnectionListener listener = - reg->callInterface( - "getInputConnectionListener"); - - m_nativeQtWindow = QJniObject::construct( - QNativeInterface::QAndroidApplication::context(), - isForeignWindow(), m_nativeParentQtWindow, listener); - m_nativeViewId = m_nativeQtWindow.callMethod("getId"); - if (window->isTopLevel()) platformScreen()->addWindow(this);