check if there is platform plugin for XDG_SESSION_DESKTOP from qt_guiPlatformPlugin()

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2023-08-20 16:32:15 +03:00
parent 198625f679
commit 543dd63b00

View file

@ -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<QGuiPlatformPlugin *>(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<QGuiPlatformPlugin*>(platformLoader()->instance(key));
if (plugin) {
break;
}
}
counter++;
}
#endif // QT_NO_LIBRARY