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 | 170 | #[knuffel(child, unwrap(argument, str))] |
| 171 | 171 | pub accel_profile: Option<AccelProfile>, |
| 172 | 172 | #[knuffel(child, unwrap(argument, str))] |
| 173 | + pub scroll_method: Option<ScrollMethod>, | |
| 174 | + #[knuffel(child, unwrap(argument, str))] | |
| 173 | 175 | pub tap_button_map: Option<TapButtonMap>, |
| 174 | 176 | #[knuffel(child)] |
| 175 | 177 | pub left_handed: bool, |
| @@ -183,6 +185,8 @@ pub struct Mouse { | ||
| 183 | 185 | pub accel_speed: f64, |
| 184 | 186 | #[knuffel(child, unwrap(argument, str))] |
| 185 | 187 | pub accel_profile: Option<AccelProfile>, |
| 188 | + #[knuffel(child, unwrap(argument, str))] | |
| 189 | + pub scroll_method: Option<ScrollMethod>, | |
| 186 | 190 | #[knuffel(child)] |
| 187 | 191 | pub left_handed: bool, |
| 188 | 192 | } |
| @@ -195,6 +199,8 @@ pub struct Trackpoint { | ||
| 195 | 199 | pub accel_speed: f64, |
| 196 | 200 | #[knuffel(child, unwrap(argument, str))] |
| 197 | 201 | pub accel_profile: Option<AccelProfile>, |
| 202 | + #[knuffel(child, unwrap(argument, str))] | |
| 203 | + pub scroll_method: Option<ScrollMethod>, | |
| 198 | 204 | } |
| 199 | 205 | |
| 200 | 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 | 255 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 231 | 256 | pub enum TapButtonMap { |
| 232 | 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 | 2289 | impl FromStr for TapButtonMap { |
| 2249 | 2290 | type Err = miette::Error; |
| 2250 | 2291 | |
| @@ -2299,6 +2340,7 @@ mod tests { | ||
| 2299 | 2340 | click-method "clickfinger" |
| 2300 | 2341 | accel-speed 0.2 |
| 2301 | 2342 | accel-profile "flat" |
| 2343 | + scroll-method "two-finger" | |
| 2302 | 2344 | tap-button-map "left-middle-right" |
| 2303 | 2345 | } |
| 2304 | 2346 | |
| @@ -2306,12 +2348,14 @@ mod tests { | ||
| 2306 | 2348 | natural-scroll |
| 2307 | 2349 | accel-speed 0.4 |
| 2308 | 2350 | accel-profile "flat" |
| 2351 | + scroll-method "no-scroll" | |
| 2309 | 2352 | } |
| 2310 | 2353 | |
| 2311 | 2354 | trackpoint { |
| 2312 | 2355 | natural-scroll |
| 2313 | 2356 | accel-speed 0.0 |
| 2314 | 2357 | accel-profile "flat" |
| 2358 | + scroll-method "on-button-down" | |
| 2315 | 2359 | } |
| 2316 | 2360 | |
| 2317 | 2361 | tablet { |
| @@ -2467,6 +2511,7 @@ mod tests { | ||
| 2467 | 2511 | natural_scroll: false, |
| 2468 | 2512 | accel_speed: 0.2, |
| 2469 | 2513 | accel_profile: Some(AccelProfile::Flat), |
| 2514 | + scroll_method: Some(ScrollMethod::TwoFinger), | |
| 2470 | 2515 | tap_button_map: Some(TapButtonMap::LeftMiddleRight), |
| 2471 | 2516 | left_handed: false, |
| 2472 | 2517 | }, |
| @@ -2474,12 +2519,14 @@ mod tests { | ||
| 2474 | 2519 | natural_scroll: true, |
| 2475 | 2520 | accel_speed: 0.4, |
| 2476 | 2521 | accel_profile: Some(AccelProfile::Flat), |
| 2522 | + scroll_method: Some(ScrollMethod::NoScroll), | |
| 2477 | 2523 | left_handed: false, |
| 2478 | 2524 | }, |
| 2479 | 2525 | trackpoint: Trackpoint { |
| 2480 | 2526 | natural_scroll: true, |
| 2481 | 2527 | accel_speed: 0.0, |
| 2482 | 2528 | accel_profile: Some(AccelProfile::Flat), |
| 2529 | + scroll_method: Some(ScrollMethod::OnButtonDown), | |
| 2483 | 2530 | }, |
| 2484 | 2531 | tablet: Tablet { |
| 2485 | 2532 | map_to_output: Some("eDP-1".to_owned()), |
resources/default-config.kdlmodified+2 -0
| @@ -27,12 +27,14 @@ input { | ||
| 27 | 27 | natural-scroll |
| 28 | 28 | // accel-speed 0.2 |
| 29 | 29 | // accel-profile "flat" |
| 30 | + // scroll-method "two-finger" | |
| 30 | 31 | } |
| 31 | 32 | |
| 32 | 33 | mouse { |
| 33 | 34 | // natural-scroll |
| 34 | 35 | // accel-speed 0.2 |
| 35 | 36 | // accel-profile "flat" |
| 37 | + // scroll-method "no-scroll" | |
| 36 | 38 | } |
| 37 | 39 | |
| 38 | 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 | 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 | 2241 | if let Some(tap_button_map) = c.tap_button_map { |
| 2236 | 2242 | let _ = device.config_tap_set_button_map(tap_button_map.into()); |
| 2237 | 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 | 2281 | } else if let Some(default) = device.config_accel_default_profile() { |
| 2276 | 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 | 2292 | if is_trackpoint { |
| @@ -2287,6 +2299,12 @@ pub fn apply_libinput_settings(config: &niri_config::Input, device: &mut input:: | ||
| 2287 | 2299 | } else if let Some(default) = device.config_accel_default_profile() { |
| 2288 | 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 | 2310 | let is_tablet = device.has_capability(input::DeviceCapability::TabletTool); |
wiki/Configuration:-Input.mdmodified+5 -0
| @@ -31,6 +31,7 @@ input { | ||
| 31 | 31 | natural-scroll |
| 32 | 32 | // accel-speed 0.2 |
| 33 | 33 | // accel-profile "flat" |
| 34 | + // scroll-method "two-finger" | |
| 34 | 35 | // tap-button-map "left-middle-right" |
| 35 | 36 | // click-method "clickfinger" |
| 36 | 37 | // left-handed |
| @@ -40,6 +41,7 @@ input { | ||
| 40 | 41 | // natural-scroll |
| 41 | 42 | // accel-speed 0.2 |
| 42 | 43 | // accel-profile "flat" |
| 44 | + // scroll-method "no-scroll" | |
| 43 | 45 | // left-handed |
| 44 | 46 | } |
| 45 | 47 | |
| @@ -47,6 +49,7 @@ input { | ||
| 47 | 49 | // natural-scroll |
| 48 | 50 | // accel-speed 0.2 |
| 49 | 51 | // accel-profile "flat" |
| 52 | + // scroll-method "on-button-down" | |
| 50 | 53 | } |
| 51 | 54 | |
| 52 | 55 | tablet { |
| @@ -124,6 +127,8 @@ A few settings are common between `touchpad`, `mouse` and `trackpoint`: | ||
| 124 | 127 | - `natural-scroll`: if set, inverts the scrolling direction. |
| 125 | 128 | - `accel-speed`: pointer acceleration speed, valid values are from `-1.0` to `1.0` where the default is `0.0`. |
| 126 | 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 | 133 | Settings specific to `touchpad`s: |
| 129 | 134 |