From 55145c52677e961804b7b3a725652bd5ce1e0269 Mon Sep 17 00:00:00 2001 From: David Faure Date: Mon, 22 Apr 2013 19:20:19 +0200 Subject: Improve desktop environment detection. UNKNOWN now means generic unix theme, rather than Gtk: there are other KDE/Qt-based desktops, and there's also the case of no desktop at all (e.g. bare Xvfb, as used by automated builds). To make this correct for GTK-based desktops, this commits improves the detection of the current desktop environment. Change-Id: Ib696624de39d5024527880df7adc26c65b838d15 Reviewed-by: J-P Nurmi Reviewed-by: Friedemann Kleint Reviewed-by: Jens Bache-Wiig Reviewed-by: Shawn Rutledge --- src/gui/kernel/qplatformservices.cpp | 5 ++++- .../services/genericunix/qgenericunixservices.cpp | 26 ++++++++++++++-------- .../themes/genericunix/qgenericunixthemes.cpp | 6 ++++- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/gui/kernel/qplatformservices.cpp b/src/gui/kernel/qplatformservices.cpp index f2cade0a35..d09b74c6fe 100644 --- a/src/gui/kernel/qplatformservices.cpp +++ b/src/gui/kernel/qplatformservices.cpp @@ -74,7 +74,10 @@ bool QPlatformServices::openDocument(const QUrl &url) /*! * \brief QPlatformServices::desktopEnvironment returns the active desktop environment. * - * On Unix this function returns KDE, GNOME or UNKNOWN. + * On Unix this function returns the uppercase desktop environment name, such as + * KDE, GNOME, UNITY, XFCE, LXDE etc. or UNKNOWN if none was detected. + * The primary way to detect the desktop environment is the environment variable + * XDG_CURRENT_DESKTOP. */ QByteArray QPlatformServices::desktopEnvironment() const { diff --git a/src/platformsupport/services/genericunix/qgenericunixservices.cpp b/src/platformsupport/services/genericunix/qgenericunixservices.cpp index fedaa3a655..77ea0f1db8 100644 --- a/src/platformsupport/services/genericunix/qgenericunixservices.cpp +++ b/src/platformsupport/services/genericunix/qgenericunixservices.cpp @@ -54,16 +54,24 @@ enum { debug = 0 }; static inline QByteArray detectDesktopEnvironment() { - if (!qEnvironmentVariableIsEmpty("KDE_FULL_SESSION")) - return QByteArray("KDE"); - // Check Unity first, whose older versions also have "GNOME_DESKTOP_SESSION_ID" set. const QByteArray xdgCurrentDesktop = qgetenv("XDG_CURRENT_DESKTOP"); - if (xdgCurrentDesktop == "Unity") - return QByteArrayLiteral("UNITY"); - // GNOME_DESKTOP_SESSION_ID is deprecated for some reason, but still check it - if (qgetenv("DESKTOP_SESSION") == "gnome" || !qEnvironmentVariableIsEmpty("GNOME_DESKTOP_SESSION_ID")) - return QByteArray("GNOME"); - return QByteArray("UNKNOWN"); + if (!xdgCurrentDesktop.isEmpty()) + return xdgCurrentDesktop.toUpper(); // KDE, GNOME, UNITY, LXDE, MATE, XFCE... + + // Classic fallbacks + if (!qEnvironmentVariableIsEmpty("KDE_FULL_SESSION")) + return QByteArrayLiteral("KDE"); + if (!qEnvironmentVariableIsEmpty("GNOME_DESKTOP_SESSION_ID")) + return QByteArrayLiteral("GNOME"); + + // Fallback to checking $DESKTOP_SESSION (unreliable) + const QByteArray desktopSession = qgetenv("DESKTOP_SESSION"); + if (desktopSession == "gnome") + return QByteArrayLiteral("GNOME"); + if (desktopSession == "xfce") + return QByteArrayLiteral("XFCE"); + + return QByteArrayLiteral("UNKNOWN"); } static inline bool checkExecutable(const QString &candidate, QString *result) diff --git a/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp b/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp index 6ea68397b6..196f67bcd8 100644 --- a/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp +++ b/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp @@ -425,7 +425,11 @@ QStringList QGenericUnixTheme::themeNames() #ifndef QT_NO_SETTINGS result.push_back(QLatin1String(QKdeTheme::name)); #endif - } else { // Gnome, Unity, other Gtk-based desktops like XFCE. + } else if (desktopEnvironment == QByteArrayLiteral("GNOME") || + desktopEnvironment == QByteArrayLiteral("UNITY") || + desktopEnvironment == QByteArrayLiteral("MATE") || + desktopEnvironment == QByteArrayLiteral("XFCE") || + desktopEnvironment == QByteArrayLiteral("LXDE")) { // Gtk-based desktops // prefer the GTK2 theme implementation with native dialogs etc. result.push_back(QStringLiteral("gtk2")); // fallback to the generic Gnome theme if loading the GTK2 theme fails -- cgit v1.2.3