config: allow configuring repeat rates via toml
This commit is contained in:
parent
b374947b45
commit
1a9b7146fd
9 changed files with 241 additions and 2 deletions
|
|
@ -117,6 +117,9 @@ pub enum Action {
|
|||
workspace: Option<Workspace>,
|
||||
output: OutputMatch,
|
||||
},
|
||||
SetRepeatRate {
|
||||
rate: RepeatRate,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
|
|
@ -269,9 +272,16 @@ pub enum ConfigKeymap {
|
|||
Defined { name: String, map: Keymap },
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct RepeatRate {
|
||||
pub rate: i32,
|
||||
pub delay: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Config {
|
||||
pub keymap: Option<ConfigKeymap>,
|
||||
pub repeat_rate: Option<RepeatRate>,
|
||||
pub shortcuts: Vec<(ModifiedKeySym, Action)>,
|
||||
pub on_graphics_initialized: Option<Action>,
|
||||
pub on_idle: Option<Action>,
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ mod mode;
|
|||
pub mod modified_keysym;
|
||||
mod output;
|
||||
mod output_match;
|
||||
mod repeat_rate;
|
||||
pub mod shortcuts;
|
||||
mod status;
|
||||
mod theme;
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ use {
|
|||
log_level::{LogLevelParser, LogLevelParserError},
|
||||
output::{OutputParser, OutputParserError},
|
||||
output_match::{OutputMatchParser, OutputMatchParserError},
|
||||
repeat_rate::{RepeatRateParser, RepeatRateParserError},
|
||||
status::{StatusParser, StatusParserError},
|
||||
theme::{ThemeParser, ThemeParserError},
|
||||
StringParser, StringParserError,
|
||||
|
|
@ -77,6 +78,8 @@ pub enum ActionParserError {
|
|||
ConfigureIdle(#[source] IdleParserError),
|
||||
#[error("Could not parse a move-to-output action")]
|
||||
MoveToOutput(#[source] OutputMatchParserError),
|
||||
#[error("Could not parse a set-repeat-rate action")]
|
||||
RepeatRate(#[source] RepeatRateParserError),
|
||||
}
|
||||
|
||||
pub struct ActionParser<'a>(pub &'a Context<'a>);
|
||||
|
|
@ -295,6 +298,14 @@ impl ActionParser<'_> {
|
|||
output,
|
||||
})
|
||||
}
|
||||
|
||||
fn parse_set_repeat_rate(&mut self, ext: &mut Extractor<'_>) -> ParseResult<Self> {
|
||||
let rate = ext
|
||||
.extract(val("rate"))?
|
||||
.parse_map(&mut RepeatRateParser(self.0))
|
||||
.map_spanned_err(ActionParserError::RepeatRate)?;
|
||||
Ok(Action::SetRepeatRate { rate })
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Parser for ActionParser<'a> {
|
||||
|
|
@ -345,6 +356,7 @@ impl<'a> Parser for ActionParser<'a> {
|
|||
"set-render-device" => self.parse_set_render_device(&mut ext),
|
||||
"configure-idle" => self.parse_configure_idle(&mut ext),
|
||||
"move-to-output" => self.parse_move_to_output(&mut ext),
|
||||
"set-repeat-rate" => self.parse_set_repeat_rate(&mut ext),
|
||||
v => {
|
||||
ext.ignore_unused();
|
||||
return Err(ActionParserError::UnknownType(v.to_string()).spanned(ty.span));
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ use {
|
|||
keymap::KeymapParser,
|
||||
log_level::LogLevelParser,
|
||||
output::OutputsParser,
|
||||
repeat_rate::RepeatRateParser,
|
||||
shortcuts::{ShortcutsParser, ShortcutsParserError},
|
||||
status::StatusParser,
|
||||
theme::ThemeParser,
|
||||
|
|
@ -95,7 +96,7 @@ impl Parser for ConfigParser<'_> {
|
|||
_,
|
||||
idle_val,
|
||||
),
|
||||
(explicit_sync,),
|
||||
(explicit_sync, repeat_rate_val),
|
||||
) = ext.extract((
|
||||
(
|
||||
opt(val("keymap")),
|
||||
|
|
@ -121,7 +122,7 @@ impl Parser for ConfigParser<'_> {
|
|||
opt(val("$schema")),
|
||||
opt(val("idle")),
|
||||
),
|
||||
(recover(opt(bol("explicit-sync"))),),
|
||||
(recover(opt(bol("explicit-sync"))), opt(val("repeat-rate"))),
|
||||
))?;
|
||||
let mut keymap = None;
|
||||
if let Some(value) = keymap_val {
|
||||
|
|
@ -256,8 +257,18 @@ impl Parser for ConfigParser<'_> {
|
|||
}
|
||||
}
|
||||
}
|
||||
let mut repeat_rate = None;
|
||||
if let Some(value) = repeat_rate_val {
|
||||
match value.parse(&mut RepeatRateParser(self.0)) {
|
||||
Ok(v) => repeat_rate = Some(v),
|
||||
Err(e) => {
|
||||
log::warn!("Could not parse the repeat rate: {}", self.0.error(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(Config {
|
||||
keymap,
|
||||
repeat_rate,
|
||||
shortcuts,
|
||||
on_graphics_initialized,
|
||||
on_idle,
|
||||
|
|
|
|||
45
toml-config/src/config/parsers/repeat_rate.rs
Normal file
45
toml-config/src/config/parsers/repeat_rate.rs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
use {
|
||||
crate::{
|
||||
config::{
|
||||
context::Context,
|
||||
extractor::{s32, Extractor, ExtractorError},
|
||||
parser::{DataType, ParseResult, Parser, UnexpectedDataType},
|
||||
RepeatRate,
|
||||
},
|
||||
toml::{
|
||||
toml_span::{Span, Spanned},
|
||||
toml_value::Value,
|
||||
},
|
||||
},
|
||||
indexmap::IndexMap,
|
||||
thiserror::Error,
|
||||
};
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum RepeatRateParserError {
|
||||
#[error(transparent)]
|
||||
Expected(#[from] UnexpectedDataType),
|
||||
#[error(transparent)]
|
||||
Extract(#[from] ExtractorError),
|
||||
}
|
||||
|
||||
pub struct RepeatRateParser<'a>(pub &'a Context<'a>);
|
||||
|
||||
impl Parser for RepeatRateParser<'_> {
|
||||
type Value = RepeatRate;
|
||||
type Error = RepeatRateParserError;
|
||||
const EXPECTED: &'static [DataType] = &[DataType::Table];
|
||||
|
||||
fn parse_table(
|
||||
&mut self,
|
||||
span: Span,
|
||||
table: &IndexMap<Spanned<String>, Spanned<Value>>,
|
||||
) -> ParseResult<Self> {
|
||||
let mut ext = Extractor::new(self.0, span, table);
|
||||
let (rate, delay) = ext.extract((s32("rate"), s32("delay")))?;
|
||||
Ok(RepeatRate {
|
||||
rate: rate.value,
|
||||
delay: delay.value,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -172,6 +172,9 @@ impl Action {
|
|||
}
|
||||
})
|
||||
}
|
||||
Action::SetRepeatRate { rate } => {
|
||||
Box::new(move || s.set_repeat_rate(rate.rate, rate.delay))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -728,6 +731,11 @@ fn load_config(initial_load: bool, persistent: &Rc<PersistentState>) {
|
|||
if let Some(keymap) = config.keymap {
|
||||
state.set_keymap(&keymap);
|
||||
}
|
||||
if let Some(repeat_rate) = config.repeat_rate {
|
||||
persistent
|
||||
.seat
|
||||
.set_repeat_rate(repeat_rate.rate, repeat_rate.delay);
|
||||
}
|
||||
on_new_connector(move |c| {
|
||||
for connector in &config.connectors {
|
||||
if connector.match_.matches(c) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue