From 939bfb838ef2eae445749e38815845d8f899456c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tinja=20Paavosepp=C3=A4?= Date: Wed, 27 Mar 2024 13:42:05 +0200 Subject: [PATCH] Android/Embedding QML: Resize also parent window The parent window created from the QtView had an empty size. Also set its size when creating the window, and when resizing the QtView. Replace parent window show() call with showNormal() to avoid switching it to a fullscreen window. As a drive-by, use setGeometry() instead of setting the width and height separately to trigger only one geometry update for the platform window. Change-Id: I91e350c1748a9e76879faa8bfcab7575f6155f02 Reviewed-by: Assam Boudjelthia (cherry picked from commit e9edd3db524e0c9c77925ae5bea98017a6220ecf) Reviewed-by: Qt Cherry-pick Bot --- .../qtproject/qt/android/QtEmbeddedDelegate.java | 4 ++-- .../platforms/android/androidwindowembedding.cpp | 13 ++++++++----- .../platforms/android/androidwindowembedding.h | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegate.java b/src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegate.java index cbf715ab19f..eb17ab680eb 100644 --- a/src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegate.java +++ b/src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegate.java @@ -30,7 +30,7 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase implements QtNative.AppS private QtNative.ApplicationStateDetails m_stateDetails; private boolean m_windowLoaded = false; - private static native void createRootWindow(View rootView); + private static native void createRootWindow(View rootView, int width, int height); static native void deleteWindow(long windowReference); public QtEmbeddedDelegate(Activity context) { @@ -159,7 +159,7 @@ class QtEmbeddedDelegate extends QtActivityDelegateBase implements QtNative.AppS private void createRootWindow() { if (m_view != null && !m_windowLoaded) { - createRootWindow(m_view); + createRootWindow(m_view, m_view.getWidth(), m_view.getHeight()); m_windowLoaded = true; } } diff --git a/src/plugins/platforms/android/androidwindowembedding.cpp b/src/plugins/platforms/android/androidwindowembedding.cpp index e72bb326ccc..40c5b3c95f6 100644 --- a/src/plugins/platforms/android/androidwindowembedding.cpp +++ b/src/plugins/platforms/android/androidwindowembedding.cpp @@ -15,12 +15,13 @@ Q_DECLARE_JNI_CLASS(QtView, "org/qtproject/qt/android/QtView"); Q_DECLARE_JNI_CLASS(QtEmbeddedDelegate, "org/qtproject/qt/android/QtEmbeddedDelegate"); namespace QtAndroidWindowEmbedding { - void createRootWindow(JNIEnv *, jclass, QtJniTypes::View rootView) + void createRootWindow(JNIEnv *, jclass, QtJniTypes::View rootView, jint width, jint height) { // QWindow should be constructed on the Qt thread rather than directly in the caller thread // To avoid hitting checkReceiverThread assert in QCoreApplication::doNotify - QMetaObject::invokeMethod(qApp, [rootView] { + QMetaObject::invokeMethod(qApp, [rootView, width, height] { QWindow *parentWindow = QWindow::fromWinId(reinterpret_cast(rootView.object())); + parentWindow->setGeometry(0, 0, width, height); rootView.callMethod("createWindow", reinterpret_cast(parentWindow)); }); } @@ -38,7 +39,7 @@ namespace QtAndroidWindowEmbedding { if (visible) { window->showNormal(); if (!window->parent()->isVisible()) - window->parent()->show(); + window->parent()->showNormal(); } else { window->hide(); } @@ -48,8 +49,10 @@ namespace QtAndroidWindowEmbedding { void resizeWindow(JNIEnv *, jclass, jlong windowRef, jint width, jint height) { QWindow *window = reinterpret_cast(windowRef); - window->setWidth(width); - window->setHeight(height); + QWindow *parent = window->parent(); + if (parent) + parent->setGeometry(0, 0, width, height); + window->setGeometry(0, 0, width, height); } bool registerNatives(QJniEnvironment& env) { diff --git a/src/plugins/platforms/android/androidwindowembedding.h b/src/plugins/platforms/android/androidwindowembedding.h index 4f3261a30bd..cb0e5f90cea 100644 --- a/src/plugins/platforms/android/androidwindowembedding.h +++ b/src/plugins/platforms/android/androidwindowembedding.h @@ -25,7 +25,7 @@ Q_DECLARE_JNI_CLASS(View, "android/view/View"); namespace QtAndroidWindowEmbedding { bool registerNatives(QJniEnvironment& env); - void createRootWindow(JNIEnv *, jclass, QtJniTypes::View rootView); + void createRootWindow(JNIEnv *, jclass, QtJniTypes::View rootView, jint width, jint height); Q_DECLARE_JNI_NATIVE_METHOD_IN_CURRENT_SCOPE(createRootWindow) void deleteWindow(JNIEnv *, jclass, jlong window); Q_DECLARE_JNI_NATIVE_METHOD_IN_CURRENT_SCOPE(deleteWindow)