Add `clickfinger` in touchpad config (#256)
Browse files at this commit3 changed files +40 -0
- niri-config/src/lib.rs +33 -0
- resources/default-config.kdl +1 -0
- src/input.rs +6 -0
niri-config/src/lib.rsmodified+33 -0
| @@ -142,6 +142,8 @@ pub struct Touchpad { | |||
| 142 | pub dwtp: bool, | 142 | pub dwtp: bool, |
| 143 | #[knuffel(child)] | 143 | #[knuffel(child)] |
| 144 | pub natural_scroll: bool, | 144 | pub natural_scroll: bool, |
| 145 | + #[knuffel(child, unwrap(argument, str))] | ||
| 146 | + pub click_method: Option<ClickMethod>, | ||
| 145 | #[knuffel(child, unwrap(argument), default)] | 147 | #[knuffel(child, unwrap(argument), default)] |
| 146 | pub accel_speed: f64, | 148 | pub accel_speed: f64, |
| 147 | #[knuffel(child, unwrap(argument, str))] | 149 | #[knuffel(child, unwrap(argument, str))] |
| @@ -170,6 +172,21 @@ pub struct Trackpoint { | |||
| 170 | pub accel_profile: Option<AccelProfile>, | 172 | pub accel_profile: Option<AccelProfile>, |
| 171 | } | 173 | } |
| 172 | 174 | ||
| 175 | +#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| 176 | +pub enum ClickMethod { | ||
| 177 | + Clickfinger, | ||
| 178 | + ButtonAreas, | ||
| 179 | +} | ||
| 180 | + | ||
| 181 | +impl From<ClickMethod> for input::ClickMethod { | ||
| 182 | + fn from(value: ClickMethod) -> Self { | ||
| 183 | + match value { | ||
| 184 | + ClickMethod::Clickfinger => Self::Clickfinger, | ||
| 185 | + ClickMethod::ButtonAreas => Self::ButtonAreas, | ||
| 186 | + } | ||
| 187 | + } | ||
| 188 | +} | ||
| 189 | + | ||
| 173 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 190 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 174 | pub enum AccelProfile { | 191 | pub enum AccelProfile { |
| 175 | Adaptive, | 192 | Adaptive, |
| @@ -1469,6 +1486,20 @@ impl FromStr for Key { | |||
| 1469 | } | 1486 | } |
| 1470 | } | 1487 | } |
| 1471 | 1488 | ||
| 1489 | +impl FromStr for ClickMethod { | ||
| 1490 | + type Err = miette::Error; | ||
| 1491 | + | ||
| 1492 | + fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
| 1493 | + match s { | ||
| 1494 | + "clickfinger" => Ok(Self::Clickfinger), | ||
| 1495 | + "button-areas" => Ok(Self::ButtonAreas), | ||
| 1496 | + _ => Err(miette!( | ||
| 1497 | + r#"invalid click method, can be "button-areas" or "clickfinger""# | ||
| 1498 | + )), | ||
| 1499 | + } | ||
| 1500 | + } | ||
| 1501 | +} | ||
| 1502 | + | ||
| 1472 | impl FromStr for AccelProfile { | 1503 | impl FromStr for AccelProfile { |
| 1473 | type Err = miette::Error; | 1504 | type Err = miette::Error; |
| 1474 | 1505 | ||
| @@ -1534,6 +1565,7 @@ mod tests { | |||
| 1534 | tap | 1565 | tap |
| 1535 | dwt | 1566 | dwt |
| 1536 | dwtp | 1567 | dwtp |
| 1568 | + click-method "clickfinger" | ||
| 1537 | accel-speed 0.2 | 1569 | accel-speed 0.2 |
| 1538 | accel-profile "flat" | 1570 | accel-profile "flat" |
| 1539 | tap-button-map "left-middle-right" | 1571 | tap-button-map "left-middle-right" |
| @@ -1676,6 +1708,7 @@ mod tests { | |||
| 1676 | tap: true, | 1708 | tap: true, |
| 1677 | dwt: true, | 1709 | dwt: true, |
| 1678 | dwtp: true, | 1710 | dwtp: true, |
| 1711 | + click_method: Some(ClickMethod::Clickfinger), | ||
| 1679 | natural_scroll: false, | 1712 | natural_scroll: false, |
| 1680 | accel_speed: 0.2, | 1713 | accel_speed: 0.2, |
| 1681 | accel_profile: Some(AccelProfile::Flat), | 1714 | accel_profile: Some(AccelProfile::Flat), |
resources/default-config.kdlmodified+1 -0
| @@ -33,6 +33,7 @@ input { | |||
| 33 | // accel-speed 0.2 | 33 | // accel-speed 0.2 |
| 34 | // accel-profile "flat" | 34 | // accel-profile "flat" |
| 35 | // tap-button-map "left-middle-right" | 35 | // tap-button-map "left-middle-right" |
| 36 | + // click-method "clickfinger" | ||
| 36 | } | 37 | } |
| 37 | 38 | ||
| 38 | mouse { | 39 | mouse { |
src/input.rsmodified+6 -0
| @@ -1774,6 +1774,12 @@ pub fn apply_libinput_settings(config: &niri_config::Input, device: &mut input:: | |||
| 1774 | } else if let Some(default) = device.config_tap_default_button_map() { | 1774 | } else if let Some(default) = device.config_tap_default_button_map() { |
| 1775 | let _ = device.config_tap_set_button_map(default); | 1775 | let _ = device.config_tap_set_button_map(default); |
| 1776 | } | 1776 | } |
| 1777 | + | ||
| 1778 | + if let Some(method) = c.click_method { | ||
| 1779 | + let _ = device.config_click_set_method(method.into()); | ||
| 1780 | + } else if let Some(default) = device.config_click_default_method() { | ||
| 1781 | + let _ = device.config_click_set_method(default); | ||
| 1782 | + } | ||
| 1777 | } | 1783 | } |
| 1778 | 1784 | ||
| 1779 | // This is how Mutter tells apart mice. | 1785 | // This is how Mutter tells apart mice. |