summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTinja Paavoseppä <tinja.paavoseppa@qt.io>2024-03-27 15:31:34 +0200
committerTinja Paavoseppä <tinja.paavoseppa@qt.io>2024-04-04 15:46:44 +0200
commitd45ce587784427c4ff72d306811eb63baa53cb3a (patch)
tree2f0f09c7d091c139f928b41edb3155710d82d0b7
parente9edd3db524e0c9c77925ae5bea98017a6220ecf (diff)
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. Pick-to: 6.7 Change-Id: I0ea89a11e4526a0a996e7b62ac126808358b6bc7 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
-rw-r--r--src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegate.java4
-rw-r--r--src/android/jar/src/org/qtproject/qt/android/QtView.java9
-rw-r--r--src/plugins/platforms/android/androidwindowembedding.cpp11
-rw-r--r--src/plugins/platforms/android/androidwindowembedding.h5
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 2fb788ab82..9a34afa51b 100644
--- a/src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegate.java
+++ b/src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegate.java
@@ -28,7 +28,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) {
@@ -157,7 +157,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 afd3030804..6836171187 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 40c5b3c95f..20021283c5 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<WId>(rootView.object()));
- parentWindow->setGeometry(0, 0, width, height);
+ parentWindow->setGeometry(x, y, width, height);
rootView.callMethod<void>("createWindow", reinterpret_cast<jlong>(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<QWindow*>(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 cb0e5f90ce..b7b0e1205f 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)
};