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.
This commit is contained in:
Le Tan 2017-08-26 21:04:36 +08:00
parent 98ef7c2cfa
commit b47982ab25
2 changed files with 17 additions and 2 deletions

View File

@ -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;
}

View File

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