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 <jpnurmi@digia.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com> Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
This commit is contained in:
parent
9e035d9de2
commit
55145c5267
@ -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
|
||||
{
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user