From b5eb0b3f3e0ff8bbca3713a0244ca948d38ffca7 Mon Sep 17 00:00:00 2001 From: WarmUpTill Date: Wed, 4 May 2022 15:17:44 +0200 Subject: [PATCH] Add option to disable registering of pause control hotkeys --- data/locale/en-US.ini | 1 + src/headers/macro-properties.hpp | 10 ++++++++-- src/headers/macro.hpp | 4 ++++ src/macro-properties.cpp | 21 +++++++++++++++++---- src/macro-tab.cpp | 3 ++- src/macro.cpp | 27 +++++++++++++++++++++++++-- 6 files changed, 57 insertions(+), 9 deletions(-) diff --git a/data/locale/en-US.ini b/data/locale/en-US.ini index 02c6d81c..a480636b 100644 --- a/data/locale/en-US.ini +++ b/data/locale/en-US.ini @@ -82,6 +82,7 @@ AdvSceneSwitcher.macroTab.minimize="Minimize" AdvSceneSwitcher.macroTab.highlightExecutedMacros="Highlight recently executed macros" AdvSceneSwitcher.macroTab.highlightTrueConditions="Highlight conditions of currently selected macro that evaluated to true recently" AdvSceneSwitcher.macroTab.highlightPerformedActions="Highlight recently performed actions of currently selected macro" +AdvSceneSwitcher.macroTab.disableHotkeys="Register hotkeys to control pause state of selected macro" ; Macro Logic AdvSceneSwitcher.logic.none="Ignore entry" diff --git a/src/headers/macro-properties.hpp b/src/headers/macro-properties.hpp index 91940952..e1c86cca 100644 --- a/src/headers/macro-properties.hpp +++ b/src/headers/macro-properties.hpp @@ -1,10 +1,12 @@ #pragma once +#include "macro.hpp" #include #include #include #include +// Global macro properties class MacroProperties { public: void Save(obs_data_t *obj); @@ -15,15 +17,19 @@ public: bool _highlightActions = false; }; +// Dialog for configuring global and macro specific settings class MacroPropertiesDialog : public QDialog { Q_OBJECT public: - MacroPropertiesDialog(QWidget *parent, const MacroProperties &); - static bool AskForSettings(QWidget *parent, MacroProperties &userInput); + MacroPropertiesDialog(QWidget *parent, const MacroProperties &, + Macro *macro); + static bool AskForSettings(QWidget *parent, MacroProperties &userInput, + Macro *macro); private: QCheckBox *_executed; QCheckBox *_conditions; QCheckBox *_actions; + QCheckBox *_hotkeys; }; diff --git a/src/headers/macro.hpp b/src/headers/macro.hpp index 09240cae..d0236cea 100644 --- a/src/headers/macro.hpp +++ b/src/headers/macro.hpp @@ -114,6 +114,9 @@ public: bool OnChangePreventedActionsRecently(); void ResetUIHelpers(); + void EnablePauseHotkeys(bool); + bool PauseHotkeysEnabled(); + private: void SetupHotkeys(); void ClearHotkeys(); @@ -132,6 +135,7 @@ private: bool _matchOnChange = false; bool _paused = false; int _count = 0; + bool _registerHotkeys = true; obs_hotkey_id _pauseHotkey = OBS_INVALID_HOTKEY_ID; obs_hotkey_id _unpauseHotkey = OBS_INVALID_HOTKEY_ID; obs_hotkey_id _togglePauseHotkey = OBS_INVALID_HOTKEY_ID; diff --git a/src/macro-properties.cpp b/src/macro-properties.cpp index 9b887561..6e90de00 100644 --- a/src/macro-properties.cpp +++ b/src/macro-properties.cpp @@ -31,14 +31,17 @@ void MacroProperties::Load(obs_data_t *obj) } MacroPropertiesDialog::MacroPropertiesDialog(QWidget *parent, - const MacroProperties &prop) + const MacroProperties &prop, + Macro *macro) : QDialog(parent), _executed(new QCheckBox(obs_module_text( "AdvSceneSwitcher.macroTab.highlightExecutedMacros"))), _conditions(new QCheckBox(obs_module_text( "AdvSceneSwitcher.macroTab.highlightTrueConditions"))), _actions(new QCheckBox(obs_module_text( - "AdvSceneSwitcher.macroTab.highlightPerformedActions"))) + "AdvSceneSwitcher.macroTab.highlightPerformedActions"))), + _hotkeys(new QCheckBox( + obs_module_text("AdvSceneSwitcher.macroTab.disableHotkeys"))) { setModal(true); setWindowModality(Qt::WindowModality::WindowModal); @@ -49,11 +52,17 @@ MacroPropertiesDialog::MacroPropertiesDialog(QWidget *parent, _executed->setChecked(prop._highlightExecuted); _conditions->setChecked(prop._highlightConditions); _actions->setChecked(prop._highlightActions); + if (macro) { + _hotkeys->setChecked(macro->PauseHotkeysEnabled()); + } else { + _hotkeys->hide(); + } QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(_executed); layout->addWidget(_conditions); layout->addWidget(_actions); + layout->addWidget(_hotkeys); setLayout(layout); QDialogButtonBox *buttonbox = new QDialogButtonBox( @@ -65,9 +74,10 @@ MacroPropertiesDialog::MacroPropertiesDialog(QWidget *parent, } bool MacroPropertiesDialog::AskForSettings(QWidget *parent, - MacroProperties &userInput) + MacroProperties &userInput, + Macro *macro) { - MacroPropertiesDialog dialog(parent, userInput); + MacroPropertiesDialog dialog(parent, userInput, macro); dialog.setWindowTitle(obs_module_text("AdvSceneSwitcher.windowTitle")); if (dialog.exec() != DialogCode::Accepted) { return false; @@ -75,5 +85,8 @@ bool MacroPropertiesDialog::AskForSettings(QWidget *parent, userInput._highlightExecuted = dialog._executed->isChecked(); userInput._highlightConditions = dialog._conditions->isChecked(); userInput._highlightActions = dialog._actions->isChecked(); + if (macro) { + macro->EnablePauseHotkeys(dialog._hotkeys->isChecked()); + } return true; } diff --git a/src/macro-tab.cpp b/src/macro-tab.cpp index 31a25a5a..bfd6b2e0 100644 --- a/src/macro-tab.cpp +++ b/src/macro-tab.cpp @@ -408,7 +408,8 @@ void AdvSceneSwitcher::HighlightOnChange() void AdvSceneSwitcher::on_macroProperties_clicked() { MacroProperties prop = switcher->macroProperties; - bool accepted = MacroPropertiesDialog::AskForSettings(this, prop); + bool accepted = MacroPropertiesDialog::AskForSettings( + this, prop, getSelectedMacro()); if (!accepted) { return; } diff --git a/src/macro.cpp b/src/macro.cpp index 9226ed40..f420dfb0 100644 --- a/src/macro.cpp +++ b/src/macro.cpp @@ -23,7 +23,6 @@ const std::map MacroCondition::logicTypes = { Macro::Macro(const std::string &name) { - SetupHotkeys(); SetName(name); } @@ -262,6 +261,7 @@ bool Macro::Save(obs_data_t *obj) obs_data_set_bool(obj, "parallel", _runInParallel); obs_data_set_bool(obj, "onChange", _matchOnChange); + obs_data_set_bool(obj, "registerHotkeys", _registerHotkeys); obs_data_array_t *pauseHotkey = obs_hotkey_save(_pauseHotkey); obs_data_set_array(obj, "pauseHotkey", pauseHotkey); obs_data_array_release(pauseHotkey); @@ -341,6 +341,11 @@ bool Macro::Load(obs_data_t *obj) _runInParallel = obs_data_get_bool(obj, "parallel"); _matchOnChange = obs_data_get_bool(obj, "onChange"); + obs_data_set_default_bool(obj, "registerHotkeys", true); + _registerHotkeys = obs_data_get_bool(obj, "registerHotkeys"); + if (_registerHotkeys) { + SetupHotkeys(); + } obs_data_array_t *pauseHotkey = obs_data_get_array(obj, "pauseHotkey"); obs_hotkey_load(_pauseHotkey, pauseHotkey); obs_data_array_release(pauseHotkey); @@ -352,7 +357,6 @@ bool Macro::Load(obs_data_t *obj) obs_data_get_array(obj, "togglePauseHotkey"); obs_hotkey_load(_togglePauseHotkey, togglePauseHotkey); obs_data_array_release(togglePauseHotkey); - SetHotkeysDesc(); bool root = true; @@ -470,6 +474,25 @@ void Macro::ResetUIHelpers() } } +void Macro::EnablePauseHotkeys(bool value) +{ + if (_registerHotkeys == value) { + return; + } + + if (_registerHotkeys) { + ClearHotkeys(); + } else { + SetupHotkeys(); + } + _registerHotkeys = value; +} + +bool Macro::PauseHotkeysEnabled() +{ + return _registerHotkeys; +} + static void pauseCB(void *data, obs_hotkey_id, obs_hotkey_t *, bool pressed) { if (pressed) {