mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Use more sources for DE detection
This commit is contained in:
parent
726aa3316d
commit
b3bb1a537c
1 changed files with 35 additions and 14 deletions
|
@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#include "platform/linux/linux_desktop_environment.h"
|
#include "platform/linux/linux_desktop_environment.h"
|
||||||
|
|
||||||
|
#include "base/platform/base_platform_info.h"
|
||||||
|
|
||||||
namespace Platform {
|
namespace Platform {
|
||||||
namespace DesktopEnvironment {
|
namespace DesktopEnvironment {
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -17,12 +19,20 @@ QString GetEnv(const char *name) {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString GetWM() {
|
||||||
|
const auto value = base::Platform::GetWindowManager();
|
||||||
|
LOG(("Getting WM: '%1'").arg(value));
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<Type> Compute() {
|
std::vector<Type> Compute() {
|
||||||
auto result = std::vector<Type>();
|
auto result = std::vector<Type>();
|
||||||
|
|
||||||
const auto xdgCurrentDesktop = GetEnv(
|
const auto xdgCurrentDesktop = GetEnv(
|
||||||
"XDG_CURRENT_DESKTOP").toLower().split(':', Qt::SkipEmptyParts);
|
"XDG_CURRENT_DESKTOP").toLower().split(':', Qt::SkipEmptyParts);
|
||||||
|
|
||||||
|
const auto xdgSessionDesktop = GetEnv("XDG_SESSION_DESKTOP").toLower();
|
||||||
|
|
||||||
const auto desktopSession = [] {
|
const auto desktopSession = [] {
|
||||||
const auto result = GetEnv("DESKTOP_SESSION").toLower();
|
const auto result = GetEnv("DESKTOP_SESSION").toLower();
|
||||||
const auto slash = result.lastIndexOf('/');
|
const auto slash = result.lastIndexOf('/');
|
||||||
|
@ -33,33 +43,37 @@ std::vector<Type> Compute() {
|
||||||
return result;
|
return result;
|
||||||
}();
|
}();
|
||||||
|
|
||||||
for (const auto ¤t : xdgCurrentDesktop) {
|
const auto windowManager = GetWM().toLower();
|
||||||
if (current == qstr("unity")) {
|
|
||||||
|
const auto desktopToType = [&](const QString &desktop) {
|
||||||
|
if (desktop == qstr("unity")) {
|
||||||
// gnome-fallback sessions set XDG_CURRENT_DESKTOP to Unity
|
// gnome-fallback sessions set XDG_CURRENT_DESKTOP to Unity
|
||||||
// DESKTOP_SESSION can be gnome-fallback or gnome-fallback-compiz
|
// DESKTOP_SESSION can be gnome-fallback or gnome-fallback-compiz
|
||||||
if (desktopSession.indexOf(qstr("gnome-fallback")) >= 0) {
|
if (desktopSession.contains(qstr("gnome-fallback"))) {
|
||||||
result.push_back(Type::Gnome);
|
result.push_back(Type::Gnome);
|
||||||
}
|
}
|
||||||
result.push_back(Type::Unity);
|
result.push_back(Type::Unity);
|
||||||
} else if (current == qstr("gnome")) {
|
} else if (desktop == qstr("gnome")) {
|
||||||
result.push_back(Type::Gnome);
|
result.push_back(Type::Gnome);
|
||||||
} else if (current == qstr("x-cinnamon")) {
|
} else if (desktop == qstr("x-cinnamon") || desktop == qstr("cinnamon")) {
|
||||||
result.push_back(Type::Cinnamon);
|
result.push_back(Type::Cinnamon);
|
||||||
} else if (current == qstr("kde")) {
|
} else if (desktop == qstr("kde")) {
|
||||||
result.push_back(Type::KDE);
|
result.push_back(Type::KDE);
|
||||||
} else if (current == qstr("mate")) {
|
} else if (desktop == qstr("mate")) {
|
||||||
result.push_back(Type::MATE);
|
result.push_back(Type::MATE);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const auto ¤t : xdgCurrentDesktop) {
|
||||||
|
desktopToType(current);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!xdgSessionDesktop.isEmpty()) {
|
||||||
|
desktopToType(xdgSessionDesktop);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!desktopSession.isEmpty()) {
|
if (!desktopSession.isEmpty()) {
|
||||||
if (desktopSession == qstr("gnome")) {
|
desktopToType(desktopSession);
|
||||||
result.push_back(Type::Gnome);
|
|
||||||
} else if (desktopSession == qstr("cinnamon")) {
|
|
||||||
result.push_back(Type::Cinnamon);
|
|
||||||
} else if (desktopSession == qstr("mate")) {
|
|
||||||
result.push_back(Type::MATE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fall back on some older environment variables.
|
// Fall back on some older environment variables.
|
||||||
|
@ -71,6 +85,13 @@ std::vector<Type> Compute() {
|
||||||
result.push_back(Type::KDE);
|
result.push_back(Type::KDE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Some DEs could be detected via X11
|
||||||
|
if (!windowManager.isEmpty()) {
|
||||||
|
if (windowManager == qstr("gnome shell")) {
|
||||||
|
result.push_back(Type::Gnome);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ranges::unique(result);
|
ranges::unique(result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue