metal: implement VRR
This commit is contained in:
parent
cd09e57568
commit
2d7c13b0b4
35 changed files with 1320 additions and 91 deletions
|
|
@ -22,7 +22,7 @@ use {
|
|||
logging::LogLevel,
|
||||
status::MessageFormat,
|
||||
theme::Color,
|
||||
video::{GfxApi, Transform},
|
||||
video::{GfxApi, Transform, VrrMode},
|
||||
Axis, Direction, Workspace,
|
||||
},
|
||||
std::{
|
||||
|
|
@ -206,6 +206,7 @@ pub struct Output {
|
|||
pub scale: Option<f64>,
|
||||
pub transform: Option<Transform>,
|
||||
pub mode: Option<Mode>,
|
||||
pub vrr: Option<Vrr>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
@ -285,6 +286,12 @@ pub struct RepeatRate {
|
|||
pub delay: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Vrr {
|
||||
pub mode: Option<VrrMode>,
|
||||
pub cursor_hz: Option<f64>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Shortcut {
|
||||
pub mask: Modifiers,
|
||||
|
|
@ -318,6 +325,7 @@ pub struct Config {
|
|||
pub explicit_sync_enabled: Option<bool>,
|
||||
pub focus_follows_mouse: bool,
|
||||
pub window_management_key: Option<ModifiedKeySym>,
|
||||
pub vrr: Option<Vrr>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
@ -30,7 +30,8 @@ use {
|
|||
video::{
|
||||
connectors, drm_devices, on_connector_connected, on_connector_disconnected,
|
||||
on_graphics_initialized, on_new_connector, on_new_drm_device,
|
||||
set_direct_scanout_enabled, set_gfx_api, Connector, DrmDevice,
|
||||
set_direct_scanout_enabled, set_gfx_api, set_vrr_cursor_hz, set_vrr_mode, Connector,
|
||||
DrmDevice,
|
||||
},
|
||||
},
|
||||
std::{cell::RefCell, io::ErrorKind, path::PathBuf, rc::Rc},
|
||||
|
|
@ -555,6 +556,14 @@ impl Output {
|
|||
Some(m) => c.set_mode(m.width(), m.height(), Some(m.refresh_rate())),
|
||||
}
|
||||
}
|
||||
if let Some(vrr) = &self.vrr {
|
||||
if let Some(mode) = vrr.mode {
|
||||
c.set_vrr_mode(mode);
|
||||
}
|
||||
if let Some(hz) = vrr.cursor_hz {
|
||||
c.set_vrr_cursor_hz(hz);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1017,6 +1026,14 @@ fn load_config(initial_load: bool, persistent: &Rc<PersistentState>) {
|
|||
.seat
|
||||
.set_window_management_key(window_management_key);
|
||||
}
|
||||
if let Some(vrr) = config.vrr {
|
||||
if let Some(mode) = vrr.mode {
|
||||
set_vrr_mode(mode);
|
||||
}
|
||||
if let Some(hz) = vrr.cursor_hz {
|
||||
set_vrr_cursor_hz(hz);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn create_command(exec: &Exec) -> Command {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue