1
0
Fork 0
forked from wry/wry

config: allow disabling color-management

This commit is contained in:
Julian Orth 2025-02-26 16:16:38 +01:00
parent c66f5798b7
commit 248eb324a5
24 changed files with 388 additions and 9 deletions

View file

@ -8,6 +8,7 @@ use {
pub mod action;
mod color;
pub mod color_management;
pub mod config;
mod connector;
mod connector_match;

View file

@ -0,0 +1,48 @@
use {
crate::{
config::{
context::Context,
extractor::{Extractor, ExtractorError, bol, opt},
parser::{DataType, ParseResult, Parser, UnexpectedDataType},
},
toml::{
toml_span::{DespanExt, Span, Spanned},
toml_value::Value,
},
},
indexmap::IndexMap,
thiserror::Error,
};
#[derive(Debug, Error)]
pub enum ColorManagementParserError {
#[error(transparent)]
Expected(#[from] UnexpectedDataType),
#[error(transparent)]
Extract(#[from] ExtractorError),
}
pub struct ColorManagementParser<'a>(pub &'a Context<'a>);
#[derive(Clone, Debug)]
pub struct ColorManagement {
pub enabled: Option<bool>,
}
impl Parser for ColorManagementParser<'_> {
type Value = ColorManagement;
type Error = ColorManagementParserError;
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 (enabled,) = ext.extract((opt(bol("enabled")),))?;
Ok(ColorManagement {
enabled: enabled.despan(),
})
}
}

View file

@ -7,6 +7,7 @@ use {
parser::{DataType, ParseResult, Parser, UnexpectedDataType},
parsers::{
action::ActionParser,
color_management::ColorManagementParser,
connector::ConnectorsParser,
drm_device::DrmDevicesParser,
drm_device_match::DrmDeviceMatchParser,
@ -117,6 +118,7 @@ impl Parser for ConfigParser<'_> {
ui_drag_val,
xwayland_val,
),
(color_management_val,),
) = ext.extract((
(
opt(val("keymap")),
@ -154,6 +156,7 @@ impl Parser for ConfigParser<'_> {
opt(val("ui-drag")),
opt(val("xwayland")),
),
(opt(val("color-management")),),
))?;
let mut keymap = None;
if let Some(value) = keymap_val {
@ -366,6 +369,18 @@ impl Parser for ConfigParser<'_> {
}
}
}
let mut color_management = None;
if let Some(value) = color_management_val {
match value.parse(&mut ColorManagementParser(self.0)) {
Ok(v) => color_management = Some(v),
Err(e) => {
log::warn!(
"Could not parse the color-management settings: {}",
self.0.error(e)
);
}
}
}
Ok(Config {
keymap,
repeat_rate,
@ -396,6 +411,7 @@ impl Parser for ConfigParser<'_> {
libei,
ui_drag,
xwayland,
color_management,
})
}
}