desktop/windowRule: fix matching CONTENT (#13636)

ref #13596
This commit is contained in:
Vaxry 2026-03-07 19:53:34 +00:00 committed by GitHub
parent 3cf62bea18
commit a4ecae9160
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 30 additions and 2 deletions

View file

@ -658,6 +658,33 @@ static bool testWindowRuleWorkspaceEmpty() {
return true;
}
static void testContentRules() {
NLog::log("{}Testing content window rules", Colors::YELLOW);
// kill me PLEASE
OK(getFromSocket("/keyword windowrule match:class kitty_bitch, content game"));
OK(getFromSocket("/keyword windowrule match:content game, border_size 10"));
OK(getFromSocket("/keyword windowrule match:content 3, opacity 0.5"));
getFromSocket("/dispatch workspace 420");
if (!spawnKitty("kitty_bitch")) {
NLog::log("{}Error: failed to spawn kitty", Colors::RED);
return;
}
{
auto res = getFromSocket("/getprop active border_size");
EXPECT_CONTAINS(res, "10");
}
{
auto res = getFromSocket("/getprop active opacity");
EXPECT_CONTAINS(res, "0.5");
}
}
static bool test() {
NLog::log("{}Testing windows", Colors::GREEN);
@ -1122,6 +1149,7 @@ static bool test() {
testWindowRuleFocusOnActivate();
testPinnedWorkspacesValid();
testWindowRuleWorkspaceEmpty();
testContentRules();
NLog::log("{}Reloading config", Colors::YELLOW);
OK(getFromSocket("/reload"));

View file

@ -48,7 +48,7 @@ static const std::unordered_map<eRuleProperty, eRuleMatchEngine> RULE_ENGINES =
{RULE_PROP_FULLSCREENSTATE_INTERNAL, RULE_MATCH_ENGINE_INT}, //
{RULE_PROP_FULLSCREENSTATE_CLIENT, RULE_MATCH_ENGINE_INT}, //
{RULE_PROP_ON_WORKSPACE, RULE_MATCH_ENGINE_WORKSPACE}, //
{RULE_PROP_CONTENT, RULE_MATCH_ENGINE_INT}, //
{RULE_PROP_CONTENT, RULE_MATCH_ENGINE_REGEX}, //
{RULE_PROP_XDG_TAG, RULE_MATCH_ENGINE_REGEX}, //
{RULE_PROP_NAMESPACE, RULE_MATCH_ENGINE_REGEX}, //
{RULE_PROP_EXEC_TOKEN, RULE_MATCH_ENGINE_REGEX}, //

View file

@ -97,7 +97,7 @@ bool CWindowRule::matches(PHLWINDOW w, bool allowEnvLookup) {
return false;
break;
case RULE_PROP_CONTENT:
if (!engine->match(w->getContentType()) && !engine->match(NContentType::toString(w->getContentType())))
if (!engine->match(std::format("{}", sc<size_t>(w->getContentType()))) && !engine->match(NContentType::toString(w->getContentType())))
return false;
break;
case RULE_PROP_XDG_TAG: