From f41395abc3872adab0df3d5a1d308452f3440016 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Mon, 2 Apr 2018 14:37:19 +0300 Subject: [PATCH] use new plasma way of detecting platform --- app/main.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/app/main.cpp b/app/main.cpp index 6cad4130a..42efe927f 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -53,6 +53,7 @@ #define CRED "\e[0;31m" inline void configureAboutData(); +inline void detectPlatform(int argc, char **argv); int main(int argc, char **argv) { @@ -72,7 +73,16 @@ int main(int argc, char **argv) } QQuickWindow::setDefaultAlphaBuffer(true); + + const bool qpaVariable = qEnvironmentVariableIsSet("QT_QPA_PLATFORM"); + detectPlatform(argc, argv); QApplication app(argc, argv); + + if (!qpaVariable) { + // don't leak the env variable to processes we start + qunsetenv("QT_QPA_PLATFORM"); + } + KQuickAddons::QtQuickSettings::init(); KLocalizedString::setApplicationDomain("latte-dock"); @@ -281,3 +291,32 @@ inline void configureAboutData() KAboutData::setApplicationData(about); } + +//! used the version provided by PW:KWorkspace +inline void detectPlatform(int argc, char **argv) +{ + if (qEnvironmentVariableIsSet("QT_QPA_PLATFORM")) { + return; + } + + for (int i = 0; i < argc; i++) { + if (qstrcmp(argv[i], "-platform") == 0 || + qstrcmp(argv[i], "--platform") == 0 || + QByteArray(argv[i]).startsWith("-platform=") || + QByteArray(argv[i]).startsWith("--platform=")) { + return; + } + } + + const QByteArray sessionType = qgetenv("XDG_SESSION_TYPE"); + + if (sessionType.isEmpty()) { + return; + } + + if (qstrcmp(sessionType, "wayland") == 0) { + qputenv("QT_QPA_PLATFORM", "wayland"); + } else if (qstrcmp(sessionType, "x11") == 0) { + qputenv("QT_QPA_PLATFORM", "xcb"); + } +}