From 5cbc78b0a93dc1f752f2d0d75106a65b8452d801 Mon Sep 17 00:00:00 2001 From: DungFu Date: Fri, 17 Aug 2018 03:50:25 -0700 Subject: [PATCH] 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 --- UI/platform-osx.mm | 8 ++++++++ UI/platform.hpp | 1 + UI/window-basic-main.cpp | 21 +++++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/UI/platform-osx.mm b/UI/platform-osx.mm index 19b1a9cdc..37e7c0abc 100644 --- a/UI/platform-osx.mm +++ b/UI/platform-osx.mm @@ -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]; +} diff --git a/UI/platform.hpp b/UI/platform.hpp index 5011e6050..4da23b3bd 100644 --- a/UI/platform.hpp +++ b/UI/platform.hpp @@ -63,4 +63,5 @@ RunOnceMutex GetRunOnceMutex(bool &already_running); #ifdef __APPLE__ void EnableOSXVSync(bool enable); +void EnableOSXDockIcon(bool enable); #endif diff --git a/UI/window-basic-main.cpp b/UI/window-basic-main.cpp index ada0d67c9..0f962b1c7 100644 --- a/UI/window-basic-main.cpp +++ b/UI/window-basic-main.cpp @@ -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) {