From b1fa8651e463b0095d2acafeaf546cb62cce4ae3 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Fri, 30 Oct 2026 12:12:04 -0700 Subject: [PATCH] fix(rules): keep a rule whose id another kind of rule already has --- komorebi/src/process_command.rs | 72 ++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index 436ef927..6fc5a07c 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -1627,22 +1627,7 @@ impl WindowManager { SocketMessage::IgnoreRule(identifier, ref id) => { let mut ignore_identifiers = IGNORE_IDENTIFIERS.lock(); - let mut should_push = true; - for i in &*ignore_identifiers { - if let MatchingRule::Simple(i) = i - && i.id.eq(id) - { - should_push = false; - } - } - - if should_push { - ignore_identifiers.push(MatchingRule::Simple(IdWithIdentifier { - kind: identifier, - id: id.clone(), - matching_strategy: Option::from(MatchingStrategy::Legacy), - })); - } + push_simple_rule(&mut ignore_identifiers, identifier, id); let offset = self.work_area_offset; @@ -1697,22 +1682,7 @@ impl WindowManager { SocketMessage::ManageRule(identifier, ref id) => { let mut manage_identifiers = MANAGE_IDENTIFIERS.lock(); - let mut should_push = true; - for m in &*manage_identifiers { - if let MatchingRule::Simple(m) = m - && m.id.eq(id) - { - should_push = false; - } - } - - if should_push { - manage_identifiers.push(MatchingRule::Simple(IdWithIdentifier { - kind: identifier, - id: id.clone(), - matching_strategy: Option::from(MatchingStrategy::Legacy), - })); - } + push_simple_rule(&mut manage_identifiers, identifier, id); } SocketMessage::ContainerPadding(monitor_idx, workspace_idx, size) => { self.set_container_padding(monitor_idx, workspace_idx, size)?; @@ -2159,6 +2129,22 @@ pub fn read_commands_uds( Ok(()) } +/// Add a simple socket-created rule unless one with the same kind and id is already present; +/// a rule of another kind with the same id is a different rule +fn push_simple_rule(rules: &mut Vec, kind: ApplicationIdentifier, id: &str) { + let exists = rules + .iter() + .any(|r| matches!(r, MatchingRule::Simple(r) if r.kind == kind && r.id.eq(id))); + + if !exists { + rules.push(MatchingRule::Simple(IdWithIdentifier { + kind, + id: id.to_string(), + matching_strategy: Option::from(MatchingStrategy::Legacy), + })); + } +} + #[cfg(test)] mod tests { use super::*; @@ -2451,4 +2437,26 @@ mod tests { std::fs::remove_file(socket_path).unwrap(); } + + #[test] + fn push_simple_rule_keeps_rules_of_another_kind_with_the_same_id() { + let mut rules = vec![]; + + push_simple_rule(&mut rules, ApplicationIdentifier::Class, "foo"); + push_simple_rule(&mut rules, ApplicationIdentifier::Exe, "foo"); + assert_eq!(rules.len(), 2); + + push_simple_rule(&mut rules, ApplicationIdentifier::Exe, "foo"); + push_simple_rule(&mut rules, ApplicationIdentifier::Class, "foo"); + assert_eq!(rules.len(), 2); + + rules.clear(); + rules.push(MatchingRule::Composite(vec![IdWithIdentifier { + kind: ApplicationIdentifier::Exe, + id: "foo".to_string(), + matching_strategy: None, + }])); + push_simple_rule(&mut rules, ApplicationIdentifier::Exe, "foo"); + assert_eq!(rules.len(), 2); + } }