From faf52c38bb6a2ad23e3ae6058f8bad7d277d8c26 Mon Sep 17 00:00:00 2001 From: WarmUpTill <19472752+WarmUpTill@users.noreply.github.com> Date: Sun, 28 Dec 2025 20:31:46 +0100 Subject: [PATCH] Add temp var for window text --- data/locale/en-US.ini | 2 ++ plugins/base/macro-condition-window.cpp | 42 ++++++++++++++++++++++--- plugins/base/macro-condition-window.hpp | 8 +++-- 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/data/locale/en-US.ini b/data/locale/en-US.ini index 7b6470c0..b0bf8770 100644 --- a/data/locale/en-US.ini +++ b/data/locale/en-US.ini @@ -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" diff --git a/plugins/base/macro-condition-window.cpp b/plugins/base/macro-condition-window.cpp index 1fe7a124..6e65e920 100644 --- a/plugins/base/macro-condition-window.cpp +++ b/plugins/base/macro-condition-window.cpp @@ -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(); diff --git a/plugins/base/macro-condition-window.hpp b/plugins/base/macro-condition-window.hpp index 704e3695..6eba3632 100644 --- a/plugins/base/macro-condition-window.hpp +++ b/plugins/base/macro-condition-window.hpp @@ -22,6 +22,9 @@ public: return std::make_shared(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; };