1
0
Fork 0
forked from wry/wry

config: make ui dragging configurable

This commit is contained in:
Julian Orth 2024-10-01 11:18:25 +02:00
parent 1dd20fb87b
commit d8ee1ac19c
19 changed files with 255 additions and 12 deletions

View file

@ -32,6 +32,7 @@ pub mod shortcuts;
mod status;
mod tearing;
mod theme;
mod ui_drag;
mod vrr;
#[derive(Debug, Error)]

View file

@ -25,10 +25,11 @@ use {
status::StatusParser,
tearing::TearingParser,
theme::ThemeParser,
ui_drag::UiDragParser,
vrr::VrrParser,
},
spanned::SpannedErrorExt,
Action, Config, Libei, Theme,
Action, Config, Libei, Theme, UiDrag,
},
toml::{
toml_span::{DespanExt, Span, Spanned},
@ -112,6 +113,7 @@ impl Parser for ConfigParser<'_> {
vrr_val,
tearing_val,
libei_val,
ui_drag_val,
),
) = ext.extract((
(
@ -147,6 +149,7 @@ impl Parser for ConfigParser<'_> {
opt(val("vrr")),
opt(val("tearing")),
opt(val("libei")),
opt(val("ui-drag")),
),
))?;
let mut keymap = None;
@ -338,6 +341,15 @@ impl Parser for ConfigParser<'_> {
}
}
}
let mut ui_drag = UiDrag::default();
if let Some(value) = ui_drag_val {
match value.parse(&mut UiDragParser(self.0)) {
Ok(v) => ui_drag = v,
Err(e) => {
log::warn!("Could not parse ui-drag setting: {}", self.0.error(e));
}
}
}
Ok(Config {
keymap,
repeat_rate,
@ -365,6 +377,7 @@ impl Parser for ConfigParser<'_> {
vrr,
tearing,
libei,
ui_drag,
})
}
}

View file

@ -0,0 +1,49 @@
use {
crate::{
config::{
context::Context,
extractor::{bol, int, opt, recover, Extractor, ExtractorError},
parser::{DataType, ParseResult, Parser, UnexpectedDataType},
parsers::exec::ExecParserError,
UiDrag,
},
toml::{
toml_span::{DespanExt, Span, Spanned},
toml_value::Value,
},
},
indexmap::IndexMap,
thiserror::Error,
};
#[derive(Debug, Error)]
pub enum UiDragParserError {
#[error(transparent)]
Expected(#[from] UnexpectedDataType),
#[error(transparent)]
Exec(#[from] ExecParserError),
#[error(transparent)]
Extract(#[from] ExtractorError),
}
pub struct UiDragParser<'a>(pub &'a Context<'a>);
impl Parser for UiDragParser<'_> {
type Value = UiDrag;
type Error = UiDragParserError;
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, threshold) =
ext.extract((recover(opt(bol("enabled"))), recover(opt(int("threshold")))))?;
Ok(UiDrag {
enabled: enabled.despan(),
threshold: threshold.despan().map(|v| v as i32),
})
}
}