add initial systray detection

This commit is contained in:
Jeff Becker 2020-11-26 07:34:33 -05:00
parent 69f2696c74
commit 9200fffae8
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05
3 changed files with 51 additions and 11 deletions

View File

@ -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:

View File

@ -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)

View File

@ -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();