From cc83ff008d7500f38bce4e75c2dbcdfc1621cac4 Mon Sep 17 00:00:00 2001 From: "la .uetcis" Date: Wed, 13 Mar 2024 21:26:03 -0700 Subject: Add `clickfinger` in touchpad config (#256) * Add clickfinger in touchpad config * Change `clickfinger` to `click-method` * Change `bottom_areas` to `button_areas` * Change button_areas to button-areas For consistency. * Reorder click methods in error message The most usual one comes first. * default-config: Move click-method down --------- Co-authored-by: Ivan Molodetskikh --- niri-config/src/lib.rs | 33 +++++++++++++++++++++++++++++++++ resources/default-config.kdl | 1 + src/input.rs | 6 ++++++ 3 files changed, 40 insertions(+) diff --git a/niri-config/src/lib.rs b/niri-config/src/lib.rs index 6d104827..cad39c66 100644 --- a/niri-config/src/lib.rs +++ b/niri-config/src/lib.rs @@ -142,6 +142,8 @@ pub struct Touchpad { pub dwtp: bool, #[knuffel(child)] pub natural_scroll: bool, + #[knuffel(child, unwrap(argument, str))] + pub click_method: Option, #[knuffel(child, unwrap(argument), default)] pub accel_speed: f64, #[knuffel(child, unwrap(argument, str))] @@ -170,6 +172,21 @@ pub struct Trackpoint { pub accel_profile: Option, } +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum ClickMethod { + Clickfinger, + ButtonAreas, +} + +impl From for input::ClickMethod { + fn from(value: ClickMethod) -> Self { + match value { + ClickMethod::Clickfinger => Self::Clickfinger, + ClickMethod::ButtonAreas => Self::ButtonAreas, + } + } +} + #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum AccelProfile { Adaptive, @@ -1469,6 +1486,20 @@ impl FromStr for Key { } } +impl FromStr for ClickMethod { + type Err = miette::Error; + + fn from_str(s: &str) -> Result { + match s { + "clickfinger" => Ok(Self::Clickfinger), + "button-areas" => Ok(Self::ButtonAreas), + _ => Err(miette!( + r#"invalid click method, can be "button-areas" or "clickfinger""# + )), + } + } +} + impl FromStr for AccelProfile { type Err = miette::Error; @@ -1534,6 +1565,7 @@ mod tests { tap dwt dwtp + click-method "clickfinger" accel-speed 0.2 accel-profile "flat" tap-button-map "left-middle-right" @@ -1676,6 +1708,7 @@ mod tests { tap: true, dwt: true, dwtp: true, + click_method: Some(ClickMethod::Clickfinger), natural_scroll: false, accel_speed: 0.2, accel_profile: Some(AccelProfile::Flat), diff --git a/resources/default-config.kdl b/resources/default-config.kdl index e1ea0a2f..0567573b 100644 --- a/resources/default-config.kdl +++ b/resources/default-config.kdl @@ -33,6 +33,7 @@ input { // accel-speed 0.2 // accel-profile "flat" // tap-button-map "left-middle-right" + // click-method "clickfinger" } mouse { diff --git a/src/input.rs b/src/input.rs index 715d39c8..7f3e6fa7 100644 --- a/src/input.rs +++ b/src/input.rs @@ -1774,6 +1774,12 @@ pub fn apply_libinput_settings(config: &niri_config::Input, device: &mut input:: } else if let Some(default) = device.config_tap_default_button_map() { let _ = device.config_tap_set_button_map(default); } + + if let Some(method) = c.click_method { + let _ = device.config_click_set_method(method.into()); + } else if let Some(default) = device.config_click_default_method() { + let _ = device.config_click_set_method(default); + } } // This is how Mutter tells apart mice. -- cgit