diff --git a/3rdparty/qv2ray/v2/proxy/QvProxyConfigurator.cpp b/3rdparty/qv2ray/v2/proxy/QvProxyConfigurator.cpp index 98fa53a..a1682a7 100644 --- a/3rdparty/qv2ray/v2/proxy/QvProxyConfigurator.cpp +++ b/3rdparty/qv2ray/v2/proxy/QvProxyConfigurator.cpp @@ -225,6 +225,18 @@ namespace Qv2ray::components::proxy { } #endif +#ifdef Q_OS_LINUX + QString GetKconfigCmd() { + if(qEnvironmentVariable("KDE_SESSION_VERSION") == "5") { + return "kwriteconfig5"; + } else if(qEnvironmentVariable("KDE_SESSION_VERSION") == "6") { + return "kwriteconfig6"; + } else { + return "kwriteconfig"; + } + } +#endif + void SetSystemProxy(int httpPort, int socksPort, QString scheme) { const QString &address = "127.0.0.1"; bool hasHTTP = (httpPort > 0 && httpPort < 65536); @@ -292,7 +304,7 @@ namespace Qv2ray::components::proxy { // for KDE: if (isKDE) { - actions << ProcessArgument{"kwriteconfig5", + actions << ProcessArgument{GetKconfigCmd(), {"--file", configPath + "/kioslaverc", // "--group", "Proxy Settings", // "--key", protocol + "Proxy", // @@ -311,7 +323,7 @@ namespace Qv2ray::components::proxy { // for KDE: if (isKDE) { - actions << ProcessArgument{"kwriteconfig5", + actions << ProcessArgument{GetKconfigCmd(), {"--file", configPath + "/kioslaverc", // "--group", "Proxy Settings", // "--key", "socksProxy", // @@ -328,7 +340,7 @@ namespace Qv2ray::components::proxy { // for KDE: if (isKDE) { - actions << ProcessArgument{"kwriteconfig5", + actions << ProcessArgument{GetKconfigCmd(), {"--file", configPath + "/kioslaverc", // "--group", "Proxy Settings", // "--key", "ProxyType", "1"}}; @@ -401,7 +413,7 @@ namespace Qv2ray::components::proxy { // for KDE: if (isKDE) { - actions << ProcessArgument{"kwriteconfig5", + actions << ProcessArgument{GetKconfigCmd(), {"--file", configRoot + "/kioslaverc", // "--group", "Proxy Settings", // "--key", "ProxyType", "0"}}; diff --git a/cmake/linux/linux.cmake b/cmake/linux/linux.cmake index c653a1d..a4dc9f5 100644 --- a/cmake/linux/linux.cmake +++ b/cmake/linux/linux.cmake @@ -1,2 +1,2 @@ -set(PLATFORM_SOURCES src/sys/linux/LinuxCap.cpp src/sys/linux/desktopinfo.cpp) +set(PLATFORM_SOURCES src/sys/linux/LinuxCap.cpp) set(PLATFORM_LIBRARIES dl) diff --git a/include/sys/linux/desktopinfo.h b/include/sys/linux/desktopinfo.h deleted file mode 100644 index 2daa226..0000000 --- a/include/sys/linux/desktopinfo.h +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once - -#include - -class DesktopInfo -{ -public: - DesktopInfo(); - - enum WM - { - GNOME, - KDE, - OTHER, - QTILE, - SWAY, - HYPRLAND - }; - - bool waylandDetected(); - WM windowManager(); - -private: - QString XDG_CURRENT_DESKTOP; - QString XDG_SESSION_TYPE; - QString WAYLAND_DISPLAY; - QString KDE_FULL_SESSION; - QString GNOME_DESKTOP_SESSION_ID; - QString GDMSESSION; - QString DESKTOP_SESSION; -}; diff --git a/src/main.cpp b/src/main.cpp index b6d4b28..161ed9c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,7 +22,6 @@ #include #endif #ifdef Q_OS_LINUX -#include "include/sys/linux/desktopinfo.h" #include #endif diff --git a/src/sys/linux/desktopinfo.cpp b/src/sys/linux/desktopinfo.cpp deleted file mode 100644 index 7225dd0..0000000 --- a/src/sys/linux/desktopinfo.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include "include/sys/linux/desktopinfo.h" -#include - -DesktopInfo::DesktopInfo() -{ - auto e = QProcessEnvironment::systemEnvironment(); - XDG_CURRENT_DESKTOP = e.value(QStringLiteral("XDG_CURRENT_DESKTOP")); - XDG_SESSION_TYPE = e.value(QStringLiteral("XDG_SESSION_TYPE")); - WAYLAND_DISPLAY = e.value(QStringLiteral("WAYLAND_DISPLAY")); - KDE_FULL_SESSION = e.value(QStringLiteral("KDE_FULL_SESSION")); - GNOME_DESKTOP_SESSION_ID = - e.value(QStringLiteral("GNOME_DESKTOP_SESSION_ID")); - DESKTOP_SESSION = e.value(QStringLiteral("DESKTOP_SESSION")); -} - -bool DesktopInfo::waylandDetected() -{ - return XDG_SESSION_TYPE == QLatin1String("wayland") || - WAYLAND_DISPLAY.contains(QLatin1String("wayland"), - Qt::CaseInsensitive); -} - -DesktopInfo::WM DesktopInfo::windowManager() -{ - DesktopInfo::WM res = DesktopInfo::OTHER; - QStringList desktops = XDG_CURRENT_DESKTOP.split(QChar(':')); - for (auto& desktop : desktops) { - if (desktop.contains(QLatin1String("GNOME"), Qt::CaseInsensitive)) { - return DesktopInfo::GNOME; - } - if (desktop.contains(QLatin1String("qtile"), Qt::CaseInsensitive)) { - return DesktopInfo::QTILE; - } - if (desktop.contains(QLatin1String("sway"), Qt::CaseInsensitive)) { - return DesktopInfo::SWAY; - } - if (desktop.contains(QLatin1String("Hyprland"), Qt::CaseInsensitive)) { - return DesktopInfo::HYPRLAND; - } - if (desktop.contains(QLatin1String("kde-plasma"))) { - return DesktopInfo::KDE; - } - } - - if (!GNOME_DESKTOP_SESSION_ID.isEmpty()) { - return DesktopInfo::GNOME; - } - - if (!KDE_FULL_SESSION.isEmpty()) { - return DesktopInfo::KDE; - } - - return res; -} diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index d97a1f5..a8b40ec 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -26,7 +26,6 @@ #else #ifdef Q_OS_LINUX #include "include/sys/linux/LinuxCap.h" -#include "include/sys/linux/desktopinfo.h" #include #include #include @@ -1910,8 +1909,7 @@ QPixmap grabScreen(QScreen* screen, bool& ok) QPixmap p; QRect geom = screen->geometry(); #ifdef Q_OS_LINUX - DesktopInfo m_info; - if (m_info.waylandDetected()) { + if (qEnvironmentVariable("XDG_SESSION_TYPE") == "wayland" || qEnvironmentVariable("WAYLAND_DISPLAY").contains("wayland", Qt::CaseInsensitive)) { QDBusInterface screenshotInterface( QStringLiteral("org.freedesktop.portal.Desktop"), QStringLiteral("/org/freedesktop/portal/desktop"),