From 07b1d0e98d736c3e1095345f42ee787985f223f7 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Mon, 8 Jan 2024 10:15:29 +0400 Subject: Add touchpad accel-profile setting --- niri-config/src/lib.rs | 34 ++++++++++++++++++++++++++++++++++ resources/default-config.kdl | 1 + src/input.rs | 4 ++++ 3 files changed, 39 insertions(+) diff --git a/niri-config/src/lib.rs b/niri-config/src/lib.rs index 19f6d036..38ff1749 100644 --- a/niri-config/src/lib.rs +++ b/niri-config/src/lib.rs @@ -10,6 +10,7 @@ use miette::{miette, Context, IntoDiagnostic, NarratableReportHandler}; use smithay::input::keyboard::keysyms::KEY_NoSymbol; use smithay::input::keyboard::xkb::{keysym_from_name, KEYSYM_CASE_INSENSITIVE}; use smithay::input::keyboard::{Keysym, XkbConfig}; +use smithay::reexports::input; #[derive(knuffel::Decode, Debug, PartialEq)] pub struct Config { @@ -109,6 +110,23 @@ pub struct Touchpad { pub natural_scroll: bool, #[knuffel(child, unwrap(argument), default)] pub accel_speed: f64, + #[knuffel(child, unwrap(argument, str))] + pub accel_profile: Option, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum AccelProfile { + Adaptive, + Flat, +} + +impl From for input::AccelProfile { + fn from(value: AccelProfile) -> Self { + match value { + AccelProfile::Adaptive => Self::Adaptive, + AccelProfile::Flat => Self::Flat, + } + } } #[derive(knuffel::Decode, Debug, Default, PartialEq)] @@ -571,6 +589,20 @@ impl FromStr for SizeChange { } } +impl FromStr for AccelProfile { + type Err = miette::Error; + + fn from_str(s: &str) -> Result { + match s { + "adaptive" => Ok(Self::Adaptive), + "flat" => Ok(Self::Flat), + _ => Err(miette!( + r#"invalid accel profile, can be "adaptive" or "flat""# + )), + } + } +} + pub fn set_miette_hook() -> Result<(), miette::InstallError> { miette::set_hook(Box::new(|_| Box::new(NarratableReportHandler::new()))) } @@ -609,6 +641,7 @@ mod tests { touchpad { tap accel-speed 0.2 + accel-profile "flat" } tablet { @@ -696,6 +729,7 @@ mod tests { tap: true, natural_scroll: false, accel_speed: 0.2, + accel_profile: Some(AccelProfile::Flat), }, tablet: Tablet { map_to_output: Some("eDP-1".to_owned()), diff --git a/resources/default-config.kdl b/resources/default-config.kdl index 5babfb41..8ad00df9 100644 --- a/resources/default-config.kdl +++ b/resources/default-config.kdl @@ -29,6 +29,7 @@ input { tap natural-scroll // accel-speed 0.2 + // accel-profile "flat" } tablet { diff --git a/src/input.rs b/src/input.rs index d0a3df7e..07252447 100644 --- a/src/input.rs +++ b/src/input.rs @@ -96,6 +96,10 @@ impl State { let _ = device.config_tap_set_enabled(c.tap); let _ = device.config_scroll_set_natural_scroll_enabled(c.natural_scroll); let _ = device.config_accel_set_speed(c.accel_speed); + + if let Some(accel_profile) = c.accel_profile { + let _ = device.config_accel_set_profile(accel_profile.into()); + } } if device.has_capability(input::DeviceCapability::TabletTool) { -- cgit