Support for setting tablet calibration matrix
Browse files at this commit- feat
- support for setting tablet calibration matrix
- this allows for rotating tablet inputs (#1122)
2 changed files +20 -0
- niri-config/src/lib.rs +6 -0
- src/input/mod.rs +14 -0
niri-config/src/lib.rsmodified+6 -0
| @@ -337,6 +337,8 @@ impl From<TapButtonMap> for input::TapButtonMap { | |||
| 337 | pub struct Tablet { | 337 | pub struct Tablet { |
| 338 | #[knuffel(child)] | 338 | #[knuffel(child)] |
| 339 | pub off: bool, | 339 | pub off: bool, |
| 340 | + #[knuffel(child, unwrap(arguments))] | ||
| 341 | + pub calibration_matrix: Option<Vec<f32>>, | ||
| 340 | #[knuffel(child, unwrap(argument))] | 342 | #[knuffel(child, unwrap(argument))] |
| 341 | pub map_to_output: Option<String>, | 343 | pub map_to_output: Option<String>, |
| 342 | #[knuffel(child)] | 344 | #[knuffel(child)] |
| @@ -3560,6 +3562,8 @@ mod tests { | |||
| 3560 | 3562 | ||
| 3561 | tablet { | 3563 | tablet { |
| 3562 | map-to-output "eDP-1" | 3564 | map-to-output "eDP-1" |
| 3565 | + calibration-matrix 1.0 2.0 3.0 \ | ||
| 3566 | + 4.0 5.0 6.0 | ||
| 3563 | } | 3567 | } |
| 3564 | 3568 | ||
| 3565 | touch { | 3569 | touch { |
| @@ -3804,6 +3808,8 @@ mod tests { | |||
| 3804 | }, | 3808 | }, |
| 3805 | tablet: Tablet { | 3809 | tablet: Tablet { |
| 3806 | off: false, | 3810 | off: false, |
| 3811 | + calibration_matrix: Some(vec![1., 2., 3., | ||
| 3812 | + 4., 5., 6.]), | ||
| 3807 | map_to_output: Some("eDP-1".to_owned()), | 3813 | map_to_output: Some("eDP-1".to_owned()), |
| 3808 | left_handed: false, | 3814 | left_handed: false, |
| 3809 | }, | 3815 | }, |
src/input/mod.rsmodified+14 -0
| @@ -3451,6 +3451,20 @@ pub fn apply_libinput_settings(config: &niri_config::Input, device: &mut input:: | |||
| 3451 | } else { | 3451 | } else { |
| 3452 | input::SendEventsMode::ENABLED | 3452 | input::SendEventsMode::ENABLED |
| 3453 | }); | 3453 | }); |
| 3454 | + | ||
| 3455 | + #[rustfmt::skip] | ||
| 3456 | + const IDENTITY_MATRIX: [f32; 6] = [ | ||
| 3457 | + 1., 0., 0., | ||
| 3458 | + 0., 1., 0., | ||
| 3459 | + ]; | ||
| 3460 | + | ||
| 3461 | + let _ = device.config_calibration_set_matrix( | ||
| 3462 | + c.calibration_matrix | ||
| 3463 | + .as_deref() | ||
| 3464 | + .and_then(|m| m.try_into().ok()) | ||
| 3465 | + .or(device.config_calibration_default_matrix()) | ||
| 3466 | + .unwrap_or(IDENTITY_MATRIX), | ||
| 3467 | + ); | ||
| 3454 | let _ = device.config_left_handed_set(c.left_handed); | 3468 | let _ = device.config_left_handed_set(c.left_handed); |
| 3455 | } | 3469 | } |
| 3456 | } | 3470 | } |