From c75b6ef66e16359e4ad6e98a97f199796458d6f5 Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Sat, 7 Mar 2026 11:47:57 +0100 Subject: [PATCH] clm: allow matching clients by id --- src/criteria/clm.rs | 9 +++++++++ src/criteria/clm/clm_matchers.rs | 1 + src/criteria/clm/clm_matchers/clmm_id.rs | 19 +++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 src/criteria/clm/clm_matchers/clmm_id.rs diff --git a/src/criteria/clm.rs b/src/criteria/clm.rs index be88c270..f9e1c595 100644 --- a/src/criteria/clm.rs +++ b/src/criteria/clm.rs @@ -7,6 +7,7 @@ use { CritDestroyListener, CritLiteralOrRegex, CritMatcherId, CritMatcherIds, CritMgrExt, CritUpstreamNode, FixedRootMatcher, RootMatcherMap, clm::clm_matchers::{ + clmm_id::ClmMatchId, clmm_is_xwayland::ClmMatchIsXwayland, clmm_pid::ClmMatchPid, clmm_sandboxed::ClmMatchSandboxed, @@ -62,6 +63,7 @@ pub struct RootMatchers { comm: ClmRootMatcherMap, exe: ClmRootMatcherMap, tag: ClmRootMatcherMap, + id: ClmRootMatcherMap, } impl RootMatchers { @@ -74,6 +76,7 @@ impl RootMatchers { self.comm.clear(); self.exe.clear(); self.tag.clear(); + self.id.clear(); } } @@ -184,6 +187,7 @@ impl ClMatcherManager { unconditional!(comm); unconditional!(exe); unconditional!(tag); + unconditional!(id); fixed!(sandboxed); fixed!(is_xwayland); self.constant[true].handle(data); @@ -229,6 +233,11 @@ impl ClMatcherManager { pub fn tag(&self, string: CritLiteralOrRegex) -> Rc { self.root(ClmMatchTag::new(string)) } + + #[expect(dead_code)] + pub fn id(&self, id: ClientId) -> Rc { + self.root(ClmMatchId(id)) + } } impl CritTarget for Rc { diff --git a/src/criteria/clm/clm_matchers.rs b/src/criteria/clm/clm_matchers.rs index bd661aa4..f39837fc 100644 --- a/src/criteria/clm/clm_matchers.rs +++ b/src/criteria/clm/clm_matchers.rs @@ -17,6 +17,7 @@ macro_rules! fixed_root_criterion { }; } +pub mod clmm_id; pub mod clmm_is_xwayland; pub mod clmm_pid; pub mod clmm_sandboxed; diff --git a/src/criteria/clm/clm_matchers/clmm_id.rs b/src/criteria/clm/clm_matchers/clmm_id.rs new file mode 100644 index 00000000..1cb347af --- /dev/null +++ b/src/criteria/clm/clm_matchers/clmm_id.rs @@ -0,0 +1,19 @@ +use { + crate::{ + client::{Client, ClientId}, + criteria::{RootMatcherMap, clm::RootMatchers, crit_graph::CritRootCriterion}, + }, + std::rc::Rc, +}; + +pub struct ClmMatchId(pub ClientId); + +impl CritRootCriterion> for ClmMatchId { + fn matches(&self, data: &Rc) -> bool { + data.id == self.0 + } + + fn nodes(roots: &RootMatchers) -> Option<&RootMatcherMap, Self>> { + Some(&roots.id) + } +}