diff --git a/data/locale/en-US.ini b/data/locale/en-US.ini index 1c58b335..8c19459d 100644 --- a/data/locale/en-US.ini +++ b/data/locale/en-US.ini @@ -856,6 +856,7 @@ AdvSceneSwitcher.condition.streamDeck.stopListen="Stop listening" AdvSceneSwitcher.condition.streamDeck.pluginDownload="

The Stream Deck plugin can be found here on GitHub.

" AdvSceneSwitcher.condition.gameCapture="Game capture" AdvSceneSwitcher.condition.gameCapture.entry="{{sources}}hooked a game." + AdvSceneSwitcher.condition.screenshot="Screenshot" AdvSceneSwitcher.condition.screenshot.entry="A screenshot was taken" AdvSceneSwitcher.condition.mqtt="MQTT" @@ -2538,6 +2539,9 @@ AdvSceneSwitcher.selectDisplay="--select display--" AdvSceneSwitcher.invaildEntriesWillNotBeSaved="invalid entries will not be saved" AdvSceneSwitcher.selectWindowTip="Use \"OBS\" to specify OBS window\nUse \"Task Switching\"to specify ALT + TAB" +AdvSceneSwitcher.keepSourceActive="Keep source active" +AdvSceneSwitcher.keepSourceActive.help="When a source is not visible in the active scene it becomes inactive, which can cause it to stop producing output (e.g. video frames or game capture hooks).\nEnabling this option forces the source to remain active at all times, ensuring it continues to produce output even when not displayed.\n\nNote: Keeping a source permanently active may increase CPU and GPU usage, as the source continues to run even when not shown." + AdvSceneSwitcher.settings.suffix.type.invalid=" (Invalid)" AdvSceneSwitcher.settings.suffix.type.bool=" (Bool)" AdvSceneSwitcher.settings.suffix.type.int=" (Int)" diff --git a/plugins/base/macro-condition-game-capture.cpp b/plugins/base/macro-condition-game-capture.cpp index 9fd9e8ed..98adb8d8 100644 --- a/plugins/base/macro-condition-game-capture.cpp +++ b/plugins/base/macro-condition-game-capture.cpp @@ -24,6 +24,8 @@ bool MacroConditionGameCapture::CheckCondition() return false; } + _activeKeeper.SetActive(_keepActive); + std::lock_guard lock(_mtx); if (_hooked) { SetTempVarValue("title", _title); @@ -38,6 +40,7 @@ bool MacroConditionGameCapture::Save(obs_data_t *obj) const { MacroCondition::Save(obj); _source.Save(obj); + obs_data_set_bool(obj, "keepActive", _keepActive); return true; } @@ -45,6 +48,7 @@ bool MacroConditionGameCapture::Load(obs_data_t *obj) { MacroCondition::Load(obj); _source.Load(obj); + _keepActive = obs_data_get_bool(obj, "keepActive"); SetupSignalHandler(OBSGetStrongRef(_source.GetSource())); return true; } @@ -111,6 +115,9 @@ void MacroConditionGameCapture::SetupSignalHandler(obs_source_t *source) _unhookSignal = OBSSignal(sh, "unhooked", UnhookedSignalReceived, this); _lastSource = source; + _activeKeeper.SetActive(_keepActive); + _activeKeeper.SetSource(source); + SetupInitialState(source); } @@ -164,17 +171,33 @@ MacroConditionGameCaptureEdit::MacroConditionGameCaptureEdit( QWidget *parent, std::shared_ptr entryData) : QWidget(parent), _sources(new SourceSelectionWidget(this, getGameCaptureSourcesList, - true)) + true)), + _keepActive(new QCheckBox( + obs_module_text("AdvSceneSwitcher.keepSourceActive"), this)), + _keepActiveHelp(new HelpIcon( + obs_module_text("AdvSceneSwitcher.keepSourceActive.help"), + this)) { QWidget::connect(_sources, SIGNAL(SourceChanged(const SourceSelection &)), this, SLOT(SourceChanged(const SourceSelection &))); + QWidget::connect(_keepActive, SIGNAL(stateChanged(int)), this, + SLOT(KeepActiveChanged(int))); - auto layout = new QHBoxLayout; + auto entryLayout = new QHBoxLayout; PlaceWidgets( obs_module_text("AdvSceneSwitcher.condition.gameCapture.entry"), - layout, {{"{{sources}}", _sources}}); - setLayout(layout); + entryLayout, {{"{{sources}}", _sources}}); + + auto keepActiveLayout = new QHBoxLayout; + keepActiveLayout->addWidget(_keepActive); + keepActiveLayout->addWidget(_keepActiveHelp); + keepActiveLayout->addStretch(); + + auto mainLayout = new QVBoxLayout; + mainLayout->addLayout(entryLayout); + mainLayout->addLayout(keepActiveLayout); + setLayout(mainLayout); _entryData = entryData; UpdateEntryData(); @@ -187,9 +210,16 @@ void MacroConditionGameCaptureEdit::SourceChanged(const SourceSelection &source) _entryData->_source = source; } +void MacroConditionGameCaptureEdit::KeepActiveChanged(int state) +{ + GUARD_LOADING_AND_LOCK(); + _entryData->_keepActive = state; +} + void MacroConditionGameCaptureEdit::UpdateEntryData() { _sources->SetSource(_entryData->_source); + _keepActive->setChecked(_entryData->_keepActive); } } // namespace advss diff --git a/plugins/base/macro-condition-game-capture.hpp b/plugins/base/macro-condition-game-capture.hpp index f78076ae..9e2b5a54 100644 --- a/plugins/base/macro-condition-game-capture.hpp +++ b/plugins/base/macro-condition-game-capture.hpp @@ -1,9 +1,12 @@ #pragma once +#include "help-icon.hpp" #include "macro-condition-edit.hpp" +#include "source-helpers.hpp" #include "source-selection.hpp" #include #include +#include namespace advss { @@ -20,6 +23,7 @@ public: } SourceSelection _source; + bool _keepActive = false; private: static void HookedSignalReceived(void *data, calldata_t *); @@ -31,6 +35,7 @@ private: void GetCalldataInfo(calldata_t *cd); obs_source_t *_lastSource = nullptr; + SourceActiveKeeper _activeKeeper; OBSSignal _hookSignal; OBSSignal _unhookSignal; @@ -63,9 +68,12 @@ public: private slots: void SourceChanged(const SourceSelection &); + void KeepActiveChanged(int); private: SourceSelectionWidget *_sources; + QCheckBox *_keepActive; + HelpIcon *_keepActiveHelp; std::shared_ptr _entryData; bool _loading = true;