Add option to keep selected game capture sources active

This commit is contained in:
WarmUpTill 2026-05-03 13:38:26 +02:00
parent c7140f7c9f
commit 145e5d3fff
3 changed files with 46 additions and 4 deletions

View File

@ -856,6 +856,7 @@ AdvSceneSwitcher.condition.streamDeck.stopListen="Stop listening"
AdvSceneSwitcher.condition.streamDeck.pluginDownload="<html><head/><body><p>The Stream Deck plugin can be found <a href=\"https://github.com/WarmUpTill/advanced-scene-switcher-streamdeck-plugin/releases\"><span style=\" text-decoration: underline; color:#268bd2;\">here on GitHub</span></a>.</p></body></html>"
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)"

View File

@ -24,6 +24,8 @@ bool MacroConditionGameCapture::CheckCondition()
return false;
}
_activeKeeper.SetActive(_keepActive);
std::lock_guard<std::mutex> 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<MacroConditionGameCapture> 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

View File

@ -1,9 +1,12 @@
#pragma once
#include "help-icon.hpp"
#include "macro-condition-edit.hpp"
#include "source-helpers.hpp"
#include "source-selection.hpp"
#include <QWidget>
#include <QComboBox>
#include <QCheckBox>
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<MacroConditionGameCapture> _entryData;
bool _loading = true;