1
0
Fork 0
forked from wry/wry

wayland: implement wl_touch

Co-authored-by: Julian Orth <ju.orth@gmail.com>
This commit is contained in:
Amine Hassane 2024-04-21 14:48:26 +01:00 committed by Julian Orth
parent 905e2dd7ba
commit 681c1ad033
35 changed files with 1071 additions and 52 deletions

View file

@ -250,6 +250,7 @@ pub struct Input {
pub keymap: Option<ConfigKeymap>,
pub switch_actions: AHashMap<SwitchEvent, Action>,
pub output: Option<Option<OutputMatch>>,
pub calibration_matrix: Option<[[f32; 3]; 2]>,
}
#[derive(Debug, Clone)]

View file

@ -40,6 +40,12 @@ pub enum InputParserError {
TwoColumns,
#[error("Transform matrix entries must be floats")]
Float,
#[error("Calibration matrix must have exactly two rows")]
CaliTwoRows,
#[error("Calibration matrix must have exactly three columns")]
CaliThreeColumns,
#[error("Calibration matrix entries must be floats")]
CaliFloat,
}
pub struct InputParser<'a> {
@ -80,6 +86,7 @@ impl<'a> Parser for InputParser<'a> {
on_converted_to_tablet_val,
output_val,
remove_mapping,
calibration_matrix,
),
) = ext.extract((
(
@ -103,6 +110,7 @@ impl<'a> Parser for InputParser<'a> {
opt(val("on-converted-to-tablet")),
opt(val("output")),
recover(opt(bol("remove-mapping"))),
recover(opt(val("calibration-matrix"))),
),
))?;
let accel_profile = match accel_profile {
@ -214,6 +222,16 @@ impl<'a> Parser for InputParser<'a> {
output = Some(None);
}
}
let calibration_matrix = match calibration_matrix {
None => None,
Some(matrix) => match matrix.parse(&mut CalibrationMatrixParser) {
Ok(v) => Some(v),
Err(e) => {
log::warn!("Could not parse calibration matrix: {}", self.cx.error(e));
None
}
},
};
Ok(Input {
tag: tag.despan_into(),
match_: match_val.parse_map(&mut InputMatchParser(self.cx))?,
@ -229,6 +247,7 @@ impl<'a> Parser for InputParser<'a> {
keymap,
switch_actions,
output,
calibration_matrix,
})
}
}
@ -311,3 +330,45 @@ impl Parser for TransformMatrixRowParser {
Ok([extract(&array[0])?, extract(&array[1])?])
}
}
struct CalibrationMatrixParser;
impl Parser for CalibrationMatrixParser {
type Value = [[f32; 3]; 2];
type Error = InputParserError;
const EXPECTED: &'static [DataType] = &[DataType::Array];
fn parse_array(&mut self, span: Span, array: &[Spanned<Value>]) -> ParseResult<Self> {
if array.len() != 2 {
return Err(InputParserError::CaliTwoRows.spanned(span));
}
Ok([
array[0].parse(&mut CalibrationMatrixRowParser)?,
array[1].parse(&mut CalibrationMatrixRowParser)?,
])
}
}
struct CalibrationMatrixRowParser;
impl Parser for CalibrationMatrixRowParser {
type Value = [f32; 3];
type Error = InputParserError;
const EXPECTED: &'static [DataType] = &[DataType::Array];
fn parse_array(&mut self, span: Span, array: &[Spanned<Value>]) -> ParseResult<Self> {
if array.len() != 3 {
return Err(InputParserError::CaliThreeColumns.spanned(span));
}
let extract = |v: &Spanned<Value>| match v.value {
Value::Float(f) => Ok(f as f32),
Value::Integer(f) => Ok(f as _),
_ => Err(InputParserError::CaliFloat.spanned(v.span)),
};
Ok([
extract(&array[0])?,
extract(&array[1])?,
extract(&array[2])?,
])
}
}

View file

@ -437,6 +437,9 @@ impl Input {
c.remove_mapping();
}
}
if let Some(v) = self.calibration_matrix {
c.set_calibration_matrix(v);
}
}
}