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 <assam.boudjelthia@qt.io>
(cherry picked from commit d45ce587784427c4ff72d306811eb63baa53cb3a)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Tinja Paavoseppä 2024-03-27 15:31:34 +02:00 committed by Qt Cherry-pick Bot
parent 939bfb838e
commit f3b91c0dae
4 changed files with 17 additions and 12 deletions

View File

@ -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;
}
}

View File

@ -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);
}
}
}
});

View File

@ -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);
}

View File

@ -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)
};