summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2020-01-06 12:33:55 +0100
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2020-01-07 07:10:44 +0100
commit42ecdfe6f3bcbf3e35ca88b24af07249e3936fc7 (patch)
tree3dddb3f2b877e313c65cd13f255be33ff8771376 /src/plugins/platforms
parent68c30e372b01561e8809fcfa5426ae896da70b8e (diff)
Revert "Android: Implement MaximizeUsingFullscreenGeometryHint"
This reverts commit c17a5cec1901dd23f4c39ec2ae47a060fbb06895. The patch introduced a call to View.getRootViewInsets() which was introduced in API level 23. We don't want to change the minimum level for Qt 5.x series now, so we will revert the change in 5.15 and reintroduce it in Qt 6, simultaneously setting the minimum API level to 23. Task-number: QTBUG-74202 Change-Id: Ia25bb2cd62287aa80a43bbd294fb757f3f79ff5e Reviewed-by: BogDan Vatra <bogdan@kdab.com>
Diffstat (limited to 'src/plugins/platforms')
-rw-r--r--src/plugins/platforms/android/androidjniinput.cpp4
-rw-r--r--src/plugins/platforms/android/androidjnimain.cpp69
-rw-r--r--src/plugins/platforms/android/androidjnimain.h13
-rw-r--r--src/plugins/platforms/android/qandroidplatformintegration.cpp54
-rw-r--r--src/plugins/platforms/android/qandroidplatformintegration.h28
-rw-r--r--src/plugins/platforms/android/qandroidplatformscreen.cpp11
-rw-r--r--src/plugins/platforms/android/qandroidplatformwindow.cpp32
-rw-r--r--src/plugins/platforms/android/qandroidplatformwindow.h4
8 files changed, 107 insertions, 108 deletions
diff --git a/src/plugins/platforms/android/androidjniinput.cpp b/src/plugins/platforms/android/androidjniinput.cpp
index 049f9b0b13..56885f2e23 100644
--- a/src/plugins/platforms/android/androidjniinput.cpp
+++ b/src/plugins/platforms/android/androidjniinput.cpp
@@ -247,8 +247,8 @@ namespace QtAndroidInput
break;
}
- const int dw = availableWidthPixels();
- const int dh = availableHeightPixels();
+ const int dw = desktopWidthPixels();
+ const int dh = desktopHeightPixels();
QWindowSystemInterface::TouchPoint touchPoint;
touchPoint.id = id;
touchPoint.pressure = pressure;
diff --git a/src/plugins/platforms/android/androidjnimain.cpp b/src/plugins/platforms/android/androidjnimain.cpp
index bdbd3517bd..fd2644717e 100644
--- a/src/plugins/platforms/android/androidjnimain.cpp
+++ b/src/plugins/platforms/android/androidjnimain.cpp
@@ -111,8 +111,8 @@ static int m_surfaceId = 1;
static QAndroidPlatformIntegration *m_androidPlatformIntegration = nullptr;
-static int m_availableWidthPixels = 0;
-static int m_availableHeightPixels = 0;
+static int m_desktopWidthPixels = 0;
+static int m_desktopHeightPixels = 0;
static double m_scaledDensity = 0;
static double m_density = 1.0;
@@ -155,14 +155,14 @@ namespace QtAndroid
: 0;
}
- int availableWidthPixels()
+ int desktopWidthPixels()
{
- return m_availableWidthPixels;
+ return m_desktopWidthPixels;
}
- int availableHeightPixels()
+ int desktopHeightPixels()
{
- return m_availableHeightPixels;
+ return m_desktopHeightPixels;
}
double scaledDensity()
@@ -200,9 +200,22 @@ namespace QtAndroid
return m_serviceObject;
}
- void setSystemUiVisibility(SystemUiVisibility uiVisibility)
+ void showStatusBar()
{
- QJNIObjectPrivate::callStaticMethod<void>(m_applicationClass, "setSystemUiVisibility", "(I)V", jint(uiVisibility));
+ if (m_statusBarShowing)
+ return;
+
+ QJNIObjectPrivate::callStaticMethod<void>(m_applicationClass, "setFullScreen", "(Z)V", false);
+ m_statusBarShowing = true;
+ }
+
+ void hideStatusBar()
+ {
+ if (!m_statusBarShowing)
+ return;
+
+ QJNIObjectPrivate::callStaticMethod<void>(m_applicationClass, "setFullScreen", "(Z)V", true);
+ m_statusBarShowing = false;
}
jobject createBitmap(QImage img, JNIEnv *env)
@@ -607,33 +620,35 @@ static void setSurface(JNIEnv *env, jobject /*thiz*/, jint id, jobject jSurface,
}
static void setDisplayMetrics(JNIEnv */*env*/, jclass /*clazz*/,
- jint screenWidthPixels, jint screenHeightPixels,
- jint availableLeftPixels, jint availableTopPixels,
- jint availableWidthPixels, jint availableHeightPixels,
+ jint widthPixels, jint heightPixels,
+ jint desktopWidthPixels, jint desktopHeightPixels,
jdouble xdpi, jdouble ydpi,
jdouble scaledDensity, jdouble density)
{
- m_availableWidthPixels = availableWidthPixels;
- m_availableHeightPixels = availableHeightPixels;
+ // Android does not give us the correct screen size for immersive mode, but
+ // the surface does have the right size
+
+ widthPixels = qMax(widthPixels, desktopWidthPixels);
+ heightPixels = qMax(heightPixels, desktopHeightPixels);
+
+ m_desktopWidthPixels = desktopWidthPixels;
+ m_desktopHeightPixels = desktopHeightPixels;
m_scaledDensity = scaledDensity;
m_density = density;
QMutexLocker lock(&m_platformMutex);
if (!m_androidPlatformIntegration) {
- QAndroidPlatformIntegration::setDefaultDisplayMetrics(availableLeftPixels,
- availableTopPixels,
- availableWidthPixels,
- availableHeightPixels,
- qRound(double(screenWidthPixels) / xdpi * 25.4),
- qRound(double(screenHeightPixels) / ydpi * 25.4),
- screenWidthPixels,
- screenHeightPixels);
+ QAndroidPlatformIntegration::setDefaultDisplayMetrics(desktopWidthPixels,
+ desktopHeightPixels,
+ qRound(double(widthPixels) / xdpi * 25.4),
+ qRound(double(heightPixels) / ydpi * 25.4),
+ widthPixels,
+ heightPixels);
} else {
- m_androidPlatformIntegration->setPhysicalSize(qRound(double(screenWidthPixels) / xdpi * 25.4),
- qRound(double(screenHeightPixels) / ydpi * 25.4));
- m_androidPlatformIntegration->setScreenSize(screenWidthPixels, screenHeightPixels);
- m_androidPlatformIntegration->setAvailableGeometry(QRect(availableLeftPixels, availableTopPixels,
- availableWidthPixels, availableHeightPixels));
+ m_androidPlatformIntegration->setDisplayMetrics(qRound(double(widthPixels) / xdpi * 25.4),
+ qRound(double(heightPixels) / ydpi * 25.4));
+ m_androidPlatformIntegration->setScreenSize(widthPixels, heightPixels);
+ m_androidPlatformIntegration->setDesktopSize(desktopWidthPixels, desktopHeightPixels);
}
}
@@ -759,7 +774,7 @@ static JNINativeMethod methods[] = {
{"quitQtCoreApplication", "()V", (void *)quitQtCoreApplication},
{"terminateQt", "()V", (void *)terminateQt},
{"waitForServiceSetup", "()V", (void *)waitForServiceSetup},
- {"setDisplayMetrics", "(IIIIIIDDDD)V", (void *)setDisplayMetrics},
+ {"setDisplayMetrics", "(IIIIDDDD)V", (void *)setDisplayMetrics},
{"setSurface", "(ILjava/lang/Object;II)V", (void *)setSurface},
{"updateWindow", "()V", (void *)updateWindow},
{"updateApplicationState", "(I)V", (void *)updateApplicationState},
diff --git a/src/plugins/platforms/android/androidjnimain.h b/src/plugins/platforms/android/androidjnimain.h
index 63be5910f9..17ae30a1be 100644
--- a/src/plugins/platforms/android/androidjnimain.h
+++ b/src/plugins/platforms/android/androidjnimain.h
@@ -77,8 +77,8 @@ namespace QtAndroid
void bringChildToBack(int surfaceId);
QWindow *topLevelWindowAt(const QPoint &globalPos);
- int availableWidthPixels();
- int availableHeightPixels();
+ int desktopWidthPixels();
+ int desktopHeightPixels();
double scaledDensity();
double pixelDensity();
JavaVM *javaVM();
@@ -88,13 +88,8 @@ namespace QtAndroid
jobject activity();
jobject service();
- // Keep synchronized with flags in ActivityDelegate.java
- enum SystemUiVisibility {
- SYSTEM_UI_VISIBILITY_NORMAL = 0,
- SYSTEM_UI_VISIBILITY_FULLSCREEN = 1,
- SYSTEM_UI_VISIBILITY_TRANSLUCENT = 2
- };
- void setSystemUiVisibility(SystemUiVisibility uiVisibility);
+ void showStatusBar();
+ void hideStatusBar();
jobject createBitmap(QImage img, JNIEnv *env = 0);
jobject createBitmap(int width, int height, QImage::Format format, JNIEnv *env);
diff --git a/src/plugins/platforms/android/qandroidplatformintegration.cpp b/src/plugins/platforms/android/qandroidplatformintegration.cpp
index 48f330680b..e0c437be27 100644
--- a/src/plugins/platforms/android/qandroidplatformintegration.cpp
+++ b/src/plugins/platforms/android/qandroidplatformintegration.cpp
@@ -76,9 +76,12 @@
QT_BEGIN_NAMESPACE
-QSize QAndroidPlatformIntegration::m_defaultScreenSize = QSize(320, 455);
-QRect QAndroidPlatformIntegration::m_defaultAvailableGeometry = QRect(0, 0, 320, 455);
-QSize QAndroidPlatformIntegration::m_defaultPhysicalSize = QSize(50, 71);
+int QAndroidPlatformIntegration::m_defaultGeometryWidth = 320;
+int QAndroidPlatformIntegration::m_defaultGeometryHeight = 455;
+int QAndroidPlatformIntegration::m_defaultScreenWidth = 320;
+int QAndroidPlatformIntegration::m_defaultScreenHeight = 455;
+int QAndroidPlatformIntegration::m_defaultPhysicalSizeWidth = 50;
+int QAndroidPlatformIntegration::m_defaultPhysicalSizeHeight = 71;
Qt::ScreenOrientation QAndroidPlatformIntegration::m_orientation = Qt::PrimaryOrientation;
Qt::ScreenOrientation QAndroidPlatformIntegration::m_nativeOrientation = Qt::PrimaryOrientation;
@@ -171,9 +174,9 @@ QAndroidPlatformIntegration::QAndroidPlatformIntegration(const QStringList &para
m_primaryScreen = new QAndroidPlatformScreen();
QWindowSystemInterface::handleScreenAdded(m_primaryScreen);
- m_primaryScreen->setPhysicalSize(m_defaultPhysicalSize);
- m_primaryScreen->setSize(m_defaultScreenSize);
- m_primaryScreen->setAvailableGeometry(m_defaultAvailableGeometry);
+ m_primaryScreen->setPhysicalSize(QSize(m_defaultPhysicalSizeWidth, m_defaultPhysicalSizeHeight));
+ m_primaryScreen->setSize(QSize(m_defaultScreenWidth, m_defaultScreenHeight));
+ m_primaryScreen->setAvailableGeometry(QRect(0, 0, m_defaultGeometryWidth, m_defaultGeometryHeight));
m_mainThread = QThread::currentThread();
@@ -263,7 +266,6 @@ bool QAndroidPlatformIntegration::hasCapability(Capability cap) const
case ThreadedOpenGL: return !needsBasicRenderloopWorkaround() && QtAndroid::activity();
case RasterGLSurface: return QtAndroid::activity();
case TopStackedNativeChildWindows: return false;
- case MaximizeUsingFullscreenGeometry: return true;
default:
return QPlatformIntegration::hasCapability(cap);
}
@@ -413,19 +415,20 @@ QPlatformTheme *QAndroidPlatformIntegration::createPlatformTheme(const QString &
return 0;
}
-void QAndroidPlatformIntegration::setDefaultDisplayMetrics(int availableLeft,
- int availableTop,
- int availableWidth,
- int availableHeight,
- int physicalWidth,
- int physicalHeight,
- int screenWidth,
- int screenHeight)
+void QAndroidPlatformIntegration::setDefaultDisplayMetrics(int gw, int gh, int sw, int sh, int screenWidth, int screenHeight)
{
- m_defaultAvailableGeometry = QRect(availableLeft, availableTop,
- availableWidth, availableHeight);
- m_defaultPhysicalSize = QSize(physicalWidth, physicalHeight);
- m_defaultScreenSize = QSize(screenWidth, screenHeight);
+ m_defaultGeometryWidth = gw;
+ m_defaultGeometryHeight = gh;
+ m_defaultPhysicalSizeWidth = sw;
+ m_defaultPhysicalSizeHeight = sh;
+ m_defaultScreenWidth = screenWidth;
+ m_defaultScreenHeight = screenHeight;
+}
+
+void QAndroidPlatformIntegration::setDefaultDesktopSize(int gw, int gh)
+{
+ m_defaultGeometryWidth = gw;
+ m_defaultGeometryHeight = gh;
}
void QAndroidPlatformIntegration::setScreenOrientation(Qt::ScreenOrientation currentOrientation,
@@ -437,9 +440,10 @@ void QAndroidPlatformIntegration::setScreenOrientation(Qt::ScreenOrientation cur
void QAndroidPlatformIntegration::flushPendingUpdates()
{
- m_primaryScreen->setPhysicalSize(m_defaultPhysicalSize);
- m_primaryScreen->setSize(m_defaultScreenSize);
- m_primaryScreen->setAvailableGeometry(m_defaultAvailableGeometry);
+ m_primaryScreen->setPhysicalSize(QSize(m_defaultPhysicalSizeWidth,
+ m_defaultPhysicalSizeHeight));
+ m_primaryScreen->setSize(QSize(m_defaultScreenWidth, m_defaultScreenHeight));
+ m_primaryScreen->setAvailableGeometry(QRect(0, 0, m_defaultGeometryWidth, m_defaultGeometryHeight));
}
#ifndef QT_NO_ACCESSIBILITY
@@ -449,13 +453,13 @@ QPlatformAccessibility *QAndroidPlatformIntegration::accessibility() const
}
#endif
-void QAndroidPlatformIntegration::setAvailableGeometry(const QRect &availableGeometry)
+void QAndroidPlatformIntegration::setDesktopSize(int width, int height)
{
if (m_primaryScreen)
- QMetaObject::invokeMethod(m_primaryScreen, "setAvailableGeometry", Qt::AutoConnection, Q_ARG(QRect, availableGeometry));
+ QMetaObject::invokeMethod(m_primaryScreen, "setAvailableGeometry", Qt::AutoConnection, Q_ARG(QRect, QRect(0,0,width, height)));
}
-void QAndroidPlatformIntegration::setPhysicalSize(int width, int height)
+void QAndroidPlatformIntegration::setDisplayMetrics(int width, int height)
{
if (m_primaryScreen)
QMetaObject::invokeMethod(m_primaryScreen, "setPhysicalSize", Qt::AutoConnection, Q_ARG(QSize, QSize(width, height)));
diff --git a/src/plugins/platforms/android/qandroidplatformintegration.h b/src/plugins/platforms/android/qandroidplatformintegration.h
index d607ec0064..c795c499bc 100644
--- a/src/plugins/platforms/android/qandroidplatformintegration.h
+++ b/src/plugins/platforms/android/qandroidplatformintegration.h
@@ -91,8 +91,8 @@ public:
QAndroidPlatformScreen *screen() { return m_primaryScreen; }
QPlatformOffscreenSurface *createPlatformOffscreenSurface(QOffscreenSurface *surface) const override;
- void setAvailableGeometry(const QRect &availableGeometry);
- void setPhysicalSize(int width, int height);
+ virtual void setDesktopSize(int width, int height);
+ virtual void setDisplayMetrics(int width, int height);
void setScreenSize(int width, int height);
bool isVirtualDesktop() { return true; }
@@ -116,17 +116,16 @@ public:
QStringList themeNames() const override;
QPlatformTheme *createPlatformTheme(const QString &name) const override;
- static void setDefaultDisplayMetrics(int availableLeft,
- int availableTop,
- int availableWidth,
- int availableHeight,
- int physicalWidth,
- int physicalHeight,
- int screenWidth,
- int screenHeight);
+ static void setDefaultDisplayMetrics(int gw, int gh, int sw, int sh, int width, int height);
+ static void setDefaultDesktopSize(int gw, int gh);
static void setScreenOrientation(Qt::ScreenOrientation currentOrientation,
Qt::ScreenOrientation nativeOrientation);
+ static QSize defaultDesktopSize()
+ {
+ return QSize(m_defaultGeometryWidth, m_defaultGeometryHeight);
+ }
+
QTouchDevice *touchDevice() const { return m_touchDevice; }
void setTouchDevice(QTouchDevice *touchDevice) { m_touchDevice = touchDevice; }
@@ -144,9 +143,12 @@ private:
QThread *m_mainThread;
- static QRect m_defaultAvailableGeometry;
- static QSize m_defaultPhysicalSize;
- static QSize m_defaultScreenSize;
+ static int m_defaultGeometryWidth;
+ static int m_defaultGeometryHeight;
+ static int m_defaultPhysicalSizeWidth;
+ static int m_defaultPhysicalSizeHeight;
+ static int m_defaultScreenWidth;
+ static int m_defaultScreenHeight;
static Qt::ScreenOrientation m_orientation;
static Qt::ScreenOrientation m_nativeOrientation;
diff --git a/src/plugins/platforms/android/qandroidplatformscreen.cpp b/src/plugins/platforms/android/qandroidplatformscreen.cpp
index 5f8486a7a2..80757c2135 100644
--- a/src/plugins/platforms/android/qandroidplatformscreen.cpp
+++ b/src/plugins/platforms/android/qandroidplatformscreen.cpp
@@ -90,8 +90,8 @@ private:
QAndroidPlatformScreen::QAndroidPlatformScreen()
: QObject(), QPlatformScreen()
{
- m_availableGeometry = QAndroidPlatformIntegration::m_defaultAvailableGeometry;
- m_size = QAndroidPlatformIntegration::m_defaultScreenSize;
+ m_availableGeometry = QRect(0, 0, QAndroidPlatformIntegration::m_defaultGeometryWidth, QAndroidPlatformIntegration::m_defaultGeometryHeight);
+ m_size = QSize(QAndroidPlatformIntegration::m_defaultScreenWidth, QAndroidPlatformIntegration::m_defaultScreenHeight);
// Raster only apps should set QT_ANDROID_RASTER_IMAGE_DEPTH to 16
// is way much faster than 32
if (qEnvironmentVariableIntValue("QT_ANDROID_RASTER_IMAGE_DEPTH") == 16) {
@@ -101,7 +101,8 @@ QAndroidPlatformScreen::QAndroidPlatformScreen()
m_format = QImage::Format_ARGB32_Premultiplied;
m_depth = 32;
}
- m_physicalSize = QAndroidPlatformIntegration::m_defaultPhysicalSize;
+ m_physicalSize.setHeight(QAndroidPlatformIntegration::m_defaultPhysicalSizeHeight);
+ m_physicalSize.setWidth(QAndroidPlatformIntegration::m_defaultPhysicalSizeWidth);
connect(qGuiApp, &QGuiApplication::applicationStateChanged, this, &QAndroidPlatformScreen::applicationStateChanged);
}
@@ -293,7 +294,7 @@ void QAndroidPlatformScreen::topWindowChanged(QWindow *w)
if (w != 0) {
QAndroidPlatformWindow *platformWindow = static_cast<QAndroidPlatformWindow *>(w->handle());
if (platformWindow != 0)
- platformWindow->updateSystemUiVisibility();
+ platformWindow->updateStatusBarVisibility();
}
}
@@ -333,7 +334,7 @@ void QAndroidPlatformScreen::doRedraw()
}
QMutexLocker lock(&m_surfaceMutex);
if (m_id == -1 && m_rasterSurfaces) {
- m_id = QtAndroid::createSurface(this, geometry(), true, m_depth);
+ m_id = QtAndroid::createSurface(this, m_availableGeometry, true, m_depth);
AndroidDeadlockProtector protector;
if (!protector.acquire())
return;
diff --git a/src/plugins/platforms/android/qandroidplatformwindow.cpp b/src/plugins/platforms/android/qandroidplatformwindow.cpp
index a88cb9b823..4f691ce112 100644
--- a/src/plugins/platforms/android/qandroidplatformwindow.cpp
+++ b/src/plugins/platforms/android/qandroidplatformwindow.cpp
@@ -67,39 +67,25 @@ void QAndroidPlatformWindow::lower()
void QAndroidPlatformWindow::raise()
{
- updateSystemUiVisibility();
+ updateStatusBarVisibility();
platformScreen()->raise(this);
}
-QMargins QAndroidPlatformWindow::safeAreaMargins() const
-{
- if ((m_windowState & Qt::WindowMaximized) && (window()->flags() & Qt::MaximizeUsingFullscreenGeometryHint)) {
- QRect availableGeometry = platformScreen()->availableGeometry();
- return QMargins(availableGeometry.left(), availableGeometry.top(),
- availableGeometry.right(), availableGeometry.bottom());
- } else {
- return QPlatformWindow::safeAreaMargins();
- }
-}
-
void QAndroidPlatformWindow::setGeometry(const QRect &rect)
{
- QPlatformWindow::setGeometry(rect);
QWindowSystemInterface::handleGeometryChange(window(), rect);
}
void QAndroidPlatformWindow::setVisible(bool visible)
{
if (visible)
- updateSystemUiVisibility();
+ updateStatusBarVisibility();
if (visible) {
- if ((m_windowState & Qt::WindowFullScreen)
- || ((m_windowState & Qt::WindowMaximized) && (window()->flags() & Qt::MaximizeUsingFullscreenGeometryHint))) {
+ if (m_windowState & Qt::WindowFullScreen)
setGeometry(platformScreen()->geometry());
- } else if (m_windowState & Qt::WindowMaximized) {
+ else if (m_windowState & Qt::WindowMaximized)
setGeometry(platformScreen()->availableGeometry());
- }
}
if (visible)
@@ -121,7 +107,7 @@ void QAndroidPlatformWindow::setWindowState(Qt::WindowStates state)
m_windowState = state;
if (window()->isVisible())
- updateSystemUiVisibility();
+ updateStatusBarVisibility();
}
void QAndroidPlatformWindow::setWindowFlags(Qt::WindowFlags flags)
@@ -157,17 +143,15 @@ void QAndroidPlatformWindow::requestActivateWindow()
platformScreen()->topWindowChanged(window());
}
-void QAndroidPlatformWindow::updateSystemUiVisibility()
+void QAndroidPlatformWindow::updateStatusBarVisibility()
{
Qt::WindowFlags flags = window()->flags();
bool isNonRegularWindow = flags & (Qt::Popup | Qt::Dialog | Qt::Sheet) & ~Qt::Window;
if (!isNonRegularWindow) {
if (m_windowState & Qt::WindowFullScreen)
- QtAndroid::setSystemUiVisibility(QtAndroid::SYSTEM_UI_VISIBILITY_FULLSCREEN);
- else if (flags & Qt::MaximizeUsingFullscreenGeometryHint)
- QtAndroid::setSystemUiVisibility(QtAndroid::SYSTEM_UI_VISIBILITY_TRANSLUCENT);
+ QtAndroid::hideStatusBar();
else
- QtAndroid::setSystemUiVisibility(QtAndroid::SYSTEM_UI_VISIBILITY_NORMAL);
+ QtAndroid::showStatusBar();
}
}
diff --git a/src/plugins/platforms/android/qandroidplatformwindow.h b/src/plugins/platforms/android/qandroidplatformwindow.h
index f83ad7bea3..d8eb6b7b7f 100644
--- a/src/plugins/platforms/android/qandroidplatformwindow.h
+++ b/src/plugins/platforms/android/qandroidplatformwindow.h
@@ -70,11 +70,9 @@ public:
QAndroidPlatformScreen *platformScreen() const;
- QMargins safeAreaMargins() const override;
-
void propagateSizeHints() override;
void requestActivateWindow() override;
- void updateSystemUiVisibility();
+ void updateStatusBarVisibility();
inline bool isRaster() const {
if (isForeignWindow())
return false;