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
qandroidplatformwindow.h
Go to the documentation of this file.
1// Copyright (C) 2014 BogDan Vatra <bogdan@kde.org>
2// Copyright (C) 2016 The Qt Company Ltd.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#ifndef ANDROIDPLATFORMWINDOW_H
6#define ANDROIDPLATFORMWINDOW_H
7#include <qobject.h>
8#include <qrect.h>
9#include <qpa/qplatformwindow.h>
10#include <QtCore/qjnienvironment.h>
11#include <QtCore/qjniobject.h>
12#include <QtCore/qjnitypes.h>
13#include <QtCore/qloggingcategory.h>
14#include <QtCore/qmutex.h>
15#include <QtCore/qwaitcondition.h>
16#include <jni.h>
17
19
20Q_DECLARE_LOGGING_CATEGORY(lcQpaWindow)
21Q_DECLARE_JNI_CLASS(QtWindow, "org/qtproject/qt/android/QtWindow")
22Q_DECLARE_JNI_CLASS(Surface, "android/view/Surface")
23Q_DECLARE_JNI_CLASS(Insets, "android/graphics/Insets")
24
25class QAndroidPlatformScreen;
26
28{
29public:
34
35 explicit QAndroidPlatformWindow(QWindow *window);
36 void initialize() override;
37
39 void lower() override;
40 void raise() override;
41
42 void setVisible(bool visible) override;
43
44 void setWindowState(Qt::WindowStates state) override;
45 void setWindowFlags(Qt::WindowFlags flags) override;
46 Qt::WindowFlags windowFlags() const;
47 void setParent(const QPlatformWindow *window) override;
48
49 WId winId() const override;
50
51 bool setMouseGrabEnabled(bool grab) override { Q_UNUSED(grab); return false; }
52 bool setKeyboardGrabEnabled(bool grab) override { Q_UNUSED(grab); return false; }
53
55
56 QMargins safeAreaMargins() const override;
57 void setSafeAreaMargins(const QMargins safeMargins);
58
63 inline bool isRaster() const { return m_isRaster; }
64 bool isExposed() const override;
65 QtJniTypes::QtWindow nativeWindow() const { return m_nativeQtWindow; }
66
68 int nativeViewId() const { return m_nativeViewId; }
69
70 static bool registerNatives(QJniEnvironment &env);
71 void onSurfaceChanged(QtJniTypes::Surface surface);
72
73 void lockSurface() { m_surfaceMutex.lock(); }
74 void unlockSurface() { m_surfaceMutex.unlock(); }
75
76protected:
77 void setGeometry(const QRect &rect) override;
78 void createSurface();
79 void destroySurface();
80 void sendExpose() const;
81 bool blockedByModal() const;
82 bool isEmbeddingContainer() const;
83 virtual void clearSurface() {}
84
88
93 // The Android Surface, accessed from multiple threads, guarded by m_surfaceMutex.
94 // If the window is using QtSurface, which is a SurfaceView subclass, this Surface will be
95 // automatically created by Android when QtSurface is in a layout and visible. If the
96 // QtSurface is detached or hidden (app goes to background), Android will automatically
97 // destroy the Surface.
103
105
106private:
107 static void setSurface(JNIEnv *env, jobject obj, jint windowId, QtJniTypes::Surface surface);
110 Q_DECLARE_JNI_NATIVE_METHOD_IN_CURRENT_SCOPE(windowFocusChanged)
112 Q_DECLARE_JNI_NATIVE_METHOD_IN_CURRENT_SCOPE(safeAreaMarginsChanged)
113
115};
116
117QT_END_NAMESPACE
118#endif // ANDROIDPLATFORMWINDOW_H
#define GET_AND_CHECK_STATIC_METHOD(VAR, CLASS, METHOD_NAME, METHOD_SIGNATURE)
static bool initJavaReferences(QJniEnvironment &env)
static const char m_qtTag[]
static sem_t m_exitSemaphore
#define GET_AND_CHECK_STATIC_FIELD(VAR, CLASS, FIELD_NAME, FIELD_SIGNATURE)
static jclass m_qtActivityClass
static AndroidAssetsFileEngineHandler * m_androidAssetsFileEngineHandler
static jclass m_bitmapClass
static void terminateQtNativeApplication(JNIEnv *env, jclass)
static jclass m_bitmapDrawableClass
static Main m_main
static void handleLayoutSizeChanged(JNIEnv *, jclass, jint availableWidth, jint availableHeight)
static jobject m_resourcesObj
static jmethodID m_bitmapDrawableConstructorMethodID
static void handleScreenChanged(JNIEnv *, jclass, jint displayId)
static QAndroidPlatformIntegration * m_androidPlatformIntegration
static AndroidContentFileEngineHandler * m_androidContentFileEngineHandler
static bool registerNatives(QJniEnvironment &env)
static JNINativeMethod methods[]
static AndroidBackendRegister * m_backendRegister
static void onNewIntent(JNIEnv *env, jclass, jobject data)
static void initializeBackends()
#define FIND_AND_CHECK_CLASS(CLASS_NAME)
#define GET_AND_CHECK_METHOD(VAR, CLASS, METHOD_NAME, METHOD_SIGNATURE)
static double m_density
static jobject m_assets
static void handleUiDarkModeChanged(JNIEnv *, jobject, jint newUiMode)
static int m_pendingApplicationState
static void handleRefreshRateChanged(JNIEnv *, jclass, jfloat refreshRate)
static QBasicMutex m_platformMutex
static void updateApplicationState(JNIEnv *, jobject, jint state)
static bool initCleanupHandshakeSemaphores()
static void clearJavaReferences(JNIEnv *env)
int(* Main)(int, char **)
static void handleOrientationChanged(JNIEnv *, jobject, jint newRotation, jint nativeOrientation)
static void startQtNativeApplication(JNIEnv *jenv, jobject object, jstring paramsString)
static const char m_methodErrorMsg[]
static void handleScreenRemoved(JNIEnv *, jclass, jint displayId)
static void updateLocale(JNIEnv *, jobject)
static jobject m_RGB_565_BitmapConfigValue
static const char m_classErrorMsg[]
static jobject m_ARGB_8888_BitmapConfigValue
static sem_t m_stopQtSemaphore
static jclass m_qtServiceClass
static AAssetManager * m_assetManager
static jmethodID m_createBitmapMethodID
static jobject onBind(JNIEnv *, jclass, jobject intent)
static void onActivityResult(JNIEnv *, jclass, jint requestCode, jint resultCode, jobject data)
static void handleScreenDensityChanged(JNIEnv *, jclass, jdouble density)
static QAndroidApkFileEngineHandler * m_androidApkFileEngineHandler
static void handleScreenAdded(JNIEnv *, jclass, jint displayId)
std::unique_ptr< QAbstractFileEngine > create(const QString &fileName) const override
If this file handler can handle fileName, this method creates a file engine and returns it wrapped in...
std::unique_ptr< QAbstractFileEngine > create(const QString &fileName) const override
If this file handler can handle fileName, this method creates a file engine and returns it wrapped in...
QString currentFileName() const override
This pure virtual function returns the name of the current directory entry, excluding the path.
QString currentFilePath() const override
Returns the path to the current directory entry.
bool advance() override
This pure virtual function advances the iterator to the next directory entry; if the operation was su...
QAndroidApkFileEngineIterator(const QString &path, QDirListing::IteratorFlags filters, const QStringList &filterNames)
static QAndroidEventDispatcherStopper * instance()
void removeEventDispatcher(QAndroidEventDispatcher *dispatcher)
void addEventDispatcher(QAndroidEventDispatcher *dispatcher)
QWindow * topLevelAt(const QPoint &p) const override
Return the given top level window for a given position.
void propagateSizeHints() override
Reimplement to propagate the size hints of the QWindow.
virtual void applicationStateChanged(Qt::ApplicationState)
QAndroidPlatformWindow(QWindow *window)
void setSafeAreaMargins(const QMargins safeMargins)
void setWindowFlags(Qt::WindowFlags flags) override
Requests setting the window flags of this surface to flags.
void setWindowState(Qt::WindowStates state) override
Requests setting the window state of this surface to type.
QtJniTypes::QtWindow nativeWindow() const
void onSurfaceChanged(QtJniTypes::Surface surface)
bool isExposed() const override
Returns if this window is exposed in the windowing system.
SurfaceContainer m_surfaceContainerType
QAndroidPlatformScreen * platformScreen() const
Qt::WindowFlags windowFlags() const
void requestActivateWindow() override
Reimplement to let Qt be able to request activation/focus for a window.
bool setKeyboardGrabEnabled(bool grab) override
static bool registerNatives(QJniEnvironment &env)
QtJniTypes::QtWindow m_nativeParentQtWindow
QtJniTypes::Surface m_androidSurfaceObject
QtJniTypes::QtWindow m_nativeQtWindow
void initialize() override
Called as part of QWindow::create(), after constructing the window.
void setVisible(bool visible) override
Reimplemented in subclasses to show the surface if visible is true, and hide it if visible is false.
void setParent(const QPlatformWindow *window) override
This function is called to enable native child window in QPA.
void lower() override
Reimplement to be able to let Qt lower windows to the bottom of the desktop.
bool setMouseGrabEnabled(bool grab) override
WId winId() const override
Reimplement in subclasses to return a handle to the native window.
void raise() override
Reimplement to be able to let Qt raise windows to the top of the desktop.
void setGeometry(const QRect &rect) override
This function is called by Qt whenever a window is moved or resized using the QWindow API.
QMargins safeAreaMargins() const override
The safe area margins of a window represent the area that is safe to place content within,...
\inmodule QtCore\reentrant
Definition qpoint.h:29
bool registerNatives(QJniEnvironment &env)
void hideContextMenu(QAndroidPlatformMenu *menu)
void setActiveTopLevelWindow(QWindow *window)
void removeMenuBar(QAndroidPlatformMenuBar *menuBar)
void syncMenu(QAndroidPlatformMenu *)
void androidPlatformMenuDestroyed(QAndroidPlatformMenu *menu)
void addMenuBar(QAndroidPlatformMenuBar *menuBar)
void showContextMenu(QAndroidPlatformMenu *menu, const QRect &anchorRect)
bool registerNatives(QJniEnvironment &env)
void setMenuBar(QAndroidPlatformMenuBar *menuBar, QWindow *window)
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)
const char * classErrorMsgFmt()
void setViewVisibility(jobject view, bool visible)
void setAndroidPlatformIntegration(QAndroidPlatformIntegration *androidPlatformIntegration)
const char * qtTagText()
jobject assets()
QBasicMutex * platformInterfaceMutex()
jobject createBitmap(int width, int height, QImage::Format format, JNIEnv *env)
jobject createBitmapDrawable(jobject bitmap, JNIEnv *env=nullptr)
QWindow * topLevelWindowAt(const QPoint &globalPos)
QAndroidPlatformIntegration * androidPlatformIntegration()
jobject createBitmap(QImage img, JNIEnv *env=nullptr)
AndroidBackendRegister * backendRegister()
QString deviceName()
bool blockEventLoopsWhenSuspended()
double pixelDensity()
QWindow * windowFromId(int windowId)
jclass applicationClass()
void notifyNativePluginIntegrationReady(bool ready)
AAssetManager * assetManager()
bool isQtApplication()
const char * methodErrorMsgFmt()
Q_DECLARE_JNI_CLASS(MotionEvent, "android/view/MotionEvent")