metal: implement VRR
This commit is contained in:
parent
cd09e57568
commit
2d7c13b0b4
35 changed files with 1320 additions and 91 deletions
|
|
@ -29,6 +29,7 @@ mod repeat_rate;
|
|||
pub mod shortcuts;
|
||||
mod status;
|
||||
mod theme;
|
||||
mod vrr;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum StringParserError {
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ use {
|
|||
},
|
||||
status::StatusParser,
|
||||
theme::ThemeParser,
|
||||
vrr::VrrParser,
|
||||
},
|
||||
spanned::SpannedErrorExt,
|
||||
Action, Config, Theme,
|
||||
|
|
@ -106,6 +107,7 @@ impl Parser for ConfigParser<'_> {
|
|||
complex_shortcuts_val,
|
||||
focus_follows_mouse,
|
||||
window_management_key_val,
|
||||
vrr_val,
|
||||
),
|
||||
) = ext.extract((
|
||||
(
|
||||
|
|
@ -138,6 +140,7 @@ impl Parser for ConfigParser<'_> {
|
|||
opt(val("complex-shortcuts")),
|
||||
recover(opt(bol("focus-follows-mouse"))),
|
||||
recover(opt(str("window-management-key"))),
|
||||
opt(val("vrr")),
|
||||
),
|
||||
))?;
|
||||
let mut keymap = None;
|
||||
|
|
@ -302,6 +305,15 @@ impl Parser for ConfigParser<'_> {
|
|||
window_management_key = Some(key);
|
||||
}
|
||||
}
|
||||
let mut vrr = None;
|
||||
if let Some(value) = vrr_val {
|
||||
match value.parse(&mut VrrParser(self.0)) {
|
||||
Ok(v) => vrr = Some(v),
|
||||
Err(e) => {
|
||||
log::warn!("Could not parse VRR setting: {}", self.0.error(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(Config {
|
||||
keymap,
|
||||
repeat_rate,
|
||||
|
|
@ -326,6 +338,7 @@ impl Parser for ConfigParser<'_> {
|
|||
idle,
|
||||
focus_follows_mouse: focus_follows_mouse.despan().unwrap_or(true),
|
||||
window_management_key,
|
||||
vrr,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ use {
|
|||
parsers::{
|
||||
mode::ModeParser,
|
||||
output_match::{OutputMatchParser, OutputMatchParserError},
|
||||
vrr::VrrParser,
|
||||
},
|
||||
Output,
|
||||
},
|
||||
|
|
@ -46,7 +47,7 @@ impl<'a> Parser for OutputParser<'a> {
|
|||
table: &IndexMap<Spanned<String>, Spanned<Value>>,
|
||||
) -> ParseResult<Self> {
|
||||
let mut ext = Extractor::new(self.cx, span, table);
|
||||
let (name, match_val, x, y, scale, transform, mode) = ext.extract((
|
||||
let (name, match_val, x, y, scale, transform, mode, vrr_val) = ext.extract((
|
||||
opt(str("name")),
|
||||
val("match"),
|
||||
recover(opt(s32("x"))),
|
||||
|
|
@ -54,6 +55,7 @@ impl<'a> Parser for OutputParser<'a> {
|
|||
recover(opt(fltorint("scale"))),
|
||||
recover(opt(str("transform"))),
|
||||
opt(val("mode")),
|
||||
opt(val("vrr")),
|
||||
))?;
|
||||
let transform = match transform {
|
||||
None => None,
|
||||
|
|
@ -96,6 +98,15 @@ impl<'a> Parser for OutputParser<'a> {
|
|||
);
|
||||
}
|
||||
}
|
||||
let mut vrr = None;
|
||||
if let Some(value) = vrr_val {
|
||||
match value.parse(&mut VrrParser(self.cx)) {
|
||||
Ok(v) => vrr = Some(v),
|
||||
Err(e) => {
|
||||
log::warn!("Could not parse VRR setting: {}", self.cx.error(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(Output {
|
||||
name: name.despan().map(|v| v.to_string()),
|
||||
match_: match_val.parse_map(&mut OutputMatchParser(self.cx))?,
|
||||
|
|
@ -104,6 +115,7 @@ impl<'a> Parser for OutputParser<'a> {
|
|||
scale: scale.despan(),
|
||||
transform,
|
||||
mode,
|
||||
vrr,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
116
toml-config/src/config/parsers/vrr.rs
Normal file
116
toml-config/src/config/parsers/vrr.rs
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
use {
|
||||
crate::{
|
||||
config::{
|
||||
context::Context,
|
||||
extractor::{opt, val, Extractor, ExtractorError},
|
||||
parser::{DataType, ParseResult, Parser, UnexpectedDataType},
|
||||
Vrr,
|
||||
},
|
||||
toml::{
|
||||
toml_span::{Span, Spanned, SpannedExt},
|
||||
toml_value::Value,
|
||||
},
|
||||
},
|
||||
indexmap::IndexMap,
|
||||
jay_config::video::VrrMode,
|
||||
thiserror::Error,
|
||||
};
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum VrrParserError {
|
||||
#[error(transparent)]
|
||||
Expected(#[from] UnexpectedDataType),
|
||||
#[error(transparent)]
|
||||
Extract(#[from] ExtractorError),
|
||||
}
|
||||
|
||||
pub struct VrrParser<'a>(pub &'a Context<'a>);
|
||||
|
||||
impl Parser for VrrParser<'_> {
|
||||
type Value = Vrr;
|
||||
type Error = VrrParserError;
|
||||
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 (mode, cursor_hz) = ext.extract((opt(val("mode")), opt(val("cursor-hz"))))?;
|
||||
let mode = mode.and_then(|m| match m.parse(&mut VrrModeParser) {
|
||||
Ok(m) => Some(m),
|
||||
Err(e) => {
|
||||
log::error!("Could not parse mode: {}", self.0.error(e));
|
||||
None
|
||||
}
|
||||
});
|
||||
let cursor_hz = cursor_hz.and_then(|m| match m.parse(&mut VrrRateParser) {
|
||||
Ok(m) => Some(m),
|
||||
Err(e) => {
|
||||
log::error!("Could not parse rate: {}", self.0.error(e));
|
||||
None
|
||||
}
|
||||
});
|
||||
Ok(Vrr { mode, cursor_hz })
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum VrrModeParserError {
|
||||
#[error(transparent)]
|
||||
Expected(#[from] UnexpectedDataType),
|
||||
#[error("Unknown mode {0}")]
|
||||
UnknownMode(String),
|
||||
}
|
||||
|
||||
struct VrrModeParser;
|
||||
|
||||
impl Parser for VrrModeParser {
|
||||
type Value = VrrMode;
|
||||
type Error = VrrModeParserError;
|
||||
const EXPECTED: &'static [DataType] = &[DataType::String];
|
||||
|
||||
fn parse_string(&mut self, span: Span, string: &str) -> ParseResult<Self> {
|
||||
let mode = match string {
|
||||
"never" => VrrMode::NEVER,
|
||||
"always" => VrrMode::ALWAYS,
|
||||
"variant1" => VrrMode::VARIANT_1,
|
||||
"variant2" => VrrMode::VARIANT_2,
|
||||
"variant3" => VrrMode::VARIANT_3,
|
||||
_ => return Err(VrrModeParserError::UnknownMode(string.to_string()).spanned(span)),
|
||||
};
|
||||
Ok(mode)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum VrrRateParserError {
|
||||
#[error(transparent)]
|
||||
Expected(#[from] UnexpectedDataType),
|
||||
#[error("Unknown rate {0}")]
|
||||
UnknownString(String),
|
||||
}
|
||||
|
||||
struct VrrRateParser;
|
||||
|
||||
impl Parser for VrrRateParser {
|
||||
type Value = f64;
|
||||
type Error = VrrRateParserError;
|
||||
const EXPECTED: &'static [DataType] = &[DataType::String, DataType::Float, DataType::Integer];
|
||||
|
||||
fn parse_string(&mut self, span: Span, string: &str) -> ParseResult<Self> {
|
||||
match string {
|
||||
"none" => Ok(f64::INFINITY),
|
||||
_ => Err(VrrRateParserError::UnknownString(string.to_string()).spanned(span)),
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_integer(&mut self, _span: Span, integer: i64) -> ParseResult<Self> {
|
||||
Ok(integer as _)
|
||||
}
|
||||
|
||||
fn parse_float(&mut self, _span: Span, float: f64) -> ParseResult<Self> {
|
||||
Ok(float)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue