windowrules: add negative: prefix for negating a regex

fixes #8799
This commit is contained in:
Vaxry
2024-12-21 23:07:23 +00:00
parent 57921d7dbd
commit 31422ae25d
5 changed files with 61 additions and 34 deletions

16
src/desktop/Rule.cpp Normal file
View File

@@ -0,0 +1,16 @@
#include "Rule.hpp"
#include <re2/re2.h>
CRuleRegexContainer::CRuleRegexContainer(const std::string& regex_) {
const bool NEGATIVE = regex_.starts_with("negative:");
negative = NEGATIVE;
regex = std::make_unique<RE2>(NEGATIVE ? regex_.substr(9) : regex_);
}
bool CRuleRegexContainer::passes(const std::string& str) const {
if (!regex)
return false;
return RE2::FullMatch(str, *regex) != negative;
}