Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
androidwindowembedding.cpp
Go to the documentation of this file.
1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
6
7#include <QtCore/qcoreapplication.h>
8#include <QtCore/qjnienvironment.h>
9#include <QtCore/qjniobject.h>
10#include <QtCore/qjnitypes.h>
11#include <QtGui/qwindow.h>
12
14
15Q_DECLARE_JNI_CLASS(QtView, "org/qtproject/qt/android/QtView");
16
18 void createRootWindow(JNIEnv *, jclass, QtJniTypes::View rootView,
19 jint x, jint y, jint width, jint height)
20 {
21 // QWindow should be constructed on the Qt thread rather than directly in the caller thread
22 // To avoid hitting checkReceiverThread assert in QCoreApplication::doNotify
23 QMetaObject::invokeMethod(qApp, [rootView, x, y, width, height] {
24 QWindow *parentWindow = QWindow::fromWinId(reinterpret_cast<WId>(rootView.object()));
25 parentWindow->setGeometry(x, y, width, height);
26 rootView.callMethod<void>("createWindow", reinterpret_cast<jlong>(parentWindow));
27 });
28 }
29
30 void deleteWindow(JNIEnv *, jclass, jlong windowRef)
31 {
32 QWindow *window = reinterpret_cast<QWindow*>(windowRef);
33 window->deleteLater();
34 }
35
36 void setWindowVisible(JNIEnv *, jclass, jlong windowRef, jboolean visible)
37 {
38 QMetaObject::invokeMethod(qApp, [windowRef, visible] {
39 QWindow *window = reinterpret_cast<QWindow*>(windowRef);
40 if (visible) {
41 window->showNormal();
42 if (!window->parent()->isVisible())
43 window->parent()->showNormal();
44 } else {
45 window->hide();
46 }
47 });
48 }
49
50 void resizeWindow(JNIEnv *, jclass, jlong windowRef, jint x, jint y, jint width, jint height)
51 {
52 QMetaObject::invokeMethod(qApp, [windowRef, x, y, width, height] {
53 QWindow *window = reinterpret_cast<QWindow*>(windowRef);
54 QWindow *parent = window->parent();
55 if (parent)
56 parent->setGeometry(x, y, width, height);
57 window->setGeometry(0, 0, width, height);
58 });
59 }
60
61 bool registerNatives(QJniEnvironment& env) {
62 return env.registerNativeMethods(
63 QtJniTypes::Traits<QtJniTypes::QtView>::className(),
64 { Q_JNI_NATIVE_SCOPED_METHOD(createRootWindow, QtAndroidWindowEmbedding),
65 Q_JNI_NATIVE_SCOPED_METHOD(deleteWindow, QtAndroidWindowEmbedding),
66 Q_JNI_NATIVE_SCOPED_METHOD(setWindowVisible, QtAndroidWindowEmbedding),
67 Q_JNI_NATIVE_SCOPED_METHOD(resizeWindow, QtAndroidWindowEmbedding) });
68 }
69}
70
71QT_END_NAMESPACE
Combined button and popup list for selecting options.
bool registerNatives(QJniEnvironment &env)
void setWindowVisible(JNIEnv *, jclass, jlong windowRef, jboolean visible)
void createRootWindow(JNIEnv *, jclass, QtJniTypes::View rootView, jint x, jint y, jint width, jint height)
void resizeWindow(JNIEnv *, jclass, jlong windowRef, jint x, jint y, jint width, jint height)
void deleteWindow(JNIEnv *, jclass, jlong windowRef)