config: allow configuring client capabilities
This commit is contained in:
parent
76a1a86091
commit
e680a3dc09
21 changed files with 624 additions and 39 deletions
|
|
@ -25,6 +25,7 @@ use {
|
|||
ahash::AHashMap,
|
||||
jay_config::{
|
||||
Axis, Direction, Workspace,
|
||||
client::ClientCapabilities,
|
||||
input::{
|
||||
LayerDirection, SwitchEvent, Timeline, acceleration::AccelProfile,
|
||||
clickmethod::ClickMethod,
|
||||
|
|
@ -247,6 +248,8 @@ pub struct ClientRule {
|
|||
pub match_: ClientMatch,
|
||||
pub action: Option<Action>,
|
||||
pub latch: Option<Action>,
|
||||
pub capabilities: Option<ClientCapabilities>,
|
||||
pub bounding_capabilities: Option<ClientCapabilities>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone)]
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use {
|
|||
|
||||
pub mod action;
|
||||
mod actions;
|
||||
mod capabilities;
|
||||
mod client_match;
|
||||
mod client_rule;
|
||||
mod color;
|
||||
|
|
|
|||
66
toml-config/src/config/parsers/capabilities.rs
Normal file
66
toml-config/src/config/parsers/capabilities.rs
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
use {
|
||||
crate::{
|
||||
config::parser::{DataType, ParseResult, Parser, UnexpectedDataType},
|
||||
toml::{
|
||||
toml_span::{Span, Spanned, SpannedExt},
|
||||
toml_value::Value,
|
||||
},
|
||||
},
|
||||
jay_config::client::{
|
||||
CC_DATA_CONTROL, CC_DRM_LEASE, CC_FOREIGN_TOPLEVEL_LIST, CC_FOREIGN_TOPLEVEL_MANAGER,
|
||||
CC_HEAD_MANAGER, CC_IDLE_NOTIFIER, CC_INPUT_METHOD, CC_LAYER_SHELL, CC_SCREENCOPY,
|
||||
CC_SEAT_MANAGER, CC_SESSION_LOCK, CC_VIRTUAL_KEYBOARD, CC_WORKSPACE_MANAGER,
|
||||
ClientCapabilities,
|
||||
},
|
||||
thiserror::Error,
|
||||
};
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum CapabilitiesParserError {
|
||||
#[error(transparent)]
|
||||
Expected(#[from] UnexpectedDataType),
|
||||
#[error("Unknown capability `{}`", .0)]
|
||||
UnknownCapability(String),
|
||||
}
|
||||
|
||||
pub struct CapabilitiesParser;
|
||||
|
||||
impl Parser for CapabilitiesParser {
|
||||
type Value = ClientCapabilities;
|
||||
type Error = CapabilitiesParserError;
|
||||
const EXPECTED: &'static [DataType] = &[DataType::Array, DataType::String];
|
||||
|
||||
fn parse_string(&mut self, span: Span, string: &str) -> ParseResult<Self> {
|
||||
let ty = match string {
|
||||
"none" => ClientCapabilities(0),
|
||||
"all" => ClientCapabilities(!0),
|
||||
"data-control" => CC_DATA_CONTROL,
|
||||
"virtual-keyboard" => CC_VIRTUAL_KEYBOARD,
|
||||
"foreign-toplevel-list" => CC_FOREIGN_TOPLEVEL_LIST,
|
||||
"idle-notifier" => CC_IDLE_NOTIFIER,
|
||||
"session-lock" => CC_SESSION_LOCK,
|
||||
"layer-shell" => CC_LAYER_SHELL,
|
||||
"screencopy" => CC_SCREENCOPY,
|
||||
"seat-manager" => CC_SEAT_MANAGER,
|
||||
"drm-lease" => CC_DRM_LEASE,
|
||||
"input-method" => CC_INPUT_METHOD,
|
||||
"workspace-manager" => CC_WORKSPACE_MANAGER,
|
||||
"foreign-toplevel-manager" => CC_FOREIGN_TOPLEVEL_MANAGER,
|
||||
"head-manager" => CC_HEAD_MANAGER,
|
||||
_ => {
|
||||
return Err(
|
||||
CapabilitiesParserError::UnknownCapability(string.to_owned()).spanned(span),
|
||||
);
|
||||
}
|
||||
};
|
||||
Ok(ty)
|
||||
}
|
||||
|
||||
fn parse_array(&mut self, _span: Span, array: &[Spanned<Value>]) -> ParseResult<Self> {
|
||||
let mut ty = ClientCapabilities(0);
|
||||
for el in array {
|
||||
ty |= el.parse(&mut CapabilitiesParser)?;
|
||||
}
|
||||
Ok(ty)
|
||||
}
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@ use {
|
|||
parser::{DataType, ParseResult, Parser, UnexpectedDataType},
|
||||
parsers::{
|
||||
action::{ActionParser, ActionParserError},
|
||||
capabilities::CapabilitiesParser,
|
||||
client_match::{ClientMatchParser, ClientMatchParserError},
|
||||
},
|
||||
spanned::SpannedErrorExt,
|
||||
|
|
@ -47,12 +48,15 @@ impl Parser for ClientRuleParser<'_> {
|
|||
table: &IndexMap<Spanned<String>, Spanned<Value>>,
|
||||
) -> ParseResult<Self> {
|
||||
let mut ext = Extractor::new(self.0, span, table);
|
||||
let (name, match_val, action_val, latch_val) = ext.extract((
|
||||
opt(str("name")),
|
||||
opt(val("match")),
|
||||
opt(val("action")),
|
||||
opt(val("latch")),
|
||||
))?;
|
||||
let (name, match_val, action_val, latch_val, capabilities_val, bounding_capabilities_val) =
|
||||
ext.extract((
|
||||
opt(str("name")),
|
||||
opt(val("match")),
|
||||
opt(val("action")),
|
||||
opt(val("latch")),
|
||||
opt(val("capabilities")),
|
||||
opt(val("sandbox-bounding-capabilities")),
|
||||
))?;
|
||||
let mut action = None;
|
||||
if let Some(value) = action_val {
|
||||
action = Some(
|
||||
|
|
@ -73,11 +77,34 @@ impl Parser for ClientRuleParser<'_> {
|
|||
None => ClientMatch::default(),
|
||||
Some(m) => m.parse_map(&mut ClientMatchParser(self.0))?,
|
||||
};
|
||||
let mut capabilities = None;
|
||||
if let Some(value) = capabilities_val {
|
||||
match value.parse(&mut CapabilitiesParser) {
|
||||
Ok(v) => capabilities = Some(v),
|
||||
Err(e) => {
|
||||
log::warn!("Could not parse the capabilities: {}", self.0.error(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut bounding_capabilities = None;
|
||||
if let Some(value) = bounding_capabilities_val {
|
||||
match value.parse(&mut CapabilitiesParser) {
|
||||
Ok(v) => bounding_capabilities = Some(v),
|
||||
Err(e) => {
|
||||
log::warn!(
|
||||
"Could not parse the bounding capabilities: {}",
|
||||
self.0.error(e)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(ClientRule {
|
||||
name: name.despan_into(),
|
||||
match_,
|
||||
action,
|
||||
latch,
|
||||
capabilities,
|
||||
bounding_capabilities,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -175,6 +175,12 @@ impl Rule for ClientRule {
|
|||
});
|
||||
}
|
||||
}
|
||||
if let Some(caps) = self.capabilities {
|
||||
matcher.set_capabilities(caps);
|
||||
}
|
||||
if let Some(caps) = self.bounding_capabilities {
|
||||
matcher.set_sandbox_bounding_capabilities(caps);
|
||||
}
|
||||
}
|
||||
|
||||
fn gen_matcher(m: Self::Matcher) -> Self::Criterion<'static> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue