From 08d4b348e0f67789a8ebb65e9b63dd07b9b6915e Mon Sep 17 00:00:00 2001 From: sithlord48 Date: Thu, 2 Jan 2025 14:04:49 -0500 Subject: [PATCH] fix: use the closeEvent to hide to tray and quit the application --- src/apps/deskflow-gui/MainWindow.cpp | 46 +++++++++------------------- src/apps/deskflow-gui/MainWindow.h | 3 -- 2 files changed, 15 insertions(+), 34 deletions(-) diff --git a/src/apps/deskflow-gui/MainWindow.cpp b/src/apps/deskflow-gui/MainWindow.cpp index e15cd37a3..f7a6c7549 100644 --- a/src/apps/deskflow-gui/MainWindow.cpp +++ b/src/apps/deskflow-gui/MainWindow.cpp @@ -130,8 +130,6 @@ MainWindow::MainWindow(ConfigScopes &configScopes, AppConfig &appConfig) m_ConfigScopes.signalReady(); - applyCloseToTray(); - updateScreenName(); applyConfig(); restoreWindow(); @@ -270,7 +268,7 @@ void MainWindow::connectSlots() connect(m_actionHelp, &QAction::triggered, this, &MainWindow::openHelpUrl); connect(m_actionMinimize, &QAction::triggered, this, &MainWindow::hide); - connect(m_actionQuit, &QAction::triggered, this, &MainWindow::quitApp); + connect(m_actionQuit, &QAction::triggered, this, &MainWindow::close); connect(m_actionRestore, &QAction::triggered, this, &MainWindow::showAndActivate); connect(m_actionSave, &QAction::triggered, this, &MainWindow::saveConfig); connect(m_actionSettings, &QAction::triggered, this, &MainWindow::openSettings); @@ -438,7 +436,6 @@ void MainWindow::clearSettings() m_CoreProcess.stop(); - m_Quitting = true; m_SaveOnExit = false; diagnostic::clearSettings(m_ConfigScopes, true); } @@ -474,7 +471,6 @@ void MainWindow::openSettings() m_ConfigScopes.save(); applyConfig(); - applyCloseToTray(); if (m_CoreProcess.isStarted()) { m_CoreProcess.restart(); @@ -527,13 +523,6 @@ void MainWindow::setModeClient() m_ConfigScopes.save(); } -void MainWindow::quitApp() -{ - qDebug() << "quitting application"; - m_Quitting = true; - QApplication::quit(); -} - void MainWindow::onWindowSaveTimerTimeout() { saveWindow(); @@ -580,7 +569,7 @@ void MainWindow::open() // Duplicate quit needed for mac os tray menu QAction *actionTrayQuit = new QAction(tr("Quit Deskflow"), this); actionTrayQuit->setShortcut(QKeySequence::Quit); - connect(actionTrayQuit, &QAction::triggered, this, &MainWindow::quitApp); + connect(actionTrayQuit, &QAction::triggered, this, &MainWindow::close); m_actionRestore->setText(tr("Open Deskflow")); trayActions.insert(3, m_actionRestore); @@ -676,11 +665,6 @@ void MainWindow::applyConfig() updateLocalFingerprint(); } -void MainWindow::applyCloseToTray() const -{ - QApplication::setQuitOnLastWindowClosed(!m_AppConfig.closeToTray()); -} - void MainWindow::saveSettings() { m_AppConfig.setServerGroupChecked(ui->rbModeServer->isChecked()); @@ -809,23 +793,23 @@ void MainWindow::showEvent(QShowEvent *event) void MainWindow::closeEvent(QCloseEvent *event) { - if (m_Quitting) { - qDebug() << "skipping close event handle on quit"; + if (m_AppConfig.closeToTray() && event->spontaneous()) { + if (m_AppConfig.showCloseReminder()) { + messages::showCloseReminder(this); + m_AppConfig.setShowCloseReminder(false); + } + qDebug() << "hiding to tray"; + hide(); + event->ignore(); return; } - if (!m_AppConfig.closeToTray()) { - qDebug() << "window will not hide to tray"; - return; - } + if (m_SaveOnExit) + m_ConfigScopes.save(); - if (m_AppConfig.showCloseReminder()) { - messages::showCloseReminder(this); - m_AppConfig.setShowCloseReminder(false); - } - - m_ConfigScopes.save(); - qDebug() << "window should hide to tray"; + qDebug() << "quitting application"; + event->accept(); + QApplication::quit(); } void MainWindow::showFirstConnectedMessage() diff --git a/src/apps/deskflow-gui/MainWindow.h b/src/apps/deskflow-gui/MainWindow.h index 3d7334edb..d188e0c36 100644 --- a/src/apps/deskflow-gui/MainWindow.h +++ b/src/apps/deskflow-gui/MainWindow.h @@ -138,7 +138,6 @@ private slots: private: std::unique_ptr ui; - void quitApp(); void updateSize(); AppConfig &appConfig() { @@ -152,7 +151,6 @@ private: void createStatusBar(); void createTrayIcon(); void applyConfig(); - void applyCloseToTray() const; void setIcon(); bool checkForApp(int which, QString &app); void setStatus(const QString &status); @@ -190,7 +188,6 @@ private: QAbstractButton *m_pCancelButton = nullptr; bool m_SecureSocket = false; bool m_SaveWindow = false; - bool m_Quitting = false; deskflow::gui::config::ServerConfigDialogState m_ServerConfigDialogState; bool m_SaveOnExit = true; deskflow::gui::core::WaylandWarnings m_WaylandWarnings;