mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-06-21 03:52:07 -05:00
Fix window condition ignoring title matching if regex is disabled
If the only enabled option was window title matching and regular expressions were not used any window title would match regardless if it existed or not
This commit is contained in:
parent
abc3357180
commit
b1a3ab5493
|
|
@ -40,7 +40,8 @@ static bool windowContainsText(const std::string &window,
|
|||
return text == matchText;
|
||||
}
|
||||
|
||||
bool MacroConditionWindow::WindowMatches(const std::string &window)
|
||||
bool MacroConditionWindow::WindowMatchesRequirements(
|
||||
const std::string &window) const
|
||||
{
|
||||
const bool focusCheckOK = (!_focus || window == switcher->currentTitle);
|
||||
if (!focusCheckOK) {
|
||||
|
|
@ -60,26 +61,52 @@ bool MacroConditionWindow::WindowMatches(const std::string &window)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (_checkText) {
|
||||
auto text = GetTextInWindow(window);
|
||||
SetVariableValue(text.value_or(""));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MacroConditionWindow::WindowMatches(
|
||||
const std::vector<std::string> &windowList)
|
||||
{
|
||||
bool match = !_checkTitle ||
|
||||
std::find(windowList.begin(), windowList.end(),
|
||||
std::string(_window)) != windowList.end();
|
||||
match = match && WindowMatchesRequirements(_window);
|
||||
SetVariableValueBasedOnMatch(_window);
|
||||
return match;
|
||||
}
|
||||
|
||||
bool MacroConditionWindow::WindowRegexMatches(
|
||||
const std::vector<std::string> &windowList)
|
||||
{
|
||||
// No need to test if checking for window title is required as if the
|
||||
// user has disabled window title matching the option will always be
|
||||
// enabled in the backend and use the regular expression ".*".
|
||||
|
||||
for (const auto &window : windowList) {
|
||||
if (matchRegex(_windowRegex, window, _window) &&
|
||||
WindowMatches(window)) {
|
||||
WindowMatchesRequirements(window)) {
|
||||
SetVariableValueBasedOnMatch(window);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
SetVariableValueBasedOnMatch("");
|
||||
return false;
|
||||
}
|
||||
|
||||
void MacroConditionWindow::SetVariableValueBasedOnMatch(
|
||||
const std::string &matchWindow)
|
||||
{
|
||||
if (!IsReferencedInVars()) {
|
||||
return;
|
||||
}
|
||||
if (_checkText) {
|
||||
auto text = GetTextInWindow(matchWindow);
|
||||
SetVariableValue(text.value_or(""));
|
||||
} else {
|
||||
SetVariableValue(switcher->currentTitle);
|
||||
}
|
||||
}
|
||||
|
||||
static bool foregroundWindowChanged()
|
||||
{
|
||||
return switcher->currentTitle != switcher->lastTitle;
|
||||
|
|
@ -87,19 +114,13 @@ static bool foregroundWindowChanged()
|
|||
|
||||
bool MacroConditionWindow::CheckCondition()
|
||||
{
|
||||
SetVariableValue("");
|
||||
if (!_checkText) {
|
||||
SetVariableValue(switcher->currentTitle);
|
||||
}
|
||||
|
||||
std::vector<std::string> windowList;
|
||||
GetWindowList(windowList);
|
||||
|
||||
bool match = false;
|
||||
if (_windowRegex.Enabled()) {
|
||||
match = WindowRegexMatches(windowList);
|
||||
} else {
|
||||
match = WindowMatches(_window);
|
||||
match = WindowMatches(windowList);
|
||||
}
|
||||
match = match && (!_windowFocusChanged || foregroundWindowChanged());
|
||||
return match;
|
||||
|
|
|
|||
|
|
@ -21,10 +21,6 @@ public:
|
|||
return std::make_shared<MacroConditionWindow>(m);
|
||||
}
|
||||
|
||||
private:
|
||||
bool WindowMatches(const std::string &window);
|
||||
bool WindowRegexMatches(const std::vector<std::string> &windowList);
|
||||
|
||||
public:
|
||||
StringVariable _window;
|
||||
RegexConfig _windowRegex;
|
||||
|
|
@ -40,6 +36,11 @@ public:
|
|||
RegexConfig _textRegex = RegexConfig::PartialMatchRegexConfig();
|
||||
|
||||
private:
|
||||
bool WindowMatchesRequirements(const std::string &window) const;
|
||||
bool WindowMatches(const std::vector<std::string> &windowList);
|
||||
bool WindowRegexMatches(const std::vector<std::string> &windowList);
|
||||
void SetVariableValueBasedOnMatch(const std::string &matchWindow);
|
||||
|
||||
static bool _registered;
|
||||
static const std::string id;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user