mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-16 13:51:19 +01:00
fix(rules): keep a rule whose id another kind of rule already has
This commit is contained in:
1 parent
bbe002be54
commit
b1fa8651e4
1 file changed
+40
-32
@@ -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<MatchingRule>, 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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user