From b47982ab25693d33c8ee4a9184a91a3ba88083cf Mon Sep 17 00:00:00 2001 From: Le Tan Date: Sat, 26 Aug 2017 21:04:36 +0800 Subject: [PATCH] macOS: disable minimizing to system tray In macOS, there is a "Quit" menu item in the Dock context menu. We can't not distinguish it from the close button in the title bar. For now, we just disable the ability to being minimized to system tray. --- src/dialog/vsettingsdialog.cpp | 12 ++++++++++-- src/vmainwindow.cpp | 7 +++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/dialog/vsettingsdialog.cpp b/src/dialog/vsettingsdialog.cpp index 275abb19..29498061 100644 --- a/src/dialog/vsettingsdialog.cpp +++ b/src/dialog/vsettingsdialog.cpp @@ -122,7 +122,12 @@ VGeneralTab::VGeneralTab(QWidget *p_parent) // System tray checkbox. m_systemTray = new QCheckBox(this); - m_systemTray->setToolTip(tr("Minimized to the system tray after closing VNote")); + m_systemTray->setToolTip(tr("Minimized to the system tray after closing VNote" + " (not supported in macOS)")); +#if defined(Q_OS_MACOS) || defined(Q_OS_MAC) + // Do not support minimized to tray on macOS. + m_systemTray->setEnabled(false); +#endif QLabel *trayLabel = new QLabel(tr("System tray:"), this); trayLabel->setToolTip(m_systemTray->toolTip()); @@ -203,7 +208,10 @@ bool VGeneralTab::loadSystemTray() bool VGeneralTab::saveSystemTray() { - vconfig.setMinimizeToSystemTray(m_systemTray->isChecked() ? 1 : 0); + if (m_systemTray->isEnabled()) { + vconfig.setMinimizeToSystemTray(m_systemTray->isChecked() ? 1 : 0); + } + return true; } diff --git a/src/vmainwindow.cpp b/src/vmainwindow.cpp index 34a0ba56..ce31e733 100644 --- a/src/vmainwindow.cpp +++ b/src/vmainwindow.cpp @@ -1576,6 +1576,11 @@ void VMainWindow::closeEvent(QCloseEvent *event) bool isExit = m_requestQuit || !vconfig.getMinimizeToStystemTray(); m_requestQuit = false; +#if defined(Q_OS_MACOS) || defined(Q_OS_MAC) + // Do not support minimized to tray on macOS. + isExit = true; +#endif + if (!isExit && vconfig.getMinimizeToStystemTray() == -1) { // Not initialized yet. Prompt for user. int ret = VUtils::showMessage(QMessageBox::Information, @@ -2030,6 +2035,8 @@ void VMainWindow::showMainWindow() } } else { this->show(); + // Need to call raise() in macOS. + this->raise(); } this->activateWindow();