diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2024-01-08 10:15:29 +0400 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2024-01-08 10:23:53 +0400 |
| commit | 07b1d0e98d736c3e1095345f42ee787985f223f7 (patch) | |
| tree | f513676b6063cf6e031a5478ff74d3db0810e481 | |
| parent | ffe25f5cc4755dfc8e0dc41cd0845cd7d185f3cc (diff) | |
| download | niri-07b1d0e98d736c3e1095345f42ee787985f223f7.tar.gz niri-07b1d0e98d736c3e1095345f42ee787985f223f7.tar.bz2 niri-07b1d0e98d736c3e1095345f42ee787985f223f7.zip | |
Add touchpad accel-profile setting
| -rw-r--r-- | niri-config/src/lib.rs | 34 | ||||
| -rw-r--r-- | resources/default-config.kdl | 1 | ||||
| -rw-r--r-- | src/input.rs | 4 |
3 files changed, 39 insertions, 0 deletions
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<AccelProfile>, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum AccelProfile { + Adaptive, + Flat, +} + +impl From<AccelProfile> 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<Self, Self::Err> { + 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) { |
