forge
Explore
Log in

Don't you dare go Hollow

Add scroll-method property to pointer devices

Browse files at this commit

4746a0da7dffde6befcb3c80609fa3d31bffc29cYuya NishiharaParent: 2ac8d84
My use case is to enable middle-button scroll on my keyboard with pointing
stick. The device is recognized as USB mouse.
niri-config/src/lib.rsmodified+47 -0
@@ -170,6 +170,8 @@ pub struct Touchpad {
170170 #[knuffel(child, unwrap(argument, str))]
171171 pub accel_profile: Option<AccelProfile>,
172172 #[knuffel(child, unwrap(argument, str))]
173+ pub scroll_method: Option<ScrollMethod>,
174+ #[knuffel(child, unwrap(argument, str))]
173175 pub tap_button_map: Option<TapButtonMap>,
174176 #[knuffel(child)]
175177 pub left_handed: bool,
@@ -183,6 +185,8 @@ pub struct Mouse {
183185 pub accel_speed: f64,
184186 #[knuffel(child, unwrap(argument, str))]
185187 pub accel_profile: Option<AccelProfile>,
188+ #[knuffel(child, unwrap(argument, str))]
189+ pub scroll_method: Option<ScrollMethod>,
186190 #[knuffel(child)]
187191 pub left_handed: bool,
188192 }
@@ -195,6 +199,8 @@ pub struct Trackpoint {
195199 pub accel_speed: f64,
196200 #[knuffel(child, unwrap(argument, str))]
197201 pub accel_profile: Option<AccelProfile>,
202+ #[knuffel(child, unwrap(argument, str))]
203+ pub scroll_method: Option<ScrollMethod>,
198204 }
199205
200206 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -227,6 +233,25 @@ impl From<AccelProfile> for input::AccelProfile {
227233 }
228234 }
229235
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+
230255 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
231256 pub enum TapButtonMap {
232257 LeftRightMiddle,
@@ -2245,6 +2270,22 @@ impl FromStr for AccelProfile {
22452270 }
22462271 }
22472272
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+
22482289 impl FromStr for TapButtonMap {
22492290 type Err = miette::Error;
22502291
@@ -2299,6 +2340,7 @@ mod tests {
22992340 click-method "clickfinger"
23002341 accel-speed 0.2
23012342 accel-profile "flat"
2343+ scroll-method "two-finger"
23022344 tap-button-map "left-middle-right"
23032345 }
23042346
@@ -2306,12 +2348,14 @@ mod tests {
23062348 natural-scroll
23072349 accel-speed 0.4
23082350 accel-profile "flat"
2351+ scroll-method "no-scroll"
23092352 }
23102353
23112354 trackpoint {
23122355 natural-scroll
23132356 accel-speed 0.0
23142357 accel-profile "flat"
2358+ scroll-method "on-button-down"
23152359 }
23162360
23172361 tablet {
@@ -2467,6 +2511,7 @@ mod tests {
24672511 natural_scroll: false,
24682512 accel_speed: 0.2,
24692513 accel_profile: Some(AccelProfile::Flat),
2514+ scroll_method: Some(ScrollMethod::TwoFinger),
24702515 tap_button_map: Some(TapButtonMap::LeftMiddleRight),
24712516 left_handed: false,
24722517 },
@@ -2474,12 +2519,14 @@ mod tests {
24742519 natural_scroll: true,
24752520 accel_speed: 0.4,
24762521 accel_profile: Some(AccelProfile::Flat),
2522+ scroll_method: Some(ScrollMethod::NoScroll),
24772523 left_handed: false,
24782524 },
24792525 trackpoint: Trackpoint {
24802526 natural_scroll: true,
24812527 accel_speed: 0.0,
24822528 accel_profile: Some(AccelProfile::Flat),
2529+ scroll_method: Some(ScrollMethod::OnButtonDown),
24832530 },
24842531 tablet: Tablet {
24852532 map_to_output: Some("eDP-1".to_owned()),
resources/default-config.kdlmodified+2 -0
@@ -27,12 +27,14 @@ input {
2727 natural-scroll
2828 // accel-speed 0.2
2929 // accel-profile "flat"
30+ // scroll-method "two-finger"
3031 }
3132
3233 mouse {
3334 // natural-scroll
3435 // accel-speed 0.2
3536 // accel-profile "flat"
37+ // scroll-method "no-scroll"
3638 }
3739
3840 // 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::
22322232 let _ = device.config_accel_set_profile(default);
22332233 }
22342234
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+
22352241 if let Some(tap_button_map) = c.tap_button_map {
22362242 let _ = device.config_tap_set_button_map(tap_button_map.into());
22372243 } 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::
22752281 } else if let Some(default) = device.config_accel_default_profile() {
22762282 let _ = device.config_accel_set_profile(default);
22772283 }
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+ }
22782290 }
22792291
22802292 if is_trackpoint {
@@ -2287,6 +2299,12 @@ pub fn apply_libinput_settings(config: &niri_config::Input, device: &mut input::
22872299 } else if let Some(default) = device.config_accel_default_profile() {
22882300 let _ = device.config_accel_set_profile(default);
22892301 }
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+ }
22902308 }
22912309
22922310 let is_tablet = device.has_capability(input::DeviceCapability::TabletTool);
wiki/Configuration:-Input.mdmodified+5 -0
@@ -31,6 +31,7 @@ input {
3131 natural-scroll
3232 // accel-speed 0.2
3333 // accel-profile "flat"
34+ // scroll-method "two-finger"
3435 // tap-button-map "left-middle-right"
3536 // click-method "clickfinger"
3637 // left-handed
@@ -40,6 +41,7 @@ input {
4041 // natural-scroll
4142 // accel-speed 0.2
4243 // accel-profile "flat"
44+ // scroll-method "no-scroll"
4345 // left-handed
4446 }
4547
@@ -47,6 +49,7 @@ input {
4749 // natural-scroll
4850 // accel-speed 0.2
4951 // accel-profile "flat"
52+ // scroll-method "on-button-down"
5053 }
5154
5255 tablet {
@@ -124,6 +127,8 @@ A few settings are common between `touchpad`, `mouse` and `trackpoint`:
124127 - `natural-scroll`: if set, inverts the scrolling direction.
125128 - `accel-speed`: pointer acceleration speed, valid values are from `-1.0` to `1.0` where the default is `0.0`.
126129 - `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.
127132
128133 Settings specific to `touchpad`s:
129134