Add option to keep selected game capture sources active

This commit is contained in:
WarmUpTill
2026-05-03 13:38:26 +02:00
committed by WarmUpTill
parent d523a2e674
commit 18aaf1dd31
3 changed files with 46 additions and 4 deletions

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;