From 9e794f358b7d44b4e04346dffbd684b2860d6fcc Mon Sep 17 00:00:00 2001 From: Ivan Chinenov Date: Fri, 14 Feb 2025 08:15:45 +0300 Subject: feat: support for setting tablet calibration matrix; this allows for rotating tablet inputs (#1122) * feat: support for setting tablet calibration matrix * Change default matrix --- niri-config/src/lib.rs | 6 ++++++ src/input/mod.rs | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/niri-config/src/lib.rs b/niri-config/src/lib.rs index 4520d75c..6a9fb682 100644 --- a/niri-config/src/lib.rs +++ b/niri-config/src/lib.rs @@ -337,6 +337,8 @@ impl From for input::TapButtonMap { pub struct Tablet { #[knuffel(child)] pub off: bool, + #[knuffel(child, unwrap(arguments))] + pub calibration_matrix: Option>, #[knuffel(child, unwrap(argument))] pub map_to_output: Option, #[knuffel(child)] @@ -3560,6 +3562,8 @@ mod tests { tablet { map-to-output "eDP-1" + calibration-matrix 1.0 2.0 3.0 \ + 4.0 5.0 6.0 } touch { @@ -3804,6 +3808,8 @@ mod tests { }, tablet: Tablet { off: false, + calibration_matrix: Some(vec![1., 2., 3., + 4., 5., 6.]), map_to_output: Some("eDP-1".to_owned()), left_handed: false, }, diff --git a/src/input/mod.rs b/src/input/mod.rs index 8d9e6d82..a2931b85 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -3451,6 +3451,20 @@ pub fn apply_libinput_settings(config: &niri_config::Input, device: &mut input:: } else { input::SendEventsMode::ENABLED }); + + #[rustfmt::skip] + const IDENTITY_MATRIX: [f32; 6] = [ + 1., 0., 0., + 0., 1., 0., + ]; + + let _ = device.config_calibration_set_matrix( + c.calibration_matrix + .as_deref() + .and_then(|m| m.try_into().ok()) + .or(device.config_calibration_default_matrix()) + .unwrap_or(IDENTITY_MATRIX), + ); let _ = device.config_left_handed_set(c.left_handed); } } -- cgit