From 543dd63b00a1551f611d5f9f577b68a8de354013 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Sun, 20 Aug 2023 16:32:15 +0300 Subject: [PATCH] check if there is platform plugin for XDG_SESSION_DESKTOP from qt_guiPlatformPlugin() Signed-off-by: Ivailo Monev --- src/gui/kernel/qguiplatformplugin.cpp | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/gui/kernel/qguiplatformplugin.cpp b/src/gui/kernel/qguiplatformplugin.cpp index 3cbb03849..e724954ee 100644 --- a/src/gui/kernel/qguiplatformplugin.cpp +++ b/src/gui/kernel/qguiplatformplugin.cpp @@ -47,17 +47,24 @@ Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, platformLoader, (QString::fromLatin1(" QGuiPlatformPlugin *qt_guiPlatformPlugin() { static QGuiPlatformPlugin *plugin = nullptr; - if (!plugin) - { + if (!plugin) { #ifndef QT_NO_LIBRARY - - static QString key = qGetEnv("QT_PLATFORM_PLUGIN"); - if (key.isEmpty()) { - key = qGetEnv("DESKTOP_SESSION"); - } - - if (!key.isEmpty()) { - plugin = qobject_cast(platformLoader()->instance(key)); + static const char* platformEnvTbl[] = { + "QT_PLATFORM_PLUGIN", + "XDG_CURRENT_DESKTOP", + "DESKTOP_SESSION", + nullptr + }; + int counter = 0; + while (platformEnvTbl[counter]) { + QString key = qGetEnv(platformEnvTbl[counter]); + if (!key.isEmpty()) { + plugin = qobject_cast(platformLoader()->instance(key)); + if (plugin) { + break; + } + } + counter++; } #endif // QT_NO_LIBRARY