Add touchpad tap-button-map setting
Browse files at this commitc6841f19e9681e886afcfa136966174ab9cb028aParent: e1971c43 changed files +38 -0
- niri-config/src/lib.rs +33 -0
- resources/default-config.kdl +1 -0
- src/input.rs +4 -0
niri-config/src/lib.rsmodified+33 -0
| @@ -114,6 +114,8 @@ pub struct Touchpad { | |||
| 114 | pub accel_speed: f64, | 114 | pub accel_speed: f64, |
| 115 | #[knuffel(child, unwrap(argument, str))] | 115 | #[knuffel(child, unwrap(argument, str))] |
| 116 | pub accel_profile: Option<AccelProfile>, | 116 | pub accel_profile: Option<AccelProfile>, |
| 117 | + #[knuffel(child, unwrap(argument, str))] | ||
| 118 | + pub tap_button_map: Option<TapButtonMap>, | ||
| 117 | } | 119 | } |
| 118 | 120 | ||
| 119 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 121 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| @@ -131,6 +133,21 @@ impl From<AccelProfile> for input::AccelProfile { | |||
| 131 | } | 133 | } |
| 132 | } | 134 | } |
| 133 | 135 | ||
| 136 | +#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| 137 | +pub enum TapButtonMap { | ||
| 138 | + LeftRightMiddle, | ||
| 139 | + LeftMiddleRight, | ||
| 140 | +} | ||
| 141 | + | ||
| 142 | +impl From<TapButtonMap> for input::TapButtonMap { | ||
| 143 | + fn from(value: TapButtonMap) -> Self { | ||
| 144 | + match value { | ||
| 145 | + TapButtonMap::LeftRightMiddle => Self::LeftRightMiddle, | ||
| 146 | + TapButtonMap::LeftMiddleRight => Self::LeftMiddleRight, | ||
| 147 | + } | ||
| 148 | + } | ||
| 149 | +} | ||
| 150 | + | ||
| 134 | #[derive(knuffel::Decode, Debug, Default, PartialEq)] | 151 | #[derive(knuffel::Decode, Debug, Default, PartialEq)] |
| 135 | pub struct Tablet { | 152 | pub struct Tablet { |
| 136 | #[knuffel(child, unwrap(argument))] | 153 | #[knuffel(child, unwrap(argument))] |
| @@ -605,6 +622,20 @@ impl FromStr for AccelProfile { | |||
| 605 | } | 622 | } |
| 606 | } | 623 | } |
| 607 | 624 | ||
| 625 | +impl FromStr for TapButtonMap { | ||
| 626 | + type Err = miette::Error; | ||
| 627 | + | ||
| 628 | + fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
| 629 | + match s { | ||
| 630 | + "left-right-middle" => Ok(Self::LeftRightMiddle), | ||
| 631 | + "left-middle-right" => Ok(Self::LeftMiddleRight), | ||
| 632 | + _ => Err(miette!( | ||
| 633 | + r#"invalid tap button map, can be "left-right-middle" or "left-middle-right""# | ||
| 634 | + )), | ||
| 635 | + } | ||
| 636 | + } | ||
| 637 | +} | ||
| 638 | + | ||
| 608 | pub fn set_miette_hook() -> Result<(), miette::InstallError> { | 639 | pub fn set_miette_hook() -> Result<(), miette::InstallError> { |
| 609 | miette::set_hook(Box::new(|_| Box::new(NarratableReportHandler::new()))) | 640 | miette::set_hook(Box::new(|_| Box::new(NarratableReportHandler::new()))) |
| 610 | } | 641 | } |
| @@ -645,6 +676,7 @@ mod tests { | |||
| 645 | dwt | 676 | dwt |
| 646 | accel-speed 0.2 | 677 | accel-speed 0.2 |
| 647 | accel-profile "flat" | 678 | accel-profile "flat" |
| 679 | + tap-button-map "left-middle-right" | ||
| 648 | } | 680 | } |
| 649 | 681 | ||
| 650 | tablet { | 682 | tablet { |
| @@ -734,6 +766,7 @@ mod tests { | |||
| 734 | natural_scroll: false, | 766 | natural_scroll: false, |
| 735 | accel_speed: 0.2, | 767 | accel_speed: 0.2, |
| 736 | accel_profile: Some(AccelProfile::Flat), | 768 | accel_profile: Some(AccelProfile::Flat), |
| 769 | + tap_button_map: Some(TapButtonMap::LeftMiddleRight), | ||
| 737 | }, | 770 | }, |
| 738 | tablet: Tablet { | 771 | tablet: Tablet { |
| 739 | map_to_output: Some("eDP-1".to_owned()), | 772 | map_to_output: Some("eDP-1".to_owned()), |
resources/default-config.kdlmodified+1 -0
| @@ -31,6 +31,7 @@ input { | |||
| 31 | natural-scroll | 31 | natural-scroll |
| 32 | // accel-speed 0.2 | 32 | // accel-speed 0.2 |
| 33 | // accel-profile "flat" | 33 | // accel-profile "flat" |
| 34 | + // tap-button-map "left-middle-right" | ||
| 34 | } | 35 | } |
| 35 | 36 | ||
| 36 | tablet { | 37 | tablet { |
src/input.rsmodified+4 -0
| @@ -101,6 +101,10 @@ impl State { | |||
| 101 | if let Some(accel_profile) = c.accel_profile { | 101 | if let Some(accel_profile) = c.accel_profile { |
| 102 | let _ = device.config_accel_set_profile(accel_profile.into()); | 102 | let _ = device.config_accel_set_profile(accel_profile.into()); |
| 103 | } | 103 | } |
| 104 | + | ||
| 105 | + if let Some(tap_button_map) = c.tap_button_map { | ||
| 106 | + let _ = device.config_tap_set_button_map(tap_button_map.into()); | ||
| 107 | + } | ||
| 104 | } | 108 | } |
| 105 | 109 | ||
| 106 | if device.has_capability(input::DeviceCapability::TabletTool) { | 110 | if device.has_capability(input::DeviceCapability::TabletTool) { |