mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Get rid of XDG_CURRENT_DESKTOP dependent logic
Just try all the commands and use the one that works first
This commit is contained in:
parent
8803dfcee6
commit
e7a7c2d267
4 changed files with 7 additions and 193 deletions
|
@ -1187,8 +1187,6 @@ PRIVATE
|
||||||
payments/payments_checkout_process.h
|
payments/payments_checkout_process.h
|
||||||
payments/payments_form.cpp
|
payments/payments_form.cpp
|
||||||
payments/payments_form.h
|
payments/payments_form.h
|
||||||
platform/linux/linux_desktop_environment.cpp
|
|
||||||
platform/linux/linux_desktop_environment.h
|
|
||||||
platform/linux/linux_wayland_integration_dummy.cpp
|
platform/linux/linux_wayland_integration_dummy.cpp
|
||||||
platform/linux/linux_wayland_integration.cpp
|
platform/linux/linux_wayland_integration.cpp
|
||||||
platform/linux/linux_wayland_integration.h
|
platform/linux/linux_wayland_integration.h
|
||||||
|
|
|
@ -1,130 +0,0 @@
|
||||||
/*
|
|
||||||
This file is part of Telegram Desktop,
|
|
||||||
the official desktop application for the Telegram messaging service.
|
|
||||||
|
|
||||||
For license and copyright information please follow this link:
|
|
||||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
||||||
*/
|
|
||||||
#include "platform/linux/linux_desktop_environment.h"
|
|
||||||
|
|
||||||
#include "base/platform/base_platform_info.h"
|
|
||||||
|
|
||||||
namespace Platform {
|
|
||||||
namespace DesktopEnvironment {
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
QString GetEnv(const char *name) {
|
|
||||||
const auto value = qEnvironmentVariable(name);
|
|
||||||
LOG(("Getting DE, %1: '%2'").arg(name, value));
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString GetWM() {
|
|
||||||
const auto result = Platform::GetWindowManager();
|
|
||||||
LOG(("Getting DE via WM: '%1'").arg(result));
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<Type> Compute() {
|
|
||||||
auto result = std::vector<Type>();
|
|
||||||
|
|
||||||
const auto xdgCurrentDesktop = GetEnv(
|
|
||||||
"XDG_CURRENT_DESKTOP").toLower().split(':', Qt::SkipEmptyParts);
|
|
||||||
|
|
||||||
const auto xdgSessionDesktop = GetEnv("XDG_SESSION_DESKTOP").toLower();
|
|
||||||
|
|
||||||
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;
|
|
||||||
}();
|
|
||||||
|
|
||||||
const auto windowManager = GetWM().toLower();
|
|
||||||
|
|
||||||
const auto desktopToType = [&](const QString &desktop) {
|
|
||||||
if (desktop == qstr("unity")) {
|
|
||||||
// gnome-fallback sessions set XDG_CURRENT_DESKTOP to Unity
|
|
||||||
// DESKTOP_SESSION can be gnome-fallback or gnome-fallback-compiz
|
|
||||||
if (desktopSession.contains(qstr("gnome-fallback"))) {
|
|
||||||
result.push_back(Type::Gnome);
|
|
||||||
}
|
|
||||||
result.push_back(Type::Unity);
|
|
||||||
} else if (desktop == qstr("gnome")) {
|
|
||||||
result.push_back(Type::Gnome);
|
|
||||||
} else if (desktop == qstr("x-cinnamon") || desktop == qstr("cinnamon")) {
|
|
||||||
result.push_back(Type::Cinnamon);
|
|
||||||
} else if (desktop == qstr("kde")) {
|
|
||||||
result.push_back(Type::KDE);
|
|
||||||
} else if (desktop == qstr("mate")) {
|
|
||||||
result.push_back(Type::MATE);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
for (const auto ¤t : xdgCurrentDesktop) {
|
|
||||||
desktopToType(current);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!xdgSessionDesktop.isEmpty()) {
|
|
||||||
desktopToType(xdgSessionDesktop);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!desktopSession.isEmpty()) {
|
|
||||||
desktopToType(desktopSession);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fall back on some older environment variables.
|
|
||||||
// Useful particularly in the DESKTOP_SESSION=default case.
|
|
||||||
if (!GetEnv("GNOME_DESKTOP_SESSION_ID").isEmpty()) {
|
|
||||||
result.push_back(Type::Gnome);
|
|
||||||
}
|
|
||||||
if (!GetEnv("KDE_FULL_SESSION").isEmpty()) {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
result = result | ranges::views::unique | ranges::to_vector;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<Type> ComputeAndLog() {
|
|
||||||
const auto result = Compute();
|
|
||||||
if (result.empty()) {
|
|
||||||
LOG(("DE: Other"));
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
const auto names = ranges::accumulate(
|
|
||||||
result | ranges::views::transform([](auto type) {
|
|
||||||
switch (type) {
|
|
||||||
case Type::Gnome: return u"Gnome, "_q;
|
|
||||||
case Type::Cinnamon: return u"Cinnamon, "_q;
|
|
||||||
case Type::KDE: return u"KDE, "_q;
|
|
||||||
case Type::Unity: return u"Unity, "_q;
|
|
||||||
case Type::MATE: return u"MATE, "_q;
|
|
||||||
}
|
|
||||||
Unexpected("Type in Platform::DesktopEnvironment::ComputeAndLog");
|
|
||||||
}),
|
|
||||||
QString()).chopped(2);
|
|
||||||
LOG(("DE: %1").arg(names));
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
// Thanks Chromium.
|
|
||||||
std::vector<Type> Get() {
|
|
||||||
static const auto result = ComputeAndLog();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace DesktopEnvironment
|
|
||||||
} // namespace Platform
|
|
|
@ -1,44 +0,0 @@
|
||||||
/*
|
|
||||||
This file is part of Telegram Desktop,
|
|
||||||
the official desktop application for the Telegram messaging service.
|
|
||||||
|
|
||||||
For license and copyright information please follow this link:
|
|
||||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
namespace Platform {
|
|
||||||
namespace DesktopEnvironment {
|
|
||||||
|
|
||||||
enum class Type {
|
|
||||||
Gnome,
|
|
||||||
Cinnamon,
|
|
||||||
KDE,
|
|
||||||
Unity,
|
|
||||||
MATE,
|
|
||||||
};
|
|
||||||
|
|
||||||
std::vector<Type> Get();
|
|
||||||
|
|
||||||
inline bool IsGnome() {
|
|
||||||
return ranges::contains(Get(), Type::Gnome);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool IsCinnamon() {
|
|
||||||
return ranges::contains(Get(), Type::Cinnamon);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool IsKDE() {
|
|
||||||
return ranges::contains(Get(), Type::KDE);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool IsUnity() {
|
|
||||||
return ranges::contains(Get(), Type::Unity);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool IsMATE() {
|
|
||||||
return ranges::contains(Get(), Type::MATE);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace DesktopEnvironment
|
|
||||||
} // namespace Platform
|
|
|
@ -12,7 +12,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "base/platform/linux/base_linux_dbus_utilities.h"
|
#include "base/platform/linux/base_linux_dbus_utilities.h"
|
||||||
#include "base/platform/linux/base_linux_xdp_utilities.h"
|
#include "base/platform/linux/base_linux_xdp_utilities.h"
|
||||||
#include "ui/platform/ui_platform_window_title.h"
|
#include "ui/platform/ui_platform_window_title.h"
|
||||||
#include "platform/linux/linux_desktop_environment.h"
|
|
||||||
#include "platform/linux/linux_wayland_integration.h"
|
#include "platform/linux/linux_wayland_integration.h"
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
@ -728,22 +727,13 @@ bool OpenSystemSettings(SystemSettingsType type) {
|
||||||
}
|
}
|
||||||
options.push_back(std::move(command));
|
options.push_back(std::move(command));
|
||||||
};
|
};
|
||||||
for (const auto &type : DesktopEnvironment::Get()) {
|
add("unity-control-center", "sound");
|
||||||
using DesktopEnvironment::Type;
|
add("kcmshell6", "kcm_pulseaudio");
|
||||||
if (type == Type::Unity) {
|
add("kcmshell5", "kcm_pulseaudio");
|
||||||
add("unity-control-center", "sound");
|
add("kcmshell4", "phonon");
|
||||||
} else if (type == Type::KDE) {
|
add("gnome-control-center", "sound");
|
||||||
add("kcmshell6", "kcm_pulseaudio");
|
add("cinnamon-settings", "sound");
|
||||||
add("kcmshell5", "kcm_pulseaudio");
|
add("mate-volume-control");
|
||||||
add("kcmshell4", "phonon");
|
|
||||||
} else if (type == Type::Gnome) {
|
|
||||||
add("gnome-control-center", "sound");
|
|
||||||
} else if (type == Type::Cinnamon) {
|
|
||||||
add("cinnamon-settings", "sound");
|
|
||||||
} else if (type == Type::MATE) {
|
|
||||||
add("mate-volume-control");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
add("pavucontrol-qt");
|
add("pavucontrol-qt");
|
||||||
add("pavucontrol");
|
add("pavucontrol");
|
||||||
add("alsamixergui");
|
add("alsamixergui");
|
||||||
|
|
Loading…
Add table
Reference in a new issue