From 56ad0b997566580ccd94568d0479ec94a1c39f9c Mon Sep 17 00:00:00 2001 From: vslg Date: Fri, 4 Sep 2020 15:31:17 -0300 Subject: [PATCH] Add config option closeMinimizesToTray Options of the system tray icon: - Hide/show Mirage - Quit Mirage Draw attention to Mirage when clicking on the icon --- src/backend/user_files.py | 1 + src/gui/Window.qml | 30 +++++++++++++++++++++++++++--- src/main.cpp | 3 +++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/backend/user_files.py b/src/backend/user_files.py index d12e0ac3..155feee5 100644 --- a/src/backend/user_files.py +++ b/src/backend/user_files.py @@ -273,6 +273,7 @@ class UISettings(JSONDataFile): "clearRoomFilterOnEnter": True, "clearRoomFilterOnEscape": True, "clearMemberFilterOnEscape": True, + "closeMinimizesToTray": False, "collapseSidePanesUnderWindowWidth": 450, "enableKineticScrolling": True, "hideProfileChangeEvents": True, diff --git a/src/gui/Window.qml b/src/gui/Window.qml index 53650f0f..66df915c 100644 --- a/src/gui/Window.qml +++ b/src/gui/Window.qml @@ -23,6 +23,7 @@ ApplicationWindow { property var uiState: ({}) property var history: ({}) property var theme: null + property bool closing: false readonly property var visibleMenus: ({}) readonly property var visiblePopups: ({}) @@ -65,6 +66,11 @@ ApplicationWindow { ) } + function drawAttention() { + window.show() + window.raise() + window.requestActivate() + } flags: Qt.WA_TranslucentBackground @@ -81,6 +87,11 @@ ApplicationWindow { onUiStateChanged: py.saveConfig("ui_state", uiState) onHistoryChanged: py.saveConfig("history", history) + onClosing: { + close.accepted = ! settings.closeMinimizesToTray + onTriggered: if (settings.closeMinimizesToTray) hide() + } + PythonRootBridge { id: py } Utils { id: utils } @@ -109,12 +120,25 @@ ApplicationWindow { tooltip: qsTr("Mirage") icon.source: `../icons/${iconPack}/tray-icon.png` - onActivated: window.show() + onActivated: + if (reason !== SystemTrayIcon.Context) + window.drawAttention() + menu: Menu { MenuItem { - text: qsTr("Quit") - onTriggered: window.hide() + text: window.visible ? "Hide Mirage" : "Show Mirage" + onTriggered: + window.visible ? + window.hide() : + window.drawAttention() + } + + MenuItem { + text: qsTr("Quit Mirage") + onTriggered: { + Qt.quit() + } } } } diff --git a/src/main.cpp b/src/main.cpp index e43236aa..fddfbeaa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -180,6 +180,9 @@ int main(int argc, char *argv[]) { QQmlEngine engine; QQmlContext *objectContext = new QQmlContext(engine.rootContext()); + // For being able to use Qt.quit() in QML side + QObject::connect(&engine, &QQmlEngine::quit, &QApplication::quit); + // Set the debugMode properties depending of if we're running in debug mode // or not (`qmake CONFIG+=dev ...`, default in live-reload.sh) #ifdef QT_DEBUG