Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions frontend/OBSApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@
#include <sys/socket.h>
#endif

#include <QDoubleSpinBox>
#include <QLineEdit>
#include <QPlainTextEdit>
#include <QSpinBox>
#include <QTextEdit>

#include "moc_OBSApp.cpp"

using namespace std;
Expand Down Expand Up @@ -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<QLineEdit *>(widget) || qobject_cast<QTextEdit *>(widget) ||
qobject_cast<QPlainTextEdit *>(widget) || qobject_cast<QSpinBox *>(widget) ||
qobject_cast<QDoubleSpinBox *>(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<QWidget *>(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;
Expand Down
4 changes: 4 additions & 0 deletions frontend/OBSApp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class OBSApp : public QApplication {

bool enableHotkeysInFocus = true;
bool enableHotkeysOutOfFocus = true;
bool hotkeysDisabled = false;

std::deque<obs_frontend_translate_ui_cb> translatorHooks;

Expand Down Expand Up @@ -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();
Expand Down
4 changes: 0 additions & 4 deletions frontend/settings/OBSBasicSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -873,8 +873,6 @@ OBSBasicSettings::OBSBasicSettings(QWidget *parent)

UpdateAutomaticReplayBufferCheckboxes();

App()->DisableHotkeys();

channelIndex = ui->channelSetup->currentIndex();
sampleRateIndex = ui->sampleRate->currentIndex();
llBufferingEnabled = ui->lowLatencyBuffering->isChecked();
Expand Down Expand Up @@ -908,8 +906,6 @@ OBSBasicSettings::~OBSBasicSettings()
delete ui->filenameFormatting->completer();
main->EnableOutputs(true);

App()->UpdateHotkeyFocusSetting();

EnableThreadedMessageBoxes(false);
}

Expand Down