Add scroll-method property to pointer devices
Browse files at this commit4746a0da7dffde6befcb3c80609fa3d31bffc29cParent: 2ac8d844 changed files +72 -0
- niri-config/src/lib.rs +47 -0
- resources/default-config.kdl +2 -0
- src/input/mod.rs +18 -0
- wiki/Configuration:-Input.md +5 -0
niri-config/src/lib.rsmodified+47 -0
| @@ -170,6 +170,8 @@ pub struct Touchpad { | |||
| 170 | #[knuffel(child, unwrap(argument, str))] | 170 | #[knuffel(child, unwrap(argument, str))] |
| 171 | pub accel_profile: Option<AccelProfile>, | 171 | pub accel_profile: Option<AccelProfile>, |
| 172 | #[knuffel(child, unwrap(argument, str))] | 172 | #[knuffel(child, unwrap(argument, str))] |
| 173 | + pub scroll_method: Option<ScrollMethod>, | ||
| 174 | + #[knuffel(child, unwrap(argument, str))] | ||
| 173 | pub tap_button_map: Option<TapButtonMap>, | 175 | pub tap_button_map: Option<TapButtonMap>, |
| 174 | #[knuffel(child)] | 176 | #[knuffel(child)] |
| 175 | pub left_handed: bool, | 177 | pub left_handed: bool, |
| @@ -183,6 +185,8 @@ pub struct Mouse { | |||
| 183 | pub accel_speed: f64, | 185 | pub accel_speed: f64, |
| 184 | #[knuffel(child, unwrap(argument, str))] | 186 | #[knuffel(child, unwrap(argument, str))] |
| 185 | pub accel_profile: Option<AccelProfile>, | 187 | pub accel_profile: Option<AccelProfile>, |
| 188 | + #[knuffel(child, unwrap(argument, str))] | ||
| 189 | + pub scroll_method: Option<ScrollMethod>, | ||
| 186 | #[knuffel(child)] | 190 | #[knuffel(child)] |
| 187 | pub left_handed: bool, | 191 | pub left_handed: bool, |
| 188 | } | 192 | } |
| @@ -195,6 +199,8 @@ pub struct Trackpoint { | |||
| 195 | pub accel_speed: f64, | 199 | pub accel_speed: f64, |
| 196 | #[knuffel(child, unwrap(argument, str))] | 200 | #[knuffel(child, unwrap(argument, str))] |
| 197 | pub accel_profile: Option<AccelProfile>, | 201 | pub accel_profile: Option<AccelProfile>, |
| 202 | + #[knuffel(child, unwrap(argument, str))] | ||
| 203 | + pub scroll_method: Option<ScrollMethod>, | ||
| 198 | } | 204 | } |
| 199 | 205 | ||
| 200 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 206 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| @@ -227,6 +233,25 @@ impl From<AccelProfile> for input::AccelProfile { | |||
| 227 | } | 233 | } |
| 228 | } | 234 | } |
| 229 | 235 | ||
| 236 | +#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| 237 | +pub enum ScrollMethod { | ||
| 238 | + NoScroll, | ||
| 239 | + TwoFinger, | ||
| 240 | + Edge, | ||
| 241 | + OnButtonDown, | ||
| 242 | +} | ||
| 243 | + | ||
| 244 | +impl From<ScrollMethod> for input::ScrollMethod { | ||
| 245 | + fn from(value: ScrollMethod) -> Self { | ||
| 246 | + match value { | ||
| 247 | + ScrollMethod::NoScroll => Self::NoScroll, | ||
| 248 | + ScrollMethod::TwoFinger => Self::TwoFinger, | ||
| 249 | + ScrollMethod::Edge => Self::Edge, | ||
| 250 | + ScrollMethod::OnButtonDown => Self::OnButtonDown, | ||
| 251 | + } | ||
| 252 | + } | ||
| 253 | +} | ||
| 254 | + | ||
| 230 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 255 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 231 | pub enum TapButtonMap { | 256 | pub enum TapButtonMap { |
| 232 | LeftRightMiddle, | 257 | LeftRightMiddle, |
| @@ -2245,6 +2270,22 @@ impl FromStr for AccelProfile { | |||
| 2245 | } | 2270 | } |
| 2246 | } | 2271 | } |
| 2247 | 2272 | ||
| 2273 | +impl FromStr for ScrollMethod { | ||
| 2274 | + type Err = miette::Error; | ||
| 2275 | + | ||
| 2276 | + fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
| 2277 | + match s { | ||
| 2278 | + "no-scroll" => Ok(Self::NoScroll), | ||
| 2279 | + "two-finger" => Ok(Self::TwoFinger), | ||
| 2280 | + "edge" => Ok(Self::Edge), | ||
| 2281 | + "on-button-down" => Ok(Self::OnButtonDown), | ||
| 2282 | + _ => Err(miette!( | ||
| 2283 | + r#"invalid scroll method, can be "no-scroll" or "two-finger", "edge", or "on-button-down""# | ||
| 2284 | + )), | ||
| 2285 | + } | ||
| 2286 | + } | ||
| 2287 | +} | ||
| 2288 | + | ||
| 2248 | impl FromStr for TapButtonMap { | 2289 | impl FromStr for TapButtonMap { |
| 2249 | type Err = miette::Error; | 2290 | type Err = miette::Error; |
| 2250 | 2291 | ||
| @@ -2299,6 +2340,7 @@ mod tests { | |||
| 2299 | click-method "clickfinger" | 2340 | click-method "clickfinger" |
| 2300 | accel-speed 0.2 | 2341 | accel-speed 0.2 |
| 2301 | accel-profile "flat" | 2342 | accel-profile "flat" |
| 2343 | + scroll-method "two-finger" | ||
| 2302 | tap-button-map "left-middle-right" | 2344 | tap-button-map "left-middle-right" |
| 2303 | } | 2345 | } |
| 2304 | 2346 | ||
| @@ -2306,12 +2348,14 @@ mod tests { | |||
| 2306 | natural-scroll | 2348 | natural-scroll |
| 2307 | accel-speed 0.4 | 2349 | accel-speed 0.4 |
| 2308 | accel-profile "flat" | 2350 | accel-profile "flat" |
| 2351 | + scroll-method "no-scroll" | ||
| 2309 | } | 2352 | } |
| 2310 | 2353 | ||
| 2311 | trackpoint { | 2354 | trackpoint { |
| 2312 | natural-scroll | 2355 | natural-scroll |
| 2313 | accel-speed 0.0 | 2356 | accel-speed 0.0 |
| 2314 | accel-profile "flat" | 2357 | accel-profile "flat" |
| 2358 | + scroll-method "on-button-down" | ||
| 2315 | } | 2359 | } |
| 2316 | 2360 | ||
| 2317 | tablet { | 2361 | tablet { |
| @@ -2467,6 +2511,7 @@ mod tests { | |||
| 2467 | natural_scroll: false, | 2511 | natural_scroll: false, |
| 2468 | accel_speed: 0.2, | 2512 | accel_speed: 0.2, |
| 2469 | accel_profile: Some(AccelProfile::Flat), | 2513 | accel_profile: Some(AccelProfile::Flat), |
| 2514 | + scroll_method: Some(ScrollMethod::TwoFinger), | ||
| 2470 | tap_button_map: Some(TapButtonMap::LeftMiddleRight), | 2515 | tap_button_map: Some(TapButtonMap::LeftMiddleRight), |
| 2471 | left_handed: false, | 2516 | left_handed: false, |
| 2472 | }, | 2517 | }, |
| @@ -2474,12 +2519,14 @@ mod tests { | |||
| 2474 | natural_scroll: true, | 2519 | natural_scroll: true, |
| 2475 | accel_speed: 0.4, | 2520 | accel_speed: 0.4, |
| 2476 | accel_profile: Some(AccelProfile::Flat), | 2521 | accel_profile: Some(AccelProfile::Flat), |
| 2522 | + scroll_method: Some(ScrollMethod::NoScroll), | ||
| 2477 | left_handed: false, | 2523 | left_handed: false, |
| 2478 | }, | 2524 | }, |
| 2479 | trackpoint: Trackpoint { | 2525 | trackpoint: Trackpoint { |
| 2480 | natural_scroll: true, | 2526 | natural_scroll: true, |
| 2481 | accel_speed: 0.0, | 2527 | accel_speed: 0.0, |
| 2482 | accel_profile: Some(AccelProfile::Flat), | 2528 | accel_profile: Some(AccelProfile::Flat), |
| 2529 | + scroll_method: Some(ScrollMethod::OnButtonDown), | ||
| 2483 | }, | 2530 | }, |
| 2484 | tablet: Tablet { | 2531 | tablet: Tablet { |
| 2485 | map_to_output: Some("eDP-1".to_owned()), | 2532 | map_to_output: Some("eDP-1".to_owned()), |
resources/default-config.kdlmodified+2 -0
| @@ -27,12 +27,14 @@ input { | |||
| 27 | natural-scroll | 27 | natural-scroll |
| 28 | // accel-speed 0.2 | 28 | // accel-speed 0.2 |
| 29 | // accel-profile "flat" | 29 | // accel-profile "flat" |
| 30 | + // scroll-method "two-finger" | ||
| 30 | } | 31 | } |
| 31 | 32 | ||
| 32 | mouse { | 33 | mouse { |
| 33 | // natural-scroll | 34 | // natural-scroll |
| 34 | // accel-speed 0.2 | 35 | // accel-speed 0.2 |
| 35 | // accel-profile "flat" | 36 | // accel-profile "flat" |
| 37 | + // scroll-method "no-scroll" | ||
| 36 | } | 38 | } |
| 37 | 39 | ||
| 38 | // Uncomment this to make the mouse warp to the center of newly focused windows. | 40 | // Uncomment this to make the mouse warp to the center of newly focused windows. |
src/input/mod.rsmodified+18 -0
| @@ -2232,6 +2232,12 @@ pub fn apply_libinput_settings(config: &niri_config::Input, device: &mut input:: | |||
| 2232 | let _ = device.config_accel_set_profile(default); | 2232 | let _ = device.config_accel_set_profile(default); |
| 2233 | } | 2233 | } |
| 2234 | 2234 | ||
| 2235 | + if let Some(method) = c.scroll_method { | ||
| 2236 | + let _ = device.config_scroll_set_method(method.into()); | ||
| 2237 | + } else if let Some(default) = device.config_scroll_default_method() { | ||
| 2238 | + let _ = device.config_scroll_set_method(default); | ||
| 2239 | + } | ||
| 2240 | + | ||
| 2235 | if let Some(tap_button_map) = c.tap_button_map { | 2241 | if let Some(tap_button_map) = c.tap_button_map { |
| 2236 | let _ = device.config_tap_set_button_map(tap_button_map.into()); | 2242 | let _ = device.config_tap_set_button_map(tap_button_map.into()); |
| 2237 | } else if let Some(default) = device.config_tap_default_button_map() { | 2243 | } else if let Some(default) = device.config_tap_default_button_map() { |
| @@ -2275,6 +2281,12 @@ pub fn apply_libinput_settings(config: &niri_config::Input, device: &mut input:: | |||
| 2275 | } else if let Some(default) = device.config_accel_default_profile() { | 2281 | } else if let Some(default) = device.config_accel_default_profile() { |
| 2276 | let _ = device.config_accel_set_profile(default); | 2282 | let _ = device.config_accel_set_profile(default); |
| 2277 | } | 2283 | } |
| 2284 | + | ||
| 2285 | + if let Some(method) = c.scroll_method { | ||
| 2286 | + let _ = device.config_scroll_set_method(method.into()); | ||
| 2287 | + } else if let Some(default) = device.config_scroll_default_method() { | ||
| 2288 | + let _ = device.config_scroll_set_method(default); | ||
| 2289 | + } | ||
| 2278 | } | 2290 | } |
| 2279 | 2291 | ||
| 2280 | if is_trackpoint { | 2292 | if is_trackpoint { |
| @@ -2287,6 +2299,12 @@ pub fn apply_libinput_settings(config: &niri_config::Input, device: &mut input:: | |||
| 2287 | } else if let Some(default) = device.config_accel_default_profile() { | 2299 | } else if let Some(default) = device.config_accel_default_profile() { |
| 2288 | let _ = device.config_accel_set_profile(default); | 2300 | let _ = device.config_accel_set_profile(default); |
| 2289 | } | 2301 | } |
| 2302 | + | ||
| 2303 | + if let Some(method) = c.scroll_method { | ||
| 2304 | + let _ = device.config_scroll_set_method(method.into()); | ||
| 2305 | + } else if let Some(default) = device.config_scroll_default_method() { | ||
| 2306 | + let _ = device.config_scroll_set_method(default); | ||
| 2307 | + } | ||
| 2290 | } | 2308 | } |
| 2291 | 2309 | ||
| 2292 | let is_tablet = device.has_capability(input::DeviceCapability::TabletTool); | 2310 | let is_tablet = device.has_capability(input::DeviceCapability::TabletTool); |
wiki/Configuration:-Input.mdmodified+5 -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 | + // scroll-method "two-finger" | ||
| 34 | // tap-button-map "left-middle-right" | 35 | // tap-button-map "left-middle-right" |
| 35 | // click-method "clickfinger" | 36 | // click-method "clickfinger" |
| 36 | // left-handed | 37 | // left-handed |
| @@ -40,6 +41,7 @@ input { | |||
| 40 | // natural-scroll | 41 | // natural-scroll |
| 41 | // accel-speed 0.2 | 42 | // accel-speed 0.2 |
| 42 | // accel-profile "flat" | 43 | // accel-profile "flat" |
| 44 | + // scroll-method "no-scroll" | ||
| 43 | // left-handed | 45 | // left-handed |
| 44 | } | 46 | } |
| 45 | 47 | ||
| @@ -47,6 +49,7 @@ input { | |||
| 47 | // natural-scroll | 49 | // natural-scroll |
| 48 | // accel-speed 0.2 | 50 | // accel-speed 0.2 |
| 49 | // accel-profile "flat" | 51 | // accel-profile "flat" |
| 52 | + // scroll-method "on-button-down" | ||
| 50 | } | 53 | } |
| 51 | 54 | ||
| 52 | tablet { | 55 | tablet { |
| @@ -124,6 +127,8 @@ A few settings are common between `touchpad`, `mouse` and `trackpoint`: | |||
| 124 | - `natural-scroll`: if set, inverts the scrolling direction. | 127 | - `natural-scroll`: if set, inverts the scrolling direction. |
| 125 | - `accel-speed`: pointer acceleration speed, valid values are from `-1.0` to `1.0` where the default is `0.0`. | 128 | - `accel-speed`: pointer acceleration speed, valid values are from `-1.0` to `1.0` where the default is `0.0`. |
| 126 | - `accel-profile`: can be `adaptive` (the default) or `flat` (disables pointer acceleration). | 129 | - `accel-profile`: can be `adaptive` (the default) or `flat` (disables pointer acceleration). |
| 130 | +- `scroll-method`: when to generate scroll events instead of pointer motion events, can be `no-scroll`, `two-finger`, `edge`, or `on-button-down`. | ||
| 131 | + The default and supported methods vary depending on the device type. | ||
| 127 | 132 | ||
| 128 | Settings specific to `touchpad`s: | 133 | Settings specific to `touchpad`s: |
| 129 | 134 | ||