From f3b91c0daea7c18b26e8fa1a914db55ac471f81a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tinja=20Paavosepp=C3=A4?= Date: Wed, 27 Mar 2024 15:31:34 +0200 Subject: [PATCH] Android/QtView: Set also x and y of the wrapped foreign QWindow Previously, we have set the size of the QWindow to match the QtView. Also set its x and y coordinate to match, just to keep the window and the view in sync. Change-Id: I0ea89a11e4526a0a996e7b62ac126808358b6bc7 Reviewed-by: Assam Boudjelthia (cherry picked from commit d45ce587784427c4ff72d306811eb63baa53cb3a) Reviewed-by: Qt Cherry-pick Bot --- .../org/qtproject/qt/android/QtEmbeddedDelegate.java | 4 ++-- .../jar/src/org/qtproject/qt/android/QtView.java | 9 ++++++--- .../platforms/android/androidwindowembedding.cpp | 11 ++++++----- .../platforms/android/androidwindowembedding.h | 5 +++-- 4 files changed, 17 insertions(+), 12 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 eb17ab680eb..2d0ea84b9e8 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, int width, int height); + private static native void createRootWindow(View rootView, int x, int y, 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, m_view.getWidth(), m_view.getHeight()); + createRootWindow(m_view, m_view.getLeft(), m_view.getTop(), m_view.getWidth(), m_view.getHeight()); m_windowLoaded = true; } } diff --git a/src/android/jar/src/org/qtproject/qt/android/QtView.java b/src/android/jar/src/org/qtproject/qt/android/QtView.java index afd30308046..6836171187e 100644 --- a/src/android/jar/src/org/qtproject/qt/android/QtView.java +++ b/src/android/jar/src/org/qtproject/qt/android/QtView.java @@ -38,7 +38,8 @@ abstract class QtView extends ViewGroup { abstract protected void createWindow(long parentWindowRef); private static native void setWindowVisible(long windowReference, boolean visible); - private static native void resizeWindow(long windowReference, int width, int height); + private static native void resizeWindow(long windowReference, + int x, int y, int width, int height); /** * Create QtView for embedding a QWindow. Instantiating a QtView will load the Qt libraries @@ -67,8 +68,10 @@ abstract class QtView extends ViewGroup { final int oldHeight = oldBottom - oldTop; final int newWidth = right - left; final int newHeight = bottom - top; - if (oldWidth != newWidth || oldHeight != newHeight) - resizeWindow(m_windowReference, right - left, bottom - top); + if (oldWidth != newWidth || oldHeight != newHeight || left != oldLeft || + top != oldTop) { + resizeWindow(m_windowReference, left, top, newWidth, newHeight); + } } } }); diff --git a/src/plugins/platforms/android/androidwindowembedding.cpp b/src/plugins/platforms/android/androidwindowembedding.cpp index 40c5b3c95f6..20021283c57 100644 --- a/src/plugins/platforms/android/androidwindowembedding.cpp +++ b/src/plugins/platforms/android/androidwindowembedding.cpp @@ -15,13 +15,14 @@ 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, jint width, jint height) + void createRootWindow(JNIEnv *, jclass, QtJniTypes::View rootView, + jint x, jint y, 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, width, height] { + QMetaObject::invokeMethod(qApp, [rootView, x, y, width, height] { QWindow *parentWindow = QWindow::fromWinId(reinterpret_cast(rootView.object())); - parentWindow->setGeometry(0, 0, width, height); + parentWindow->setGeometry(x, y, width, height); rootView.callMethod("createWindow", reinterpret_cast(parentWindow)); }); } @@ -46,12 +47,12 @@ namespace QtAndroidWindowEmbedding { }); } - void resizeWindow(JNIEnv *, jclass, jlong windowRef, jint width, jint height) + void resizeWindow(JNIEnv *, jclass, jlong windowRef, jint x, jint y, jint width, jint height) { QWindow *window = reinterpret_cast(windowRef); QWindow *parent = window->parent(); if (parent) - parent->setGeometry(0, 0, width, height); + parent->setGeometry(x, y, width, height); window->setGeometry(0, 0, width, height); } diff --git a/src/plugins/platforms/android/androidwindowembedding.h b/src/plugins/platforms/android/androidwindowembedding.h index cb0e5f90cea..b7b0e1205ff 100644 --- a/src/plugins/platforms/android/androidwindowembedding.h +++ b/src/plugins/platforms/android/androidwindowembedding.h @@ -25,13 +25,14 @@ Q_DECLARE_JNI_CLASS(View, "android/view/View"); namespace QtAndroidWindowEmbedding { bool registerNatives(QJniEnvironment& env); - void createRootWindow(JNIEnv *, jclass, QtJniTypes::View rootView, jint width, jint height); + void createRootWindow(JNIEnv *, jclass, QtJniTypes::View rootView, + jint x, jint y,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) void setWindowVisible(JNIEnv *, jclass, jlong window, jboolean visible); Q_DECLARE_JNI_NATIVE_METHOD_IN_CURRENT_SCOPE(setWindowVisible) - void resizeWindow(JNIEnv *, jclass, jlong windowRef, jint width, jint height); + void resizeWindow(JNIEnv *, jclass, jlong windowRef, jint x, jint y, jint width, jint height); Q_DECLARE_JNI_NATIVE_METHOD_IN_CURRENT_SCOPE(resizeWindow) };