config: add client window criteria
This commit is contained in:
parent
59f8acdfde
commit
2b5be7fbd9
19 changed files with 205 additions and 14 deletions
|
|
@ -254,6 +254,7 @@ pub struct WindowRule {
|
|||
pub struct WindowMatch {
|
||||
pub generic: GenericMatch<Self>,
|
||||
pub types: Option<WindowType>,
|
||||
pub client: Option<ClientMatch>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
|
|||
|
|
@ -5,7 +5,10 @@ use {
|
|||
context::Context,
|
||||
extractor::{Extractor, ExtractorError, arr, n32, opt, str, val},
|
||||
parser::{DataType, ParseResult, Parser, UnexpectedDataType},
|
||||
parsers::window_type::{WindowTypeParser, WindowTypeParserError},
|
||||
parsers::{
|
||||
client_match::{ClientMatchParser, ClientMatchParserError},
|
||||
window_type::{WindowTypeParser, WindowTypeParserError},
|
||||
},
|
||||
},
|
||||
toml::{
|
||||
toml_span::{DespanExt, Span, Spanned},
|
||||
|
|
@ -24,6 +27,8 @@ pub enum WindowMatchParserError {
|
|||
Extract(#[from] ExtractorError),
|
||||
#[error(transparent)]
|
||||
WindowTypes(#[from] WindowTypeParserError),
|
||||
#[error(transparent)]
|
||||
ClientMatchParserError(#[from] ClientMatchParserError),
|
||||
}
|
||||
|
||||
pub struct WindowMatchParser<'a>(pub &'a Context<'a>);
|
||||
|
|
@ -39,14 +44,16 @@ impl Parser for WindowMatchParser<'_> {
|
|||
table: &IndexMap<Spanned<String>, Spanned<Value>>,
|
||||
) -> ParseResult<Self> {
|
||||
let mut ext = Extractor::new(self.0, span, table);
|
||||
let ((name, not_val, all_val, any_val, exactly_val, types_val),) = ext.extract(((
|
||||
opt(str("name")),
|
||||
opt(val("not")),
|
||||
opt(arr("all")),
|
||||
opt(arr("any")),
|
||||
opt(val("exactly")),
|
||||
opt(val("types")),
|
||||
),))?;
|
||||
let ((name, not_val, all_val, any_val, exactly_val, types_val, client_val),) = ext
|
||||
.extract(((
|
||||
opt(str("name")),
|
||||
opt(val("not")),
|
||||
opt(arr("all")),
|
||||
opt(arr("any")),
|
||||
opt(val("exactly")),
|
||||
opt(val("types")),
|
||||
opt(val("client")),
|
||||
),))?;
|
||||
let mut not = None;
|
||||
if let Some(value) = not_val {
|
||||
not = Some(Box::new(value.parse(&mut WindowMatchParser(self.0))?));
|
||||
|
|
@ -74,6 +81,10 @@ impl Parser for WindowMatchParser<'_> {
|
|||
if let Some(value) = exactly_val {
|
||||
exactly = Some(value.parse(&mut WindowMatchExactlyParser(self.0))?);
|
||||
}
|
||||
let mut client = None;
|
||||
if let Some(value) = client_val {
|
||||
client = Some(value.parse_map(&mut ClientMatchParser(self.0))?);
|
||||
}
|
||||
Ok(WindowMatch {
|
||||
generic: GenericMatch {
|
||||
name: name.despan_into(),
|
||||
|
|
@ -83,6 +94,7 @@ impl Parser for WindowMatchParser<'_> {
|
|||
exactly,
|
||||
},
|
||||
types,
|
||||
client,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -219,7 +219,7 @@ impl Rule for WindowRule {
|
|||
}
|
||||
|
||||
fn map_custom(
|
||||
_state: &Rc<State>,
|
||||
state: &Rc<State>,
|
||||
all: &mut Vec<MatcherTemp<Self>>,
|
||||
match_: &Self::Match,
|
||||
) -> Option<()> {
|
||||
|
|
@ -248,6 +248,14 @@ impl Rule for WindowRule {
|
|||
if let Some(value) = &match_.types {
|
||||
all.push(m(WindowCriterion::Types(*value)));
|
||||
}
|
||||
if let Some(value) = &match_.client {
|
||||
let mut mapper = state.persistent.client_rule_mapper.borrow_mut();
|
||||
let mapper = mapper.as_mut()?;
|
||||
let matcher = mapper.map_temporary_match(&[], value)?;
|
||||
all.push(m(WindowCriterion::Client(&ClientCriterion::Matcher(
|
||||
matcher.0,
|
||||
))));
|
||||
}
|
||||
Some(())
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue