summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/android
diff options
context:
space:
mode:
authorIvan Solovev <ivan.solovev@qt.io>2022-02-23 18:26:09 +0100
committerIvan Solovev <ivan.solovev@qt.io>2022-03-04 02:37:11 +0100
commit79fb80152ff29a30faa3f0cce79a602e36cadbeb (patch)
tree5ea749e479c8bc564c51e251f353d1c134a24a0d /src/plugins/platforms/android
parent285ea132861f8b8d1b5d1ea0f966c141da985953 (diff)
Android: make sure that orientationChange is reported after resize
On Android orientation changes are reported from the DisplayListener.onDisplayChanged() method, while the screen size changes are reported from QtLayout.onSizeChanged(). In practice these callbacks come in random order, so rotating the screen multiple times might result in inconsistent order of signals and events. This patch makes sure that size change events always happen before orientation changes. This is done by caching the new orientation values and reporting them only when needed. At this point we also need to use QMetaObject::invokeMethod() for orientation change, like it is done for geometry change. Otherwise the orientation update can still be processed earlier than the geometry change. Also note that at some point we might get an orientation change without a size change (for example Qt::LandscapeOrientation -> Qt::InvertedLandscapeOrientation). That is the reason for isSimilarRotation() helper function. As a drive-by: ignore size changes with inconsistent values when window size is reported to have old orientation, while the screen has already been rotated. In such cases a new size change will be triggered shortly with normal value. Task-number: QTBUG-94459 Pick-to: 6.3 6.2 5.15 Change-Id: I5c98e526d0370d380344b2297169d5e0c0ee8ea7 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
Diffstat (limited to 'src/plugins/platforms/android')
-rw-r--r--src/plugins/platforms/android/androidjnimain.cpp15
-rw-r--r--src/plugins/platforms/android/qandroidplatformscreen.cpp5
-rw-r--r--src/plugins/platforms/android/qandroidplatformscreen.h1
3 files changed, 17 insertions, 4 deletions
diff --git a/src/plugins/platforms/android/androidjnimain.cpp b/src/plugins/platforms/android/androidjnimain.cpp
index ac1b29ba5b..6cb9d8fe7e 100644
--- a/src/plugins/platforms/android/androidjnimain.cpp
+++ b/src/plugins/platforms/android/androidjnimain.cpp
@@ -1,7 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2014 BogDan Vatra <bogdan@kde.org>
-** Copyright (C) 2021 The Qt Company Ltd.
+** Copyright (C) 2022 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the plugins of the Qt Toolkit.
@@ -541,6 +541,9 @@ static void startQtApplication(JNIEnv */*env*/, jclass /*clazz*/)
vm->AttachCurrentThread(&env, &args);
}
+ // Register type for invokeMethod() calls.
+ qRegisterMetaType<Qt::ScreenOrientation>("Qt::ScreenOrientation");
+
// Register resources if they are available
if (QFile{QStringLiteral("assets:/android_rcc_bundle.rcc")}.exists())
QResource::registerResource(QStringLiteral("assets:/android_rcc_bundle.rcc"));
@@ -759,9 +762,13 @@ static void handleOrientationChanged(JNIEnv */*env*/, jobject /*thiz*/, jint new
QAndroidPlatformIntegration::setScreenOrientation(screenOrientation, native);
QMutexLocker lock(&m_platformMutex);
if (m_androidPlatformIntegration) {
- QPlatformScreen *screen = m_androidPlatformIntegration->screen();
- QWindowSystemInterface::handleScreenOrientationChange(screen->screen(),
- screenOrientation);
+ QAndroidPlatformScreen *screen = m_androidPlatformIntegration->screen();
+ // Use invokeMethod to keep the certain order of the "geometry change"
+ // and "orientation change" event handling.
+ if (screen) {
+ QMetaObject::invokeMethod(screen, "setOrientation", Qt::AutoConnection,
+ Q_ARG(Qt::ScreenOrientation, screenOrientation));
+ }
}
}
diff --git a/src/plugins/platforms/android/qandroidplatformscreen.cpp b/src/plugins/platforms/android/qandroidplatformscreen.cpp
index 75967f5678..fdb027b9de 100644
--- a/src/plugins/platforms/android/qandroidplatformscreen.cpp
+++ b/src/plugins/platforms/android/qandroidplatformscreen.cpp
@@ -309,6 +309,11 @@ void QAndroidPlatformScreen::setRefreshRate(qreal refreshRate)
QWindowSystemInterface::handleScreenRefreshRateChange(QPlatformScreen::screen(), refreshRate);
}
+void QAndroidPlatformScreen::setOrientation(Qt::ScreenOrientation orientation)
+{
+ QWindowSystemInterface::handleScreenOrientationChange(QPlatformScreen::screen(), orientation);
+}
+
void QAndroidPlatformScreen::setAvailableGeometry(const QRect &rect)
{
QMutexLocker lock(&m_surfaceMutex);
diff --git a/src/plugins/platforms/android/qandroidplatformscreen.h b/src/plugins/platforms/android/qandroidplatformscreen.h
index 4a06bb20bd..24494de2da 100644
--- a/src/plugins/platforms/android/qandroidplatformscreen.h
+++ b/src/plugins/platforms/android/qandroidplatformscreen.h
@@ -96,6 +96,7 @@ public slots:
void setSizeParameters(const QSize &physicalSize, const QSize &size,
const QRect &availableGeometry);
void setRefreshRate(qreal refreshRate);
+ void setOrientation(Qt::ScreenOrientation orientation);
protected:
bool event(QEvent *event) override;