Add scroll-button property for Touchpad, Mouse, Trackpoint, Trackball (#744)
Browse files at this commit4 changed files +87 -1
- niri-config/src/lib.rs +20 -0
- resources/default-config.kdl +10 -0
- src/input/mod.rs +54 -0
- wiki/Configuration:-Input.md +3 -1
niri-config/src/lib.rsmodified+20 -0
| @@ -176,6 +176,8 @@ pub struct Touchpad { | |||
| 176 | pub accel_profile: Option<AccelProfile>, | 176 | pub accel_profile: Option<AccelProfile>, |
| 177 | #[knuffel(child, unwrap(argument, str))] | 177 | #[knuffel(child, unwrap(argument, str))] |
| 178 | pub scroll_method: Option<ScrollMethod>, | 178 | pub scroll_method: Option<ScrollMethod>, |
| 179 | + #[knuffel(child, unwrap(argument))] | ||
| 180 | + pub scroll_button: Option<u32>, | ||
| 179 | #[knuffel(child, unwrap(argument, str))] | 181 | #[knuffel(child, unwrap(argument, str))] |
| 180 | pub tap_button_map: Option<TapButtonMap>, | 182 | pub tap_button_map: Option<TapButtonMap>, |
| 181 | #[knuffel(child)] | 183 | #[knuffel(child)] |
| @@ -198,6 +200,8 @@ pub struct Mouse { | |||
| 198 | pub accel_profile: Option<AccelProfile>, | 200 | pub accel_profile: Option<AccelProfile>, |
| 199 | #[knuffel(child, unwrap(argument, str))] | 201 | #[knuffel(child, unwrap(argument, str))] |
| 200 | pub scroll_method: Option<ScrollMethod>, | 202 | pub scroll_method: Option<ScrollMethod>, |
| 203 | + #[knuffel(child, unwrap(argument))] | ||
| 204 | + pub scroll_button: Option<u32>, | ||
| 201 | #[knuffel(child)] | 205 | #[knuffel(child)] |
| 202 | pub left_handed: bool, | 206 | pub left_handed: bool, |
| 203 | #[knuffel(child)] | 207 | #[knuffel(child)] |
| @@ -216,6 +220,8 @@ pub struct Trackpoint { | |||
| 216 | pub accel_profile: Option<AccelProfile>, | 220 | pub accel_profile: Option<AccelProfile>, |
| 217 | #[knuffel(child, unwrap(argument, str))] | 221 | #[knuffel(child, unwrap(argument, str))] |
| 218 | pub scroll_method: Option<ScrollMethod>, | 222 | pub scroll_method: Option<ScrollMethod>, |
| 223 | + #[knuffel(child, unwrap(argument))] | ||
| 224 | + pub scroll_button: Option<u32>, | ||
| 219 | #[knuffel(child)] | 225 | #[knuffel(child)] |
| 220 | pub middle_emulation: bool, | 226 | pub middle_emulation: bool, |
| 221 | } | 227 | } |
| @@ -230,6 +236,10 @@ pub struct Trackball { | |||
| 230 | pub accel_speed: f64, | 236 | pub accel_speed: f64, |
| 231 | #[knuffel(child, unwrap(argument, str))] | 237 | #[knuffel(child, unwrap(argument, str))] |
| 232 | pub accel_profile: Option<AccelProfile>, | 238 | pub accel_profile: Option<AccelProfile>, |
| 239 | + #[knuffel(child, unwrap(argument, str))] | ||
| 240 | + pub scroll_method: Option<ScrollMethod>, | ||
| 241 | + #[knuffel(child, unwrap(argument))] | ||
| 242 | + pub scroll_button: Option<u32>, | ||
| 233 | #[knuffel(child)] | 243 | #[knuffel(child)] |
| 234 | pub left_handed: bool, | 244 | pub left_handed: bool, |
| 235 | #[knuffel(child)] | 245 | #[knuffel(child)] |
| @@ -2902,6 +2912,7 @@ mod tests { | |||
| 2902 | accel-speed 0.2 | 2912 | accel-speed 0.2 |
| 2903 | accel-profile "flat" | 2913 | accel-profile "flat" |
| 2904 | scroll-method "two-finger" | 2914 | scroll-method "two-finger" |
| 2915 | + scroll-button 272 | ||
| 2905 | tap-button-map "left-middle-right" | 2916 | tap-button-map "left-middle-right" |
| 2906 | disabled-on-external-mouse | 2917 | disabled-on-external-mouse |
| 2907 | } | 2918 | } |
| @@ -2911,6 +2922,7 @@ mod tests { | |||
| 2911 | accel-speed 0.4 | 2922 | accel-speed 0.4 |
| 2912 | accel-profile "flat" | 2923 | accel-profile "flat" |
| 2913 | scroll-method "no-scroll" | 2924 | scroll-method "no-scroll" |
| 2925 | + scroll-button 273 | ||
| 2914 | middle-emulation | 2926 | middle-emulation |
| 2915 | } | 2927 | } |
| 2916 | 2928 | ||
| @@ -2920,6 +2932,7 @@ mod tests { | |||
| 2920 | accel-speed 0.0 | 2932 | accel-speed 0.0 |
| 2921 | accel-profile "flat" | 2933 | accel-profile "flat" |
| 2922 | scroll-method "on-button-down" | 2934 | scroll-method "on-button-down" |
| 2935 | + scroll-button 274 | ||
| 2923 | } | 2936 | } |
| 2924 | 2937 | ||
| 2925 | trackball { | 2938 | trackball { |
| @@ -2927,6 +2940,8 @@ mod tests { | |||
| 2927 | natural-scroll | 2940 | natural-scroll |
| 2928 | accel-speed 0.0 | 2941 | accel-speed 0.0 |
| 2929 | accel-profile "flat" | 2942 | accel-profile "flat" |
| 2943 | + scroll-method "edge" | ||
| 2944 | + scroll-button 275 | ||
| 2930 | left-handed | 2945 | left-handed |
| 2931 | middle-emulation | 2946 | middle-emulation |
| 2932 | } | 2947 | } |
| @@ -3096,6 +3111,7 @@ mod tests { | |||
| 3096 | accel_speed: 0.2, | 3111 | accel_speed: 0.2, |
| 3097 | accel_profile: Some(AccelProfile::Flat), | 3112 | accel_profile: Some(AccelProfile::Flat), |
| 3098 | scroll_method: Some(ScrollMethod::TwoFinger), | 3113 | scroll_method: Some(ScrollMethod::TwoFinger), |
| 3114 | + scroll_button: Some(272), | ||
| 3099 | tap_button_map: Some(TapButtonMap::LeftMiddleRight), | 3115 | tap_button_map: Some(TapButtonMap::LeftMiddleRight), |
| 3100 | left_handed: false, | 3116 | left_handed: false, |
| 3101 | disabled_on_external_mouse: true, | 3117 | disabled_on_external_mouse: true, |
| @@ -3107,6 +3123,7 @@ mod tests { | |||
| 3107 | accel_speed: 0.4, | 3123 | accel_speed: 0.4, |
| 3108 | accel_profile: Some(AccelProfile::Flat), | 3124 | accel_profile: Some(AccelProfile::Flat), |
| 3109 | scroll_method: Some(ScrollMethod::NoScroll), | 3125 | scroll_method: Some(ScrollMethod::NoScroll), |
| 3126 | + scroll_button: Some(273), | ||
| 3110 | left_handed: false, | 3127 | left_handed: false, |
| 3111 | middle_emulation: true, | 3128 | middle_emulation: true, |
| 3112 | }, | 3129 | }, |
| @@ -3116,6 +3133,7 @@ mod tests { | |||
| 3116 | accel_speed: 0.0, | 3133 | accel_speed: 0.0, |
| 3117 | accel_profile: Some(AccelProfile::Flat), | 3134 | accel_profile: Some(AccelProfile::Flat), |
| 3118 | scroll_method: Some(ScrollMethod::OnButtonDown), | 3135 | scroll_method: Some(ScrollMethod::OnButtonDown), |
| 3136 | + scroll_button: Some(274), | ||
| 3119 | middle_emulation: false, | 3137 | middle_emulation: false, |
| 3120 | }, | 3138 | }, |
| 3121 | trackball: Trackball { | 3139 | trackball: Trackball { |
| @@ -3123,6 +3141,8 @@ mod tests { | |||
| 3123 | natural_scroll: true, | 3141 | natural_scroll: true, |
| 3124 | accel_speed: 0.0, | 3142 | accel_speed: 0.0, |
| 3125 | accel_profile: Some(AccelProfile::Flat), | 3143 | accel_profile: Some(AccelProfile::Flat), |
| 3144 | + scroll_method: Some(ScrollMethod::Edge), | ||
| 3145 | + scroll_button: Some(275), | ||
| 3126 | left_handed: true, | 3146 | left_handed: true, |
| 3127 | middle_emulation: true, | 3147 | middle_emulation: true, |
| 3128 | }, | 3148 | }, |
resources/default-config.kdlmodified+10 -0
| @@ -40,6 +40,16 @@ input { | |||
| 40 | // scroll-method "no-scroll" | 40 | // scroll-method "no-scroll" |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | + trackpoint { | ||
| 44 | + // off | ||
| 45 | + // natural-scroll | ||
| 46 | + // accel-speed 0.2 | ||
| 47 | + // accel-profile "flat" | ||
| 48 | + // scroll-method "on-button-down" | ||
| 49 | + // scroll-button 273 | ||
| 50 | + // middle-emulation | ||
| 51 | + } | ||
| 52 | + | ||
| 43 | // Uncomment this to make the mouse warp to the center of newly focused windows. | 53 | // Uncomment this to make the mouse warp to the center of newly focused windows. |
| 44 | // warp-mouse-to-focus | 54 | // warp-mouse-to-focus |
| 45 | 55 | ||
src/input/mod.rsmodified+54 -0
| @@ -2657,8 +2657,20 @@ pub fn apply_libinput_settings(config: &niri_config::Input, device: &mut input:: | |||
| 2657 | 2657 | ||
| 2658 | if let Some(method) = c.scroll_method { | 2658 | if let Some(method) = c.scroll_method { |
| 2659 | let _ = device.config_scroll_set_method(method.into()); | 2659 | let _ = device.config_scroll_set_method(method.into()); |
| 2660 | + | ||
| 2661 | + if method == niri_config::ScrollMethod::OnButtonDown { | ||
| 2662 | + if let Some(button) = c.scroll_button { | ||
| 2663 | + let _ = device.config_scroll_set_button(button); | ||
| 2664 | + } | ||
| 2665 | + } | ||
| 2660 | } else if let Some(default) = device.config_scroll_default_method() { | 2666 | } else if let Some(default) = device.config_scroll_default_method() { |
| 2661 | let _ = device.config_scroll_set_method(default); | 2667 | let _ = device.config_scroll_set_method(default); |
| 2668 | + | ||
| 2669 | + if default == input::ScrollMethod::OnButtonDown { | ||
| 2670 | + if let Some(button) = c.scroll_button { | ||
| 2671 | + let _ = device.config_scroll_set_button(button); | ||
| 2672 | + } | ||
| 2673 | + } | ||
| 2662 | } | 2674 | } |
| 2663 | 2675 | ||
| 2664 | if let Some(tap_button_map) = c.tap_button_map { | 2676 | if let Some(tap_button_map) = c.tap_button_map { |
| @@ -2713,8 +2725,20 @@ pub fn apply_libinput_settings(config: &niri_config::Input, device: &mut input:: | |||
| 2713 | 2725 | ||
| 2714 | if let Some(method) = c.scroll_method { | 2726 | if let Some(method) = c.scroll_method { |
| 2715 | let _ = device.config_scroll_set_method(method.into()); | 2727 | let _ = device.config_scroll_set_method(method.into()); |
| 2728 | + | ||
| 2729 | + if method == niri_config::ScrollMethod::OnButtonDown { | ||
| 2730 | + if let Some(button) = c.scroll_button { | ||
| 2731 | + let _ = device.config_scroll_set_button(button); | ||
| 2732 | + } | ||
| 2733 | + } | ||
| 2716 | } else if let Some(default) = device.config_scroll_default_method() { | 2734 | } else if let Some(default) = device.config_scroll_default_method() { |
| 2717 | let _ = device.config_scroll_set_method(default); | 2735 | let _ = device.config_scroll_set_method(default); |
| 2736 | + | ||
| 2737 | + if default == input::ScrollMethod::OnButtonDown { | ||
| 2738 | + if let Some(button) = c.scroll_button { | ||
| 2739 | + let _ = device.config_scroll_set_button(button); | ||
| 2740 | + } | ||
| 2741 | + } | ||
| 2718 | } | 2742 | } |
| 2719 | } | 2743 | } |
| 2720 | 2744 | ||
| @@ -2735,6 +2759,24 @@ pub fn apply_libinput_settings(config: &niri_config::Input, device: &mut input:: | |||
| 2735 | } else if let Some(default) = device.config_accel_default_profile() { | 2759 | } else if let Some(default) = device.config_accel_default_profile() { |
| 2736 | let _ = device.config_accel_set_profile(default); | 2760 | let _ = device.config_accel_set_profile(default); |
| 2737 | } | 2761 | } |
| 2762 | + | ||
| 2763 | + if let Some(method) = c.scroll_method { | ||
| 2764 | + let _ = device.config_scroll_set_method(method.into()); | ||
| 2765 | + | ||
| 2766 | + if method == niri_config::ScrollMethod::OnButtonDown { | ||
| 2767 | + if let Some(button) = c.scroll_button { | ||
| 2768 | + let _ = device.config_scroll_set_button(button); | ||
| 2769 | + } | ||
| 2770 | + } | ||
| 2771 | + } else if let Some(default) = device.config_scroll_default_method() { | ||
| 2772 | + let _ = device.config_scroll_set_method(default); | ||
| 2773 | + | ||
| 2774 | + if default == input::ScrollMethod::OnButtonDown { | ||
| 2775 | + if let Some(button) = c.scroll_button { | ||
| 2776 | + let _ = device.config_scroll_set_button(button); | ||
| 2777 | + } | ||
| 2778 | + } | ||
| 2779 | + } | ||
| 2738 | } | 2780 | } |
| 2739 | 2781 | ||
| 2740 | if is_trackpoint { | 2782 | if is_trackpoint { |
| @@ -2756,8 +2798,20 @@ pub fn apply_libinput_settings(config: &niri_config::Input, device: &mut input:: | |||
| 2756 | 2798 | ||
| 2757 | if let Some(method) = c.scroll_method { | 2799 | if let Some(method) = c.scroll_method { |
| 2758 | let _ = device.config_scroll_set_method(method.into()); | 2800 | let _ = device.config_scroll_set_method(method.into()); |
| 2801 | + | ||
| 2802 | + if method == niri_config::ScrollMethod::OnButtonDown { | ||
| 2803 | + if let Some(button) = c.scroll_button { | ||
| 2804 | + let _ = device.config_scroll_set_button(button); | ||
| 2805 | + } | ||
| 2806 | + } | ||
| 2759 | } else if let Some(default) = device.config_scroll_default_method() { | 2807 | } else if let Some(default) = device.config_scroll_default_method() { |
| 2760 | let _ = device.config_scroll_set_method(default); | 2808 | let _ = device.config_scroll_set_method(default); |
| 2809 | + | ||
| 2810 | + if default == input::ScrollMethod::OnButtonDown { | ||
| 2811 | + if let Some(button) = c.scroll_button { | ||
| 2812 | + let _ = device.config_scroll_set_button(button); | ||
| 2813 | + } | ||
| 2814 | + } | ||
| 2761 | } | 2815 | } |
| 2762 | } | 2816 | } |
| 2763 | 2817 | ||
wiki/Configuration:-Input.mdmodified+3 -1
| @@ -56,6 +56,7 @@ input { | |||
| 56 | // accel-speed 0.2 | 56 | // accel-speed 0.2 |
| 57 | // accel-profile "flat" | 57 | // accel-profile "flat" |
| 58 | // scroll-method "on-button-down" | 58 | // scroll-method "on-button-down" |
| 59 | + // scroll-button 273 | ||
| 59 | // middle-emulation | 60 | // middle-emulation |
| 60 | } | 61 | } |
| 61 | 62 | ||
| @@ -134,13 +135,14 @@ A few settings are common between input devices: | |||
| 134 | 135 | ||
| 135 | - `off`: if set, no events will be sent from this device. | 136 | - `off`: if set, no events will be sent from this device. |
| 136 | 137 | ||
| 137 | -A few settings are common between `touchpad`, `mouse` and `trackpoint`: | 138 | +A few settings are common between `touchpad`, `mouse`, `trackpoint`, and `trackball`: |
| 138 | 139 | ||
| 139 | - `natural-scroll`: if set, inverts the scrolling direction. | 140 | - `natural-scroll`: if set, inverts the scrolling direction. |
| 140 | - `accel-speed`: pointer acceleration speed, valid values are from `-1.0` to `1.0` where the default is `0.0`. | 141 | - `accel-speed`: pointer acceleration speed, valid values are from `-1.0` to `1.0` where the default is `0.0`. |
| 141 | - `accel-profile`: can be `adaptive` (the default) or `flat` (disables pointer acceleration). | 142 | - `accel-profile`: can be `adaptive` (the default) or `flat` (disables pointer acceleration). |
| 142 | - `scroll-method`: when to generate scroll events instead of pointer motion events, can be `no-scroll`, `two-finger`, `edge`, or `on-button-down`. | 143 | - `scroll-method`: when to generate scroll events instead of pointer motion events, can be `no-scroll`, `two-finger`, `edge`, or `on-button-down`. |
| 143 | The default and supported methods vary depending on the device type. | 144 | The default and supported methods vary depending on the device type. |
| 145 | +- `scroll-button`: the button code used for the `on-button-down` scroll method. You can find it in `libinput debug-events`. | ||
| 144 | - `middle-emulation`: emulate a middle mouse click by pressing left and right mouse buttons at once. | 146 | - `middle-emulation`: emulate a middle mouse click by pressing left and right mouse buttons at once. |
| 145 | 147 | ||
| 146 | Settings specific to `touchpad`s: | 148 | Settings specific to `touchpad`s: |