diff --git a/frontend/OBSApp.cpp b/frontend/OBSApp.cpp index de10127b54b44e..dda72244ec0a6c 100644 --- a/frontend/OBSApp.cpp +++ b/frontend/OBSApp.cpp @@ -51,6 +51,12 @@ #include #endif +#include +#include +#include +#include +#include + #include "moc_OBSApp.cpp" using namespace std; @@ -1130,9 +1136,47 @@ bool OBSApp::OBSInit() connect(this, &QGuiApplication::applicationStateChanged, [this](Qt::ApplicationState state) { ResetHotkeyState(state == Qt::ApplicationActive); }); ResetHotkeyState(applicationState() == Qt::ApplicationActive); + + connect(this, &QApplication::focusChanged, this, &OBSApp::WidgetFocusChanged); return true; } +static bool IsWidgetEditable(QWidget *widget) +{ + if (!widget) + return false; + + if (qobject_cast(widget) || qobject_cast(widget) || + qobject_cast(widget) || qobject_cast(widget) || + qobject_cast(widget)) + return true; + else + return false; +} + +void OBSApp::WidgetFocusChanged(QWidget *, QWidget *now) +{ + bool wasDisabled = hotkeysDisabled; + bool nowDisabled = false; + QWidget *parent = nullptr; + + if (now) + parent = qobject_cast(now->window()); + + if ((parent && parent->isModal()) || IsWidgetEditable(now)) + nowDisabled = true; + + if (wasDisabled != nowDisabled) { + if (!wasDisabled) { + DisableHotkeys(); + hotkeysDisabled = true; + } else { + UpdateHotkeyFocusSetting(); + hotkeysDisabled = false; + } + } +} + string OBSApp::GetVersionString(bool platform) const { stringstream ver; diff --git a/frontend/OBSApp.hpp b/frontend/OBSApp.hpp index ce0c4fb6594cc4..71c508de0c909a 100644 --- a/frontend/OBSApp.hpp +++ b/frontend/OBSApp.hpp @@ -70,6 +70,7 @@ class OBSApp : public QApplication { bool enableHotkeysInFocus = true; bool enableHotkeysOutOfFocus = true; + bool hotkeysDisabled = false; std::deque translatorHooks; @@ -189,6 +190,9 @@ private slots: static void SigIntSignalHandler(int); #endif +private slots: + void WidgetFocusChanged(QWidget *old, QWidget *now); + public slots: void Exec(VoidFunc func); void ProcessSigInt(); diff --git a/frontend/settings/OBSBasicSettings.cpp b/frontend/settings/OBSBasicSettings.cpp index 32e2d92debb6c2..11a161c6c7bce6 100644 --- a/frontend/settings/OBSBasicSettings.cpp +++ b/frontend/settings/OBSBasicSettings.cpp @@ -873,8 +873,6 @@ OBSBasicSettings::OBSBasicSettings(QWidget *parent) UpdateAutomaticReplayBufferCheckboxes(); - App()->DisableHotkeys(); - channelIndex = ui->channelSetup->currentIndex(); sampleRateIndex = ui->sampleRate->currentIndex(); llBufferingEnabled = ui->lowLatencyBuffering->isChecked(); @@ -908,8 +906,6 @@ OBSBasicSettings::~OBSBasicSettings() delete ui->filenameFormatting->completer(); main->EnableOutputs(true); - App()->UpdateHotkeyFocusSetting(); - EnableThreadedMessageBoxes(false); }