diff --git a/res/qml/main.qml b/res/qml/main.qml index ddd1fc5..215899d 100644 --- a/res/qml/main.qml +++ b/res/qml/main.qml @@ -52,8 +52,7 @@ ApplicationWindow { Qt.quit(); } - function display() { - /* + function openSysTray() { var rect = platformDetails.getAbsoluteCursorPosition(); console.log("mouse cursor at: "+ rect.x +", "+ rect.y); @@ -83,10 +82,12 @@ ApplicationWindow { var winX = (right ? (rect.x - window.width) : rect.x); var winY = (bottom ? (rect.y - window.height) : rect.y); - window.x = winX; - window.y = winY; - console.log("updated window popup position: "+ window.x + ", "+ window.y); - */ + // systrayMenu.x = winX; + // systrayMenu.y = winY; + systrayMenu.visible = true; + } + + function display() { window.show(); window.raise(); window.requestActivate(); @@ -96,12 +97,12 @@ ApplicationWindow { SystemTrayIcon { id: systray tooltip: qsTr("Loki Network") - visible: !platformDetails.isLinux() + visible: platformDetails.hasSysTray(); iconSource: "qrc:/res/images/icon.svg" menu: Menu { id: systrayMenu - enabled: true + enabled: platformDetails.hasSysTray(); MenuItem { text: qsTr("Show") @@ -163,12 +164,11 @@ ApplicationWindow { // right click case SystemTrayIcon.Context: - systrayMenu.open(); + window.openSysTray(); break; - // left click case SystemTrayIcon.Trigger: - systrayMenu.open(); + window.display(); break; case SystemTrayIcon.DoubleClick: diff --git a/src/PlatformDetails.cpp b/src/PlatformDetails.cpp index 12d0211..b1a4ed5 100644 --- a/src/PlatformDetails.cpp +++ b/src/PlatformDetails.cpp @@ -26,6 +26,39 @@ Q_INVOKABLE bool PlatformDetails::isLinux() { #endif } +// PlatformDetails::hasSysTray +Q_INVOKABLE bool PlatformDetails::hasSysTray() { + if(isWindows()) + return true; + if(isMacOS()) + return true; + if(isGayland()) + { + // pretty much every sane environment has a systray but not gayland (GNOME WAYLAND) because $reasons. + return false; + } + if(isLinux()) + return true; + // we don't know what we are runnning on let's assume we dont have a tray + return false; +} + +// PlatformDetails::isGayland +Q_INVOKABLE bool PlatformDetails::isGayland() { +#if defined(Q_OS_LINUX) + if(const auto wayland = ::getenv("WAYLAND_DISPLAY"); wayland) + { + if(const auto desktop = ::getenv("XDG_CURRENT_DESKTOP"); desktop) + { + return std::string{desktop} == "GNOME"; + } + } + return false; +#else + return false; +#endif +} + // PlatformDetails::isMacOS Q_INVOKABLE bool PlatformDetails::isMacOS() { #if defined(Q_OS_MACOS) diff --git a/src/PlatformDetails.hpp b/src/PlatformDetails.hpp index f6d7612..e41b39f 100644 --- a/src/PlatformDetails.hpp +++ b/src/PlatformDetails.hpp @@ -16,9 +16,16 @@ class PlatformDetails : public QObject public: + /// return if we are on windows Q_INVOKABLE static bool isWindows(); + /// return if we are on linux Q_INVOKABLE static bool isLinux(); + /// return if we are on gnome wayland + Q_INVOKABLE static bool isGayland(); + /// return if we are on macos Q_INVOKABLE static bool isMacOS(); + /// return if we have a system tray or not + Q_INVOKABLE static bool hasSysTray(); Q_INVOKABLE static bool isDebug();