2017-02-26 17:19:35 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-02-26 17:19:35 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-02-26 17:19:35 +00:00
|
|
|
*/
|
|
|
|
#include "platform/linux/linux_desktop_environment.h"
|
|
|
|
|
2020-01-22 13:02:27 +00:00
|
|
|
#include "platform/linux/specific_linux.h"
|
2020-11-04 15:50:17 +00:00
|
|
|
#include "base/qt_adapters.h"
|
2020-01-22 13:02:27 +00:00
|
|
|
|
2017-02-26 17:19:35 +00:00
|
|
|
namespace Platform {
|
|
|
|
namespace DesktopEnvironment {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
QString GetEnv(const char *name) {
|
|
|
|
auto result = getenv(name);
|
2017-04-03 16:56:20 +00:00
|
|
|
auto value = result ? QString::fromLatin1(result) : QString();
|
|
|
|
LOG(("Getting DE, %1: '%2'").arg(name).arg(value));
|
|
|
|
return value;
|
2017-02-26 17:19:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Type Compute() {
|
|
|
|
auto xdgCurrentDesktop = GetEnv("XDG_CURRENT_DESKTOP").toLower();
|
2020-11-04 15:50:17 +00:00
|
|
|
auto list = xdgCurrentDesktop.split(':', base::QStringSkipEmptyParts);
|
2017-02-26 17:19:35 +00:00
|
|
|
auto desktopSession = GetEnv("DESKTOP_SESSION").toLower();
|
2020-01-22 13:02:27 +00:00
|
|
|
auto slash = desktopSession.lastIndexOf('/');
|
2017-02-26 17:19:35 +00:00
|
|
|
auto kdeSession = GetEnv("KDE_SESSION_VERSION");
|
2020-01-22 13:02:27 +00:00
|
|
|
|
|
|
|
// DESKTOP_SESSION can contain a path
|
|
|
|
if (slash != -1) {
|
|
|
|
desktopSession = desktopSession.mid(slash + 1);
|
|
|
|
}
|
|
|
|
|
2017-02-26 17:19:35 +00:00
|
|
|
if (!list.isEmpty()) {
|
|
|
|
if (list.contains("unity")) {
|
|
|
|
// gnome-fallback sessions set XDG_CURRENT_DESKTOP to Unity
|
|
|
|
// DESKTOP_SESSION can be gnome-fallback or gnome-fallback-compiz
|
|
|
|
if (desktopSession.indexOf(qstr("gnome-fallback")) >= 0) {
|
|
|
|
return Type::Gnome;
|
|
|
|
}
|
|
|
|
return Type::Unity;
|
2020-05-29 19:08:45 +00:00
|
|
|
} else if (list.contains("xfce")) {
|
|
|
|
return Type::XFCE;
|
2017-02-26 17:19:35 +00:00
|
|
|
} else if (list.contains("gnome")) {
|
|
|
|
return Type::Gnome;
|
2020-05-29 19:08:45 +00:00
|
|
|
} else if (list.contains("x-cinnamon")) {
|
|
|
|
return Type::Cinnamon;
|
2017-02-26 17:19:35 +00:00
|
|
|
} else if (list.contains("kde")) {
|
|
|
|
if (kdeSession == qstr("5")) {
|
|
|
|
return Type::KDE5;
|
|
|
|
}
|
|
|
|
return Type::KDE4;
|
2020-01-31 06:34:37 +00:00
|
|
|
} else if (list.contains("mate")) {
|
|
|
|
return Type::MATE;
|
2020-05-29 19:08:45 +00:00
|
|
|
} else if (list.contains("lxde")) {
|
|
|
|
return Type::LXDE;
|
2017-02-26 17:19:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!desktopSession.isEmpty()) {
|
2020-01-22 13:02:27 +00:00
|
|
|
if (desktopSession == qstr("gnome")) {
|
2017-02-26 17:19:35 +00:00
|
|
|
return Type::Gnome;
|
2020-05-29 19:08:45 +00:00
|
|
|
} else if (desktopSession == qstr("cinnamon")) {
|
|
|
|
return Type::Cinnamon;
|
2017-02-26 17:19:35 +00:00
|
|
|
} else if (desktopSession == qstr("kde4") || desktopSession == qstr("kde-plasma")) {
|
|
|
|
return Type::KDE4;
|
|
|
|
} else if (desktopSession == qstr("kde")) {
|
|
|
|
// This may mean KDE4 on newer systems, so we have to check.
|
|
|
|
if (!kdeSession.isEmpty()) {
|
|
|
|
return Type::KDE4;
|
|
|
|
}
|
|
|
|
return Type::KDE3;
|
2020-05-29 19:08:45 +00:00
|
|
|
} else if (desktopSession == qstr("xfce")) {
|
|
|
|
return Type::XFCE;
|
2020-01-31 06:34:37 +00:00
|
|
|
} else if (desktopSession == qstr("mate")) {
|
|
|
|
return Type::MATE;
|
2020-05-29 19:08:45 +00:00
|
|
|
} else if (desktopSession == qstr("lxde")) {
|
|
|
|
return Type::LXDE;
|
2017-02-26 17:19:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fall back on some older environment variables.
|
|
|
|
// Useful particularly in the DESKTOP_SESSION=default case.
|
|
|
|
if (!GetEnv("GNOME_DESKTOP_SESSION_ID").isEmpty()) {
|
|
|
|
return Type::Gnome;
|
|
|
|
} else if (!GetEnv("KDE_FULL_SESSION").isEmpty()) {
|
|
|
|
if (!kdeSession.isEmpty()) {
|
|
|
|
return Type::KDE4;
|
|
|
|
}
|
|
|
|
return Type::KDE3;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Type::Other;
|
|
|
|
}
|
|
|
|
|
2017-04-03 16:56:20 +00:00
|
|
|
Type ComputeAndLog() {
|
|
|
|
auto result = Compute();
|
|
|
|
auto name = [result]() -> QString {
|
|
|
|
switch (result) {
|
|
|
|
case Type::Other: return "Other";
|
|
|
|
case Type::Gnome: return "Gnome";
|
2020-05-29 19:08:45 +00:00
|
|
|
case Type::Cinnamon: return "Cinnamon";
|
2017-04-03 16:56:20 +00:00
|
|
|
case Type::KDE3: return "KDE3";
|
|
|
|
case Type::KDE4: return "KDE4";
|
|
|
|
case Type::KDE5: return "KDE5";
|
|
|
|
case Type::Unity: return "Unity";
|
2020-05-29 19:08:45 +00:00
|
|
|
case Type::XFCE: return "XFCE";
|
2020-01-31 06:34:37 +00:00
|
|
|
case Type::MATE: return "MATE";
|
2020-05-29 19:08:45 +00:00
|
|
|
case Type::LXDE: return "LXDE";
|
2017-04-03 16:56:20 +00:00
|
|
|
}
|
|
|
|
return QString::number(static_cast<int>(result));
|
|
|
|
};
|
|
|
|
LOG(("DE: %1").arg(name()));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-02-26 17:19:35 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// Thanks Chromium.
|
|
|
|
Type Get() {
|
2017-04-03 16:56:20 +00:00
|
|
|
static const auto result = ComputeAndLog();
|
2017-02-26 17:19:35 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace DesktopEnvironment
|
2017-04-03 16:56:20 +00:00
|
|
|
} // namespace Platform
|