summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/android/qandroidplatformwindow.cpp
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2024-07-04 13:28:47 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2024-08-08 01:48:35 +0200
commite2ce1f724f56db8072033665d066ad34f4d4c702 (patch)
tree1f25baf938e51bd030bddc256e275a1365971ddc /src/plugins/platforms/android/qandroidplatformwindow.cpp
parenteea00824bdbc6740261d2b78821e31c1f21c9c0c (diff)
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. Pick-to: 6.8 Change-Id: Ia3f0b33e6729f5399946d86799f39877d058511b Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> Reviewed-by: Petri Virkkunen <petri.virkkunen@qt.io>
Diffstat (limited to 'src/plugins/platforms/android/qandroidplatformwindow.cpp')
-rw-r--r--src/plugins/platforms/android/qandroidplatformwindow.cpp38
1 files 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<QAndroidPlatformWindow*>(parent());
+ if (!androidParent->isEmbeddingContainer())
+ m_nativeParentQtWindow = androidParent->nativeWindow();
+ }
+
+ AndroidBackendRegister *reg = QtAndroid::backendRegister();
+ QtJniTypes::QtInputConnectionListener listener =
+ reg->callInterface<QtJniTypes::QtInputInterface, QtJniTypes::QtInputConnectionListener>(
+ "getInputConnectionListener");
+
+ m_nativeQtWindow = QJniObject::construct<QtJniTypes::QtWindow>(
+ QNativeInterface::QAndroidApplication::context(),
+ isForeignWindow(), m_nativeParentQtWindow, listener);
+ m_nativeViewId = m_nativeQtWindow.callMethod<jint>("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<QAndroidPlatformWindow*>(parent());
- if (!androidParent->isEmbeddingContainer())
- m_nativeParentQtWindow = androidParent->nativeWindow();
- }
-
- AndroidBackendRegister *reg = QtAndroid::backendRegister();
- QtJniTypes::QtInputConnectionListener listener =
- reg->callInterface<QtJniTypes::QtInputInterface, QtJniTypes::QtInputConnectionListener>(
- "getInputConnectionListener");
-
- m_nativeQtWindow = QJniObject::construct<QtJniTypes::QtWindow>(
- QNativeInterface::QAndroidApplication::context(),
- isForeignWindow(), m_nativeParentQtWindow, listener);
- m_nativeViewId = m_nativeQtWindow.callMethod<jint>("getId");
-
if (window->isTopLevel())
platformScreen()->addWindow(this);