diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2024-01-08 10:32:04 +0400 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2024-01-08 10:32:04 +0400 |
| commit | c6841f19e9681e886afcfa136966174ab9cb028a (patch) | |
| tree | 6aae09de57282e8498e78f49d58238fe02095c7f | |
| parent | e1971c4af5761d043e0fcef57b2cc9d8311fec00 (diff) | |
| download | niri-c6841f19e9681e886afcfa136966174ab9cb028a.tar.gz niri-c6841f19e9681e886afcfa136966174ab9cb028a.tar.bz2 niri-c6841f19e9681e886afcfa136966174ab9cb028a.zip | |
Add touchpad tap-button-map setting
| -rw-r--r-- | niri-config/src/lib.rs | 33 | ||||
| -rw-r--r-- | resources/default-config.kdl | 1 | ||||
| -rw-r--r-- | src/input.rs | 4 |
3 files changed, 38 insertions, 0 deletions
diff --git a/niri-config/src/lib.rs b/niri-config/src/lib.rs index 8d0eb8e6..2fe2b56d 100644 --- a/niri-config/src/lib.rs +++ b/niri-config/src/lib.rs @@ -114,6 +114,8 @@ pub struct Touchpad { pub accel_speed: f64, #[knuffel(child, unwrap(argument, str))] pub accel_profile: Option<AccelProfile>, + #[knuffel(child, unwrap(argument, str))] + pub tap_button_map: Option<TapButtonMap>, } #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -131,6 +133,21 @@ impl From<AccelProfile> for input::AccelProfile { } } +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum TapButtonMap { + LeftRightMiddle, + LeftMiddleRight, +} + +impl From<TapButtonMap> for input::TapButtonMap { + fn from(value: TapButtonMap) -> Self { + match value { + TapButtonMap::LeftRightMiddle => Self::LeftRightMiddle, + TapButtonMap::LeftMiddleRight => Self::LeftMiddleRight, + } + } +} + #[derive(knuffel::Decode, Debug, Default, PartialEq)] pub struct Tablet { #[knuffel(child, unwrap(argument))] @@ -605,6 +622,20 @@ impl FromStr for AccelProfile { } } +impl FromStr for TapButtonMap { + type Err = miette::Error; + + fn from_str(s: &str) -> Result<Self, Self::Err> { + match s { + "left-right-middle" => Ok(Self::LeftRightMiddle), + "left-middle-right" => Ok(Self::LeftMiddleRight), + _ => Err(miette!( + r#"invalid tap button map, can be "left-right-middle" or "left-middle-right""# + )), + } + } +} + pub fn set_miette_hook() -> Result<(), miette::InstallError> { miette::set_hook(Box::new(|_| Box::new(NarratableReportHandler::new()))) } @@ -645,6 +676,7 @@ mod tests { dwt accel-speed 0.2 accel-profile "flat" + tap-button-map "left-middle-right" } tablet { @@ -734,6 +766,7 @@ mod tests { natural_scroll: false, accel_speed: 0.2, accel_profile: Some(AccelProfile::Flat), + tap_button_map: Some(TapButtonMap::LeftMiddleRight), }, tablet: Tablet { map_to_output: Some("eDP-1".to_owned()), diff --git a/resources/default-config.kdl b/resources/default-config.kdl index 13bb9d35..c97229bc 100644 --- a/resources/default-config.kdl +++ b/resources/default-config.kdl @@ -31,6 +31,7 @@ input { natural-scroll // accel-speed 0.2 // accel-profile "flat" + // tap-button-map "left-middle-right" } tablet { diff --git a/src/input.rs b/src/input.rs index 9dc10189..2692726f 100644 --- a/src/input.rs +++ b/src/input.rs @@ -101,6 +101,10 @@ impl State { if let Some(accel_profile) = c.accel_profile { let _ = device.config_accel_set_profile(accel_profile.into()); } + + if let Some(tap_button_map) = c.tap_button_map { + let _ = device.config_tap_set_button_map(tap_button_map.into()); + } } if device.has_capability(input::DeviceCapability::TabletTool) { |
