Skip to content

Commit 2191cf6

Browse files
fix: avoid hiding floating docks when the OBS app is not active.
This PR changes the behavior of floating docks on macOS to have them stay visible while the OBS app is not active. The main change is to set the `NSWindow.hidesOnDeactivate` setting to false. This is enough to keep the docks visible. The remaining changes are just making sure that this setting is consistent across all the different ways OBS creates docks. In macOS, only one app can be "active" (aka "focused") at the time, and "floating panels" (OBS' docks in this case) disappear by default when their parent app is not active. The issue is that disappearing floating panels defy many of the use cases that OBS is great for. For example: - I'm doing game streaming on Twitch. I want to keep track of my chat. - I have a floating panel displaying the "Twitch chat" dock on a side monitor. - I click on my game, which becomes the active app. OBS is not the active app anymore, therefore the chat dock panel disappears. This is a common issue between macOS users: - https://obsproject.com/forum/threads/popped-out-docks-disappear-when-obs-is-not-in-focus.165011/ - https://obsproject.com/forum/threads/keep-dock-windows-visible-even-when-obs-is-not-in-focus.167324/
1 parent 154088b commit 2191cf6

2 files changed

Lines changed: 35 additions & 2 deletions

File tree

frontend/docks/OBSDock.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,20 @@
44

55
#include <QCheckBox>
66
#include <QMessageBox>
7+
#include <QTimer>
78

89
#include "moc_OBSDock.cpp"
910

11+
OBSDock::OBSDock(QWidget *parent) : QDockWidget(parent)
12+
{
13+
InstallDockFloatingBehavior(this);
14+
}
15+
16+
OBSDock::OBSDock(const QString &title, QWidget *parent) : QDockWidget(title, parent)
17+
{
18+
InstallDockFloatingBehavior(this);
19+
}
20+
1021
void OBSDock::closeEvent(QCloseEvent *event)
1122
{
1223
auto msgBox = []() {
@@ -43,4 +54,24 @@ void OBSDock::closeEvent(QCloseEvent *event)
4354
void OBSDock::showEvent(QShowEvent *event)
4455
{
4556
QDockWidget::showEvent(event);
57+
#ifdef __APPLE__
58+
this->setAttribute(Qt::WA_MacAlwaysShowToolWindow, true);
59+
#endif
60+
}
61+
62+
void InstallDockFloatingBehavior(QDockWidget *dock)
63+
{
64+
#ifdef __APPLE__
65+
if (!dock)
66+
return;
67+
68+
QObject::connect(dock, &QDockWidget::topLevelChanged, dock,
69+
[dock](bool) { dock->setAttribute(Qt::WA_MacAlwaysShowToolWindow, true); });
70+
71+
if (dock->isFloating()) {
72+
QTimer::singleShot(0, dock, [dock]() { dock->setAttribute(Qt::WA_MacAlwaysShowToolWindow, true); });
73+
}
74+
#else
75+
Q_UNUSED(dock);
76+
#endif
4677
}

frontend/docks/OBSDock.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ class OBSDock : public QDockWidget {
1010
Q_OBJECT
1111

1212
public:
13-
inline OBSDock(QWidget *parent = nullptr) : QDockWidget(parent) {}
14-
inline OBSDock(const QString &title, QWidget *parent = nullptr) : QDockWidget(title, parent) {}
13+
OBSDock(QWidget *parent = nullptr);
14+
OBSDock(const QString &title, QWidget *parent = nullptr);
1515

1616
virtual void closeEvent(QCloseEvent *event);
1717
virtual void showEvent(QShowEvent *event);
1818
};
19+
20+
void InstallDockFloatingBehavior(QDockWidget *dock);

0 commit comments

Comments
 (0)