Parse XDG_SESSION_TYPE and use that to determine default platform

Makes Qt application try to launch using wayland in a wayland session,
even if it was a default desktop build.

Change-Id: Ib7d4a79fbe777527d1862bd775627afae10b1e9e
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
Allan Sandfeld Jensen 2018-03-22 16:54:41 +01:00
parent ab7d48625a
commit 4b4870a12c
1 changed files with 15 additions and 0 deletions

View File

@ -1291,6 +1291,21 @@ void QGuiApplicationPrivate::createPlatformIntegration()
#ifdef QT_QPA_DEFAULT_PLATFORM_NAME
platformName = QT_QPA_DEFAULT_PLATFORM_NAME;
#endif
#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
QByteArray sessionType = qgetenv("XDG_SESSION_TYPE");
if (!sessionType.isEmpty()) {
if (sessionType == QByteArrayLiteral("x11") && !platformName.contains(QByteArrayLiteral("xcb")))
platformName = QByteArrayLiteral("xcb");
else if (sessionType == QByteArrayLiteral("wayland") && !platformName.contains(QByteArrayLiteral("wayland")))
platformName = QByteArrayLiteral("wayland");
}
#ifdef QT_QPA_DEFAULT_PLATFORM_NAME
// Add it as fallback in case XDG_SESSION_TYPE is something wrong
if (!platformName.contains(QT_QPA_DEFAULT_PLATFORM_NAME))
platformName += QByteArrayLiteral(";" QT_QPA_DEFAULT_PLATFORM_NAME);
#endif
#endif
QByteArray platformNameEnv = qgetenv("QT_QPA_PLATFORM");
if (!platformNameEnv.isEmpty()) {
platformName = platformNameEnv;