Add touchpad accel-profile setting

This commit is contained in:
Ivan Molodetskikh
2024-01-08 10:15:29 +04:00
parent ffe25f5cc4
commit 07b1d0e98d
3 changed files with 39 additions and 0 deletions
+34
View File
@@ -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()),
+1
View File
@@ -29,6 +29,7 @@ input {
tap
natural-scroll
// accel-speed 0.2
// accel-profile "flat"
}
tablet {
+4
View File
@@ -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) {