metal: implement tearing
This commit is contained in:
parent
d355059ad9
commit
49f6304716
31 changed files with 726 additions and 51 deletions
|
|
@ -22,7 +22,7 @@ use {
|
|||
logging::LogLevel,
|
||||
status::MessageFormat,
|
||||
theme::Color,
|
||||
video::{GfxApi, Transform, VrrMode},
|
||||
video::{GfxApi, TearingMode, Transform, VrrMode},
|
||||
Axis, Direction, Workspace,
|
||||
},
|
||||
std::{
|
||||
|
|
@ -207,6 +207,7 @@ pub struct Output {
|
|||
pub transform: Option<Transform>,
|
||||
pub mode: Option<Mode>,
|
||||
pub vrr: Option<Vrr>,
|
||||
pub tearing: Option<Tearing>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
@ -292,6 +293,11 @@ pub struct Vrr {
|
|||
pub cursor_hz: Option<f64>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Tearing {
|
||||
pub mode: Option<TearingMode>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Shortcut {
|
||||
pub mask: Modifiers,
|
||||
|
|
@ -326,6 +332,7 @@ pub struct Config {
|
|||
pub focus_follows_mouse: bool,
|
||||
pub window_management_key: Option<ModifiedKeySym>,
|
||||
pub vrr: Option<Vrr>,
|
||||
pub tearing: Option<Tearing>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ mod output_match;
|
|||
mod repeat_rate;
|
||||
pub mod shortcuts;
|
||||
mod status;
|
||||
mod tearing;
|
||||
mod theme;
|
||||
mod vrr;
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ use {
|
|||
ShortcutsParserError,
|
||||
},
|
||||
status::StatusParser,
|
||||
tearing::TearingParser,
|
||||
theme::ThemeParser,
|
||||
vrr::VrrParser,
|
||||
},
|
||||
|
|
@ -108,6 +109,7 @@ impl Parser for ConfigParser<'_> {
|
|||
focus_follows_mouse,
|
||||
window_management_key_val,
|
||||
vrr_val,
|
||||
tearing_val,
|
||||
),
|
||||
) = ext.extract((
|
||||
(
|
||||
|
|
@ -141,6 +143,7 @@ impl Parser for ConfigParser<'_> {
|
|||
recover(opt(bol("focus-follows-mouse"))),
|
||||
recover(opt(str("window-management-key"))),
|
||||
opt(val("vrr")),
|
||||
opt(val("tearing")),
|
||||
),
|
||||
))?;
|
||||
let mut keymap = None;
|
||||
|
|
@ -314,6 +317,15 @@ impl Parser for ConfigParser<'_> {
|
|||
}
|
||||
}
|
||||
}
|
||||
let mut tearing = None;
|
||||
if let Some(value) = tearing_val {
|
||||
match value.parse(&mut TearingParser(self.0)) {
|
||||
Ok(v) => tearing = Some(v),
|
||||
Err(e) => {
|
||||
log::warn!("Could not parse tearing setting: {}", self.0.error(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(Config {
|
||||
keymap,
|
||||
repeat_rate,
|
||||
|
|
@ -339,6 +351,7 @@ impl Parser for ConfigParser<'_> {
|
|||
focus_follows_mouse: focus_follows_mouse.despan().unwrap_or(true),
|
||||
window_management_key,
|
||||
vrr,
|
||||
tearing,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ use {
|
|||
parsers::{
|
||||
mode::ModeParser,
|
||||
output_match::{OutputMatchParser, OutputMatchParserError},
|
||||
tearing::TearingParser,
|
||||
vrr::VrrParser,
|
||||
},
|
||||
Output,
|
||||
|
|
@ -47,16 +48,18 @@ 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, vrr_val) = ext.extract((
|
||||
opt(str("name")),
|
||||
val("match"),
|
||||
recover(opt(s32("x"))),
|
||||
recover(opt(s32("y"))),
|
||||
recover(opt(fltorint("scale"))),
|
||||
recover(opt(str("transform"))),
|
||||
opt(val("mode")),
|
||||
opt(val("vrr")),
|
||||
))?;
|
||||
let (name, match_val, x, y, scale, transform, mode, vrr_val, tearing_val) =
|
||||
ext.extract((
|
||||
opt(str("name")),
|
||||
val("match"),
|
||||
recover(opt(s32("x"))),
|
||||
recover(opt(s32("y"))),
|
||||
recover(opt(fltorint("scale"))),
|
||||
recover(opt(str("transform"))),
|
||||
opt(val("mode")),
|
||||
opt(val("vrr")),
|
||||
opt(val("tearing")),
|
||||
))?;
|
||||
let transform = match transform {
|
||||
None => None,
|
||||
Some(t) => match t.value {
|
||||
|
|
@ -107,6 +110,15 @@ impl<'a> Parser for OutputParser<'a> {
|
|||
}
|
||||
}
|
||||
}
|
||||
let mut tearing = None;
|
||||
if let Some(value) = tearing_val {
|
||||
match value.parse(&mut TearingParser(self.cx)) {
|
||||
Ok(v) => tearing = Some(v),
|
||||
Err(e) => {
|
||||
log::warn!("Could not parse tearing setting: {}", self.cx.error(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(Output {
|
||||
name: name.despan().map(|v| v.to_string()),
|
||||
match_: match_val.parse_map(&mut OutputMatchParser(self.cx))?,
|
||||
|
|
@ -116,6 +128,7 @@ impl<'a> Parser for OutputParser<'a> {
|
|||
transform,
|
||||
mode,
|
||||
vrr,
|
||||
tearing,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
78
toml-config/src/config/parsers/tearing.rs
Normal file
78
toml-config/src/config/parsers/tearing.rs
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
use {
|
||||
crate::{
|
||||
config::{
|
||||
context::Context,
|
||||
extractor::{opt, val, Extractor, ExtractorError},
|
||||
parser::{DataType, ParseResult, Parser, UnexpectedDataType},
|
||||
Tearing,
|
||||
},
|
||||
toml::{
|
||||
toml_span::{Span, Spanned, SpannedExt},
|
||||
toml_value::Value,
|
||||
},
|
||||
},
|
||||
indexmap::IndexMap,
|
||||
jay_config::video::TearingMode,
|
||||
thiserror::Error,
|
||||
};
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum TearingParserError {
|
||||
#[error(transparent)]
|
||||
Expected(#[from] UnexpectedDataType),
|
||||
#[error(transparent)]
|
||||
Extract(#[from] ExtractorError),
|
||||
}
|
||||
|
||||
pub struct TearingParser<'a>(pub &'a Context<'a>);
|
||||
|
||||
impl Parser for TearingParser<'_> {
|
||||
type Value = Tearing;
|
||||
type Error = TearingParserError;
|
||||
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 = ext.extract(opt(val("mode")))?;
|
||||
let mode = mode.and_then(|m| match m.parse(&mut TearingModeParser) {
|
||||
Ok(m) => Some(m),
|
||||
Err(e) => {
|
||||
log::error!("Could not parse mode: {}", self.0.error(e));
|
||||
None
|
||||
}
|
||||
});
|
||||
Ok(Tearing { mode })
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum TearingModeParserError {
|
||||
#[error(transparent)]
|
||||
Expected(#[from] UnexpectedDataType),
|
||||
#[error("Unknown mode {0}")]
|
||||
UnknownMode(String),
|
||||
}
|
||||
|
||||
struct TearingModeParser;
|
||||
|
||||
impl Parser for TearingModeParser {
|
||||
type Value = TearingMode;
|
||||
type Error = TearingModeParserError;
|
||||
const EXPECTED: &'static [DataType] = &[DataType::String];
|
||||
|
||||
fn parse_string(&mut self, span: Span, string: &str) -> ParseResult<Self> {
|
||||
let mode = match string {
|
||||
"never" => TearingMode::NEVER,
|
||||
"always" => TearingMode::ALWAYS,
|
||||
"variant1" => TearingMode::VARIANT_1,
|
||||
"variant2" => TearingMode::VARIANT_2,
|
||||
"variant3" => TearingMode::VARIANT_3,
|
||||
_ => return Err(TearingModeParserError::UnknownMode(string.to_string()).spanned(span)),
|
||||
};
|
||||
Ok(mode)
|
||||
}
|
||||
}
|
||||
|
|
@ -30,8 +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, set_vrr_cursor_hz, set_vrr_mode, Connector,
|
||||
DrmDevice,
|
||||
set_direct_scanout_enabled, set_gfx_api, set_tearing_mode, set_vrr_cursor_hz,
|
||||
set_vrr_mode, Connector, DrmDevice,
|
||||
},
|
||||
},
|
||||
std::{cell::RefCell, io::ErrorKind, path::PathBuf, rc::Rc},
|
||||
|
|
@ -564,6 +564,11 @@ impl Output {
|
|||
c.set_vrr_cursor_hz(hz);
|
||||
}
|
||||
}
|
||||
if let Some(tearing) = &self.tearing {
|
||||
if let Some(mode) = tearing.mode {
|
||||
c.set_tearing_mode(mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1034,6 +1039,11 @@ fn load_config(initial_load: bool, persistent: &Rc<PersistentState>) {
|
|||
set_vrr_cursor_hz(hz);
|
||||
}
|
||||
}
|
||||
if let Some(tearing) = config.tearing {
|
||||
if let Some(mode) = tearing.mode {
|
||||
set_tearing_mode(mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn create_command(exec: &Exec) -> Command {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue