Repository: hyprwm/Hyprland
File: src/desktop/rule/windowRule/WindowRule.cpp (C++)

Code before:
                break;
            case RULE_PROP_CONTENT:
                if (!engine->match(w->getContentType()))
                    return false;
                break;
            case RULE_PROP_XDG_TAG:
                if (!w->xdgTag().has_value() || !engine->match(*w->xdgTag()))
                    return false;
                break;

            case RULE_PROP_EXEC_TOKEN:
                // this is only allowed on static rules, we don't need it on dynamic plus it's expensive
                if (!allowEnvLookup)
                    break;
                {
                    const auto ENV = w->getEnv();
                    if (ENV.contains(EXEC_RULE_ENV_NAME)) {
                        const auto TKN = ENV.at(EXEC_RULE_ENV_NAME);
                        if (!engine->match(TKN))
                            return false;
                        break;
                    }
                }
                break;
            case RULE_PROP_EXEC_PID:
                if (!engine->match(w->getPID()))
                    return false;
                break;
        }
    }

    return true;
}

SP<CWindowRule> CWindowRule::buildFromExecString(std::string&& s) {
    CVarList2       varlist(std::move(s), 0, ';');
    SP<CWindowRule> wr = makeShared<CWindowRule>("__exec_rule");

    for (const auto& el : varlist) {
        // split element by space, can't do better
        size_t spacePos = el.find(' ');
        if (spacePos != std::string::npos) {
            // great, split and try to parse
            auto       LHS    = el.substr(0, spacePos);
            const auto EFFECT = windowEffects()->get(LHS);

            if (!EFFECT.has_value() || *EFFECT == WINDOW_RULE_EFFECT_NONE)
                continue; // invalid...

            wr->addEffect(*EFFECT, std::string{el.substr(spacePos + 1)});
            continue;

Review comment (suggestion):
```suggestion
                if (allowEnvLookup && w->getEnv().empty() && !engine->match(w->getPID()))
```
that should do it

Code after:
                break;
            case RULE_PROP_CONTENT:
                if (!engine->match(w->getContentType()))
                    return false;
                break;
            case RULE_PROP_XDG_TAG:
                if (!w->xdgTag().has_value() || !engine->match(*w->xdgTag()))
                    return false;
                break;

            case RULE_PROP_EXEC_TOKEN:
                if (!allowEnvLookup)
                    break;

                const auto ENV   = w->getEnv();
                bool       match = false;

                if (ENV.contains(EXEC_RULE_ENV_NAME)) {
                    if (engine->match(ENV.at(EXEC_RULE_ENV_NAME)))
                        match = true;
                } else if (m_matchEngines.contains(RULE_PROP_EXEC_PID)) {
                    if (m_matchEngines.at(RULE_PROP_EXEC_PID)->match(w->getPID()))
                        match = true;
                }
                if (!match)
                    return false;
                break;
        }
    }

    return true;
}

SP<CWindowRule> CWindowRule::buildFromExecString(std::string&& s) {
    CVarList2       varlist(std::move(s), 0, ';');
    SP<CWindowRule> wr = makeShared<CWindowRule>("__exec_rule");

    for (const auto& el : varlist) {
        // split element by space, can't do better
        size_t spacePos = el.find(' ');
        if (spacePos != std::string::npos) {
            // great, split and try to parse
            auto       LHS    = el.substr(0, spacePos);
            const auto EFFECT = windowEffects()->get(LHS);

            if (!EFFECT.has_value() || *EFFECT == WINDOW_RULE_EFFECT_NONE)
                continue; // invalid...

            wr->addEffect(*EFFECT, std::string{el.substr(spacePos + 1)});
            continue;
        }