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"
|
|
|
|
|
2022-01-08 06:23:16 +00:00
|
|
|
#include "base/platform/base_platform_info.h"
|
|
|
|
|
2017-02-26 17:19:35 +00:00
|
|
|
namespace Platform {
|
|
|
|
namespace DesktopEnvironment {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
QString GetEnv(const char *name) {
|
2022-01-06 19:24:21 +00:00
|
|
|
const auto value = qEnvironmentVariable(name);
|
2021-03-13 11:50:34 +00:00
|
|
|
LOG(("Getting DE, %1: '%2'").arg(name, value));
|
2017-04-03 16:56:20 +00:00
|
|
|
return value;
|
2017-02-26 17:19:35 +00:00
|
|
|
}
|
|
|
|
|
2022-01-08 06:23:16 +00:00
|
|
|
QString GetWM() {
|
|
|
|
const auto value = base::Platform::GetWindowManager();
|
|
|
|
LOG(("Getting WM: '%1'").arg(value));
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2022-01-06 19:24:21 +00:00
|
|
|
std::vector<Type> Compute() {
|
|
|
|
auto result = std::vector<Type>();
|
2020-01-22 13:02:27 +00:00
|
|
|
|
2022-01-06 19:24:21 +00:00
|
|
|
const auto xdgCurrentDesktop = GetEnv(
|
|
|
|
"XDG_CURRENT_DESKTOP").toLower().split(':', Qt::SkipEmptyParts);
|
|
|
|
|
2022-01-08 06:23:16 +00:00
|
|
|
const auto xdgSessionDesktop = GetEnv("XDG_SESSION_DESKTOP").toLower();
|
|
|
|
|
2022-01-06 19:24:21 +00:00
|
|
|
const auto desktopSession = [] {
|
|
|
|
const auto result = GetEnv("DESKTOP_SESSION").toLower();
|
|
|
|
const auto slash = result.lastIndexOf('/');
|
|
|
|
// DESKTOP_SESSION can contain a path
|
|
|
|
if (slash != -1) {
|
|
|
|
return result.mid(slash + 1);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}();
|
2020-01-22 13:02:27 +00:00
|
|
|
|
2022-01-08 06:23:16 +00:00
|
|
|
const auto windowManager = GetWM().toLower();
|
|
|
|
|
|
|
|
const auto desktopToType = [&](const QString &desktop) {
|
|
|
|
if (desktop == qstr("unity")) {
|
2017-02-26 17:19:35 +00:00
|
|
|
// gnome-fallback sessions set XDG_CURRENT_DESKTOP to Unity
|
|
|
|
// DESKTOP_SESSION can be gnome-fallback or gnome-fallback-compiz
|
2022-01-08 06:23:16 +00:00
|
|
|
if (desktopSession.contains(qstr("gnome-fallback"))) {
|
2022-01-06 19:24:21 +00:00
|
|
|
result.push_back(Type::Gnome);
|
2017-02-26 17:19:35 +00:00
|
|
|
}
|
2022-01-06 19:24:21 +00:00
|
|
|
result.push_back(Type::Unity);
|
2022-01-08 06:23:16 +00:00
|
|
|
} else if (desktop == qstr("gnome")) {
|
2022-01-06 19:24:21 +00:00
|
|
|
result.push_back(Type::Gnome);
|
2022-01-08 06:23:16 +00:00
|
|
|
} else if (desktop == qstr("x-cinnamon") || desktop == qstr("cinnamon")) {
|
2022-01-06 19:24:21 +00:00
|
|
|
result.push_back(Type::Cinnamon);
|
2022-01-08 06:23:16 +00:00
|
|
|
} else if (desktop == qstr("kde")) {
|
2022-01-06 19:24:21 +00:00
|
|
|
result.push_back(Type::KDE);
|
2022-01-08 06:23:16 +00:00
|
|
|
} else if (desktop == qstr("mate")) {
|
2022-01-06 19:24:21 +00:00
|
|
|
result.push_back(Type::MATE);
|
2017-02-26 17:19:35 +00:00
|
|
|
}
|
2022-01-08 06:23:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (const auto ¤t : xdgCurrentDesktop) {
|
|
|
|
desktopToType(current);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!xdgSessionDesktop.isEmpty()) {
|
|
|
|
desktopToType(xdgSessionDesktop);
|
2017-02-26 17:19:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!desktopSession.isEmpty()) {
|
2022-01-08 06:23:16 +00:00
|
|
|
desktopToType(desktopSession);
|
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()) {
|
2022-01-06 19:24:21 +00:00
|
|
|
result.push_back(Type::Gnome);
|
|
|
|
}
|
|
|
|
if (!GetEnv("KDE_FULL_SESSION").isEmpty()) {
|
|
|
|
result.push_back(Type::KDE);
|
2017-02-26 17:19:35 +00:00
|
|
|
}
|
|
|
|
|
2022-01-08 06:23:16 +00:00
|
|
|
// Some DEs could be detected via X11
|
|
|
|
if (!windowManager.isEmpty()) {
|
|
|
|
if (windowManager == qstr("gnome shell")) {
|
|
|
|
result.push_back(Type::Gnome);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-06 19:24:21 +00:00
|
|
|
ranges::unique(result);
|
|
|
|
return result;
|
2017-02-26 17:19:35 +00:00
|
|
|
}
|
|
|
|
|
2022-01-06 19:24:21 +00:00
|
|
|
std::vector<Type> ComputeAndLog() {
|
|
|
|
const auto result = Compute();
|
|
|
|
if (result.empty()) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
const auto names = ranges::accumulate(
|
|
|
|
result | ranges::views::transform([](auto type) {
|
|
|
|
switch (type) {
|
|
|
|
case Type::Gnome: return qsl("Gnome, ");
|
|
|
|
case Type::Cinnamon: return qsl("Cinnamon, ");
|
|
|
|
case Type::KDE: return qsl("KDE, ");
|
|
|
|
case Type::Unity: return qsl("Unity, ");
|
|
|
|
case Type::MATE: return qsl("MATE, ");
|
|
|
|
}
|
|
|
|
Unexpected("Type in Platform::DesktopEnvironment::ComputeAndLog");
|
|
|
|
}),
|
|
|
|
QString()).chopped(2);
|
|
|
|
LOG(("DE: %1").arg(names));
|
2017-04-03 16:56:20 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-02-26 17:19:35 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// Thanks Chromium.
|
2022-01-06 19:24:21 +00:00
|
|
|
std::vector<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
|