Add temp var for window text

This commit is contained in:
WarmUpTill 2025-12-28 20:31:46 +01:00 committed by WarmUpTill
parent bad1a548fb
commit faf52c38bb
3 changed files with 45 additions and 7 deletions

View File

@ -2149,6 +2149,8 @@ AdvSceneSwitcher.tempVar.window.window="Window title"
AdvSceneSwitcher.tempVar.window.window.description="The window title of the matching window."
AdvSceneSwitcher.tempVar.window.windowClass="Window class"
AdvSceneSwitcher.tempVar.window.windowClass.description="The window class of the matching window."
AdvSceneSwitcher.tempVar.window.windowText="Window text"
AdvSceneSwitcher.tempVar.window.windowText.description="Text contained within the window (won't work on all window types)."
AdvSceneSwitcher.tempVar.timer.seconds="Seconds"
AdvSceneSwitcher.tempVar.timer.minutes="Minutes"

View File

@ -29,6 +29,22 @@ static bool windowContainsText(const std::string &window,
return text == matchText;
}
void MacroConditionWindow::SetCheckText(bool value)
{
#ifdef _WIN32
_checkText = value;
#else
(void)value;
_checkText = false;
#endif
SetupTempVars();
}
bool MacroConditionWindow::GetCheckText()
{
return _checkText;
}
bool MacroConditionWindow::WindowMatchesRequirements(
const std::string &window) const
{
@ -94,12 +110,18 @@ void MacroConditionWindow::SetVariableValueBasedOnMatch(
#ifdef _WIN32
SetTempVarValue("windowClass",
GetWindowClassByWindowTitle(matchWindow));
if (_checkText) {
const auto text = GetTextInWindow(matchWindow);
if (text) {
SetTempVarValue("windowText", *text);
}
}
#endif
if (!IsReferencedInVars()) {
return;
}
if (_checkText) {
auto text = GetTextInWindow(matchWindow);
const auto text = GetTextInWindow(matchWindow);
SetVariableValue(text.value_or(""));
} else {
SetVariableValue(ForegroundWindowTitle());
@ -186,6 +208,16 @@ void MacroConditionWindow::SetupTempVars()
obs_module_text("AdvSceneSwitcher.tempVar.window.windowClass"),
obs_module_text(
"AdvSceneSwitcher.tempVar.window.windowClass.description"));
if (!_checkText) {
return;
}
AddTempvar(
"windowText",
obs_module_text("AdvSceneSwitcher.tempVar.window.windowText"),
obs_module_text(
"AdvSceneSwitcher.tempVar.window.windowText.description"));
#endif
}
@ -349,7 +381,7 @@ void MacroConditionWindowEdit::CheckTitleChanged(int state)
void MacroConditionWindowEdit::CheckTextChanged(int state)
{
GUARD_LOADING_AND_LOCK();
_entryData->_checkText = state;
_entryData->SetCheckText(state);
SetWidgetVisibility();
}
@ -409,8 +441,8 @@ void MacroConditionWindowEdit::SetWidgetVisibility()
_entryData->_focus || _entryData->_windowFocusChanged);
_windowSelection->setVisible(_entryData->_checkTitle);
_windowRegex->setVisible(_entryData->_checkTitle);
_textRegex->setVisible(_entryData->_checkText);
_text->setVisible(_entryData->_checkText);
_textRegex->setVisible(_entryData->GetCheckText());
_text->setVisible(_entryData->GetCheckText());
adjustSize();
updateGeometry();
}
@ -429,7 +461,7 @@ void MacroConditionWindowEdit::UpdateEntryData()
_maximized->setChecked(_entryData->_maximized);
_focused->setChecked(_entryData->_focus);
_windowFocusChanged->setChecked(_entryData->_windowFocusChanged);
_checkText->setChecked(_entryData->_checkText);
_checkText->setChecked(_entryData->GetCheckText());
_text->setPlainText(_entryData->_text);
_textRegex->SetRegexConfig(_entryData->_textRegex);
SetWidgetVisibility();

View File

@ -22,6 +22,9 @@ public:
return std::make_shared<MacroConditionWindow>(m);
}
void SetCheckText(bool value);
bool GetCheckText();
StringVariable _window;
RegexConfig _windowRegex;
bool _checkTitle = true;
@ -30,8 +33,6 @@ public:
bool _focus = true;
bool _windowFocusChanged = false;
// For now only supported on Windows
bool _checkText = false;
StringVariable _text;
RegexConfig _textRegex = RegexConfig::PartialMatchRegexConfig();
@ -42,6 +43,9 @@ private:
void SetVariableValueBasedOnMatch(const std::string &matchWindow);
void SetupTempVars();
// For now only supported on Windows
bool _checkText = false;
static bool _registered;
static const std::string id;
};