UI: Hide Dock Icon on Mac OSX when minimizing to tray

This hides the dock icon when minimizing OBS to the tray on OSX. This
also fixes the bugs with minimizing on startup (and hides the dock icon
correctly in that case as well).

Closes obsproject/obs-studio#1430
This commit is contained in:
DungFu 2018-08-17 03:50:25 -07:00 committed by jp9000
parent 71d2e870bb
commit 5cbc78b0a9
3 changed files with 30 additions and 0 deletions

View File

@ -168,3 +168,11 @@ void EnableOSXVSync(bool enable)
deferred_updates(enable ? 1 : 0);
}
}
void EnableOSXDockIcon(bool enable)
{
if (enable)
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
else
[NSApp setActivationPolicy:NSApplicationActivationPolicyProhibited];
}

View File

@ -63,4 +63,5 @@ RunOnceMutex GetRunOnceMutex(bool &already_running);
#ifdef __APPLE__
void EnableOSXVSync(bool enable);
void EnableOSXDockIcon(bool enable);
#endif

View File

@ -1594,7 +1594,9 @@ void OBSBasic::OBSInit()
ui->lockUI->setChecked(docksLocked);
ui->lockUI->blockSignals(false);
#ifndef __APPLE__
SystemTray(true);
#endif
if (windowState().testFlag(Qt::WindowFullScreen))
fullscreenInterface = true;
@ -1719,6 +1721,10 @@ void OBSBasic::DeferredLoad(const QString &file, int requeueCount)
Load(QT_TO_UTF8(file));
RefreshSceneCollections();
OnFirstLoad();
/* Minimizng to tray on initial startup does not work on mac
* unless it is done in the deferred load */
SystemTray(true);
}
/* shows a "what's new" page on startup of new versions using CEF */
@ -6204,6 +6210,10 @@ void OBSBasic::SetShowing(bool showing)
setVisible(false);
#ifdef __APPLE__
EnableOSXDockIcon(false);
#endif
} else if (showing && !isVisible()) {
if (showHide)
showHide->setText(QTStr("Basic.SystemTray.Hide"));
@ -6214,6 +6224,14 @@ void OBSBasic::SetShowing(bool showing)
setVisible(true);
#ifdef __APPLE__
EnableOSXDockIcon(true);
#endif
/* raise and activate window to ensure it is on top */
raise();
activateWindow();
/* show all child dialogs that was visible earlier */
if (!visDialogs.isEmpty()) {
for (int i = 0; i < visDialogs.size(); ++i) {
@ -6341,6 +6359,9 @@ void OBSBasic::SystemTray(bool firstStarted)
QTimer::singleShot(50, this, SLOT(hide()));
EnablePreviewDisplay(false);
setVisible(false);
#ifdef __APPLE__
EnableOSXDockIcon(false);
#endif
opt_minimize_tray = false;
}
} else if (sysTrayEnabled) {