1
0
Fork 0
forked from wry/wry

config: allow matching on client tag

This commit is contained in:
Julian Orth 2026-02-27 20:53:09 +01:00
parent 596909cd25
commit 8b19315f50
13 changed files with 76 additions and 8 deletions

View file

@ -2107,6 +2107,7 @@ impl ConfigProxyHandler {
}
ClientCriterionStringField::Comm => mgr.comm(needle),
ClientCriterionStringField::Exe => mgr.exe(needle),
ClientCriterionStringField::Tag => mgr.tag(needle),
}
}
ClientCriterionIpc::Sandboxed => mgr.sandboxed(),

View file

@ -12,7 +12,7 @@ use {
clmm_sandboxed::ClmMatchSandboxed,
clmm_string::{
ClmMatchComm, ClmMatchExe, ClmMatchSandboxAppId, ClmMatchSandboxEngine,
ClmMatchSandboxInstanceId,
ClmMatchSandboxInstanceId, ClmMatchTag,
},
clmm_uid::ClmMatchUid,
},
@ -61,6 +61,7 @@ pub struct RootMatchers {
pid: ClmRootMatcherMap<ClmMatchPid>,
comm: ClmRootMatcherMap<ClmMatchComm>,
exe: ClmRootMatcherMap<ClmMatchExe>,
tag: ClmRootMatcherMap<ClmMatchTag>,
}
impl RootMatchers {
@ -72,6 +73,7 @@ impl RootMatchers {
self.pid.clear();
self.comm.clear();
self.exe.clear();
self.tag.clear();
}
}
@ -181,6 +183,7 @@ impl ClMatcherManager {
unconditional!(pid);
unconditional!(comm);
unconditional!(exe);
unconditional!(tag);
fixed!(sandboxed);
fixed!(is_xwayland);
self.constant[true].handle(data);
@ -222,6 +225,10 @@ impl ClMatcherManager {
pub fn exe(&self, string: CritLiteralOrRegex) -> Rc<ClmUpstreamNode> {
self.root(ClmMatchExe::new(string))
}
pub fn tag(&self, string: CritLiteralOrRegex) -> Rc<ClmUpstreamNode> {
self.root(ClmMatchTag::new(string))
}
}
impl CritTarget for Rc<Client> {

View file

@ -15,6 +15,7 @@ pub type ClmMatchString<T> = CritMatchString<Rc<Client>, T>;
pub type ClmMatchSandboxEngine = ClmMatchString<AcceptorMetadataAccess<SandboxEngineField>>;
pub type ClmMatchSandboxAppId = ClmMatchString<AcceptorMetadataAccess<SandboxAppIdField>>;
pub type ClmMatchSandboxInstanceId = ClmMatchString<AcceptorMetadataAccess<SandboxInstanceIdField>>;
pub type ClmMatchTag = ClmMatchString<AcceptorMetadataAccess<TagField>>;
pub type ClmMatchComm = ClmMatchString<CommAccess>;
pub type ClmMatchExe = ClmMatchString<ExeAccess>;
@ -22,7 +23,7 @@ pub struct AcceptorMetadataAccess<T>(PhantomData<T>);
pub struct CommAccess;
pub struct ExeAccess;
trait SandboxField: Sized + 'static {
trait AcceptorMetadataField: Sized + 'static {
fn field(meta: &AcceptorMetadata) -> &Option<String>;
fn nodes(
roots: &RootMatchers,
@ -32,10 +33,11 @@ trait SandboxField: Sized + 'static {
pub struct SandboxEngineField;
pub struct SandboxAppIdField;
pub struct SandboxInstanceIdField;
pub struct TagField;
impl<T> StringAccess<Rc<Client>> for AcceptorMetadataAccess<T>
where
T: SandboxField,
T: AcceptorMetadataField,
{
fn with_string(data: &Rc<Client>, f: impl FnOnce(&str) -> bool) -> bool {
f(T::field(&data.acceptor).as_deref().unwrap_or_default())
@ -46,7 +48,7 @@ where
}
}
impl SandboxField for SandboxEngineField {
impl AcceptorMetadataField for SandboxEngineField {
fn field(meta: &AcceptorMetadata) -> &Option<String> {
&meta.sandbox_engine
}
@ -58,7 +60,7 @@ impl SandboxField for SandboxEngineField {
}
}
impl SandboxField for SandboxAppIdField {
impl AcceptorMetadataField for SandboxAppIdField {
fn field(meta: &AcceptorMetadata) -> &Option<String> {
&meta.app_id
}
@ -70,7 +72,7 @@ impl SandboxField for SandboxAppIdField {
}
}
impl SandboxField for SandboxInstanceIdField {
impl AcceptorMetadataField for SandboxInstanceIdField {
fn field(meta: &AcceptorMetadata) -> &Option<String> {
&meta.instance_id
}
@ -82,6 +84,18 @@ impl SandboxField for SandboxInstanceIdField {
}
}
impl AcceptorMetadataField for TagField {
fn field(meta: &AcceptorMetadata) -> &Option<String> {
&meta.tag
}
fn nodes(
roots: &RootMatchers,
) -> &ClmRootMatcherMap<ClmMatchString<AcceptorMetadataAccess<Self>>> {
&roots.tag
}
}
impl StringAccess<Rc<Client>> for CommAccess {
fn with_string(data: &Rc<Client>, f: impl FnOnce(&str) -> bool) -> bool {
f(&data.pid_info.comm)