Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI: Disable hotkeys when typing or in modal dialog #7924

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
38 changes: 38 additions & 0 deletions UI/obs-app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1302,9 +1302,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<OBSPlainTextEdit *>(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 UI/obs-app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,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 @@ -222,6 +223,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 UI/window-basic-settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -894,8 +894,6 @@ OBSBasicSettings::OBSBasicSettings(QWidget *parent)

UpdateAutomaticReplayBufferCheckboxes();

App()->DisableHotkeys();

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

App()->UpdateHotkeyFocusSetting();

EnableThreadedMessageBoxes(false);
}

Expand Down
Loading