desktop/rules: use pid for exec rules (#13374)

This commit is contained in:
ItsOhen 2026-02-26 19:13:49 +01:00 committed by GitHub
parent cc14dd1baf
commit 70cdd819e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 39 additions and 28 deletions

View file

@ -915,11 +915,13 @@ bool CKeybindManager::handleInternalKeybinds(xkb_keysym_t keysym) {
// Dispatchers
SDispatchResult CKeybindManager::spawn(std::string args) {
const uint64_t PROC = spawnWithRules(args, nullptr);
return {.success = PROC > 0, .error = std::format("Failed to start process {}", args)};
const auto PROC = spawnWithRules(args, nullptr);
if (!PROC.has_value())
return {.success = false, .error = std::format("Failed to start process. No closing bracket in exec rule. {}", args)};
return {.success = PROC.value() > 0, .error = std::format("Failed to start process {}", args)};
}
uint64_t CKeybindManager::spawnWithRules(std::string args, PHLWORKSPACE pInitialWorkspace) {
std::optional<uint64_t> CKeybindManager::spawnWithRules(std::string args, PHLWORKSPACE pInitialWorkspace) {
args = trim(args);
@ -927,22 +929,29 @@ uint64_t CKeybindManager::spawnWithRules(std::string args, PHLWORKSPACE pInitial
if (args[0] == '[') {
// we have exec rules
RULES = args.substr(1, args.substr(1).find_first_of(']'));
args = args.substr(args.find_first_of(']') + 1);
const auto end = args.find_first_of(']');
if (end == std::string::npos)
return std::nullopt;
RULES = args.substr(1, end - 1);
args = args.substr(end + 1);
}
std::string execToken = "";
if (!RULES.empty()) {
auto rule = Desktop::Rule::CWindowRule::buildFromExecString(std::move(RULES));
auto rule = Desktop::Rule::CWindowRule::buildFromExecString(std::move(RULES));
execToken = rule->execToken();
const auto TOKEN = g_pTokenManager->registerNewToken(nullptr, std::chrono::seconds(1));
const uint64_t PROC = spawnRawProc(args, pInitialWorkspace, TOKEN);
rule->markAsExecRule(TOKEN, PROC, false /* TODO: could be nice. */);
rule->registerMatch(Desktop::Rule::RULE_PROP_EXEC_TOKEN, TOKEN);
rule->registerMatch(Desktop::Rule::RULE_PROP_EXEC_PID, std::to_string(PROC));
Desktop::Rule::ruleEngine()->registerRule(std::move(rule));
Log::logger->log(Log::DEBUG, "Applied rule arguments for exec.");
return PROC;
}
const uint64_t PROC = spawnRawProc(args, pInitialWorkspace, execToken);
return PROC;

View file

@ -166,7 +166,7 @@ class CKeybindManager {
static void switchToWindow(PHLWINDOW PWINDOWTOCHANGETO, bool forceFSCycle = false);
static uint64_t spawnRawProc(std::string, PHLWORKSPACE pInitialWorkspace, const std::string& execRuleToken = "");
static uint64_t spawnWithRules(std::string, PHLWORKSPACE pInitialWorkspace);
static std::optional<uint64_t> spawnWithRules(std::string, PHLWORKSPACE pInitialWorkspace);
// -------------- Dispatchers -------------- //
static SDispatchResult closeActive(std::string);