Add "off" and "disabled-on-external-mouse" properties to input devices
Browse files at this commitc8e46b9d172dfa2ca89d82b87055b8e39622f80cParent: f2ce84b4 changed files +52 -0
- niri-config/src/lib.rs +17 -0
- resources/default-config.kdl +3 -0
- src/input/mod.rs +22 -0
- wiki/Configuration:-Input.md +10 -0
niri-config/src/lib.rsmodified+17 -0
| @@ -155,6 +155,8 @@ pub enum TrackLayout { | |||
| 155 | // FIXME: Add the rest of the settings. | 155 | // FIXME: Add the rest of the settings. |
| 156 | #[derive(knuffel::Decode, Debug, Default, PartialEq)] | 156 | #[derive(knuffel::Decode, Debug, Default, PartialEq)] |
| 157 | pub struct Touchpad { | 157 | pub struct Touchpad { |
| 158 | + #[knuffel(child)] | ||
| 159 | + pub off: bool, | ||
| 158 | #[knuffel(child)] | 160 | #[knuffel(child)] |
| 159 | pub tap: bool, | 161 | pub tap: bool, |
| 160 | #[knuffel(child)] | 162 | #[knuffel(child)] |
| @@ -175,10 +177,14 @@ pub struct Touchpad { | |||
| 175 | pub tap_button_map: Option<TapButtonMap>, | 177 | pub tap_button_map: Option<TapButtonMap>, |
| 176 | #[knuffel(child)] | 178 | #[knuffel(child)] |
| 177 | pub left_handed: bool, | 179 | pub left_handed: bool, |
| 180 | + #[knuffel(child)] | ||
| 181 | + pub disabled_on_external_mouse: bool, | ||
| 178 | } | 182 | } |
| 179 | 183 | ||
| 180 | #[derive(knuffel::Decode, Debug, Default, PartialEq)] | 184 | #[derive(knuffel::Decode, Debug, Default, PartialEq)] |
| 181 | pub struct Mouse { | 185 | pub struct Mouse { |
| 186 | + #[knuffel(child)] | ||
| 187 | + pub off: bool, | ||
| 182 | #[knuffel(child)] | 188 | #[knuffel(child)] |
| 183 | pub natural_scroll: bool, | 189 | pub natural_scroll: bool, |
| 184 | #[knuffel(child, unwrap(argument), default)] | 190 | #[knuffel(child, unwrap(argument), default)] |
| @@ -193,6 +199,8 @@ pub struct Mouse { | |||
| 193 | 199 | ||
| 194 | #[derive(knuffel::Decode, Debug, Default, PartialEq)] | 200 | #[derive(knuffel::Decode, Debug, Default, PartialEq)] |
| 195 | pub struct Trackpoint { | 201 | pub struct Trackpoint { |
| 202 | + #[knuffel(child)] | ||
| 203 | + pub off: bool, | ||
| 196 | #[knuffel(child)] | 204 | #[knuffel(child)] |
| 197 | pub natural_scroll: bool, | 205 | pub natural_scroll: bool, |
| 198 | #[knuffel(child, unwrap(argument), default)] | 206 | #[knuffel(child, unwrap(argument), default)] |
| @@ -269,6 +277,8 @@ impl From<TapButtonMap> for input::TapButtonMap { | |||
| 269 | 277 | ||
| 270 | #[derive(knuffel::Decode, Debug, Default, PartialEq)] | 278 | #[derive(knuffel::Decode, Debug, Default, PartialEq)] |
| 271 | pub struct Tablet { | 279 | pub struct Tablet { |
| 280 | + #[knuffel(child)] | ||
| 281 | + pub off: bool, | ||
| 272 | #[knuffel(child, unwrap(argument))] | 282 | #[knuffel(child, unwrap(argument))] |
| 273 | pub map_to_output: Option<String>, | 283 | pub map_to_output: Option<String>, |
| 274 | #[knuffel(child)] | 284 | #[knuffel(child)] |
| @@ -2342,6 +2352,7 @@ mod tests { | |||
| 2342 | accel-profile "flat" | 2352 | accel-profile "flat" |
| 2343 | scroll-method "two-finger" | 2353 | scroll-method "two-finger" |
| 2344 | tap-button-map "left-middle-right" | 2354 | tap-button-map "left-middle-right" |
| 2355 | + disabled-on-external-mouse | ||
| 2345 | } | 2356 | } |
| 2346 | 2357 | ||
| 2347 | mouse { | 2358 | mouse { |
| @@ -2352,6 +2363,7 @@ mod tests { | |||
| 2352 | } | 2363 | } |
| 2353 | 2364 | ||
| 2354 | trackpoint { | 2365 | trackpoint { |
| 2366 | + off | ||
| 2355 | natural-scroll | 2367 | natural-scroll |
| 2356 | accel-speed 0.0 | 2368 | accel-speed 0.0 |
| 2357 | accel-profile "flat" | 2369 | accel-profile "flat" |
| @@ -2504,6 +2516,7 @@ mod tests { | |||
| 2504 | track_layout: TrackLayout::Window, | 2516 | track_layout: TrackLayout::Window, |
| 2505 | }, | 2517 | }, |
| 2506 | touchpad: Touchpad { | 2518 | touchpad: Touchpad { |
| 2519 | + off: false, | ||
| 2507 | tap: true, | 2520 | tap: true, |
| 2508 | dwt: true, | 2521 | dwt: true, |
| 2509 | dwtp: true, | 2522 | dwtp: true, |
| @@ -2514,8 +2527,10 @@ mod tests { | |||
| 2514 | scroll_method: Some(ScrollMethod::TwoFinger), | 2527 | scroll_method: Some(ScrollMethod::TwoFinger), |
| 2515 | tap_button_map: Some(TapButtonMap::LeftMiddleRight), | 2528 | tap_button_map: Some(TapButtonMap::LeftMiddleRight), |
| 2516 | left_handed: false, | 2529 | left_handed: false, |
| 2530 | + disabled_on_external_mouse: true, | ||
| 2517 | }, | 2531 | }, |
| 2518 | mouse: Mouse { | 2532 | mouse: Mouse { |
| 2533 | + off: false, | ||
| 2519 | natural_scroll: true, | 2534 | natural_scroll: true, |
| 2520 | accel_speed: 0.4, | 2535 | accel_speed: 0.4, |
| 2521 | accel_profile: Some(AccelProfile::Flat), | 2536 | accel_profile: Some(AccelProfile::Flat), |
| @@ -2523,12 +2538,14 @@ mod tests { | |||
| 2523 | left_handed: false, | 2538 | left_handed: false, |
| 2524 | }, | 2539 | }, |
| 2525 | trackpoint: Trackpoint { | 2540 | trackpoint: Trackpoint { |
| 2541 | + off: true, | ||
| 2526 | natural_scroll: true, | 2542 | natural_scroll: true, |
| 2527 | accel_speed: 0.0, | 2543 | accel_speed: 0.0, |
| 2528 | accel_profile: Some(AccelProfile::Flat), | 2544 | accel_profile: Some(AccelProfile::Flat), |
| 2529 | scroll_method: Some(ScrollMethod::OnButtonDown), | 2545 | scroll_method: Some(ScrollMethod::OnButtonDown), |
| 2530 | }, | 2546 | }, |
| 2531 | tablet: Tablet { | 2547 | tablet: Tablet { |
| 2548 | + off: false, | ||
| 2532 | map_to_output: Some("eDP-1".to_owned()), | 2549 | map_to_output: Some("eDP-1".to_owned()), |
| 2533 | left_handed: false, | 2550 | left_handed: false, |
| 2534 | }, | 2551 | }, |
resources/default-config.kdlmodified+3 -0
| @@ -21,6 +21,7 @@ input { | |||
| 21 | // Next sections include libinput settings. | 21 | // Next sections include libinput settings. |
| 22 | // Omitting settings disables them, or leaves them at their default values. | 22 | // Omitting settings disables them, or leaves them at their default values. |
| 23 | touchpad { | 23 | touchpad { |
| 24 | + // off | ||
| 24 | tap | 25 | tap |
| 25 | // dwt | 26 | // dwt |
| 26 | // dwtp | 27 | // dwtp |
| @@ -28,9 +29,11 @@ input { | |||
| 28 | // accel-speed 0.2 | 29 | // accel-speed 0.2 |
| 29 | // accel-profile "flat" | 30 | // accel-profile "flat" |
| 30 | // scroll-method "two-finger" | 31 | // scroll-method "two-finger" |
| 32 | + // disabled-on-external-mouse | ||
| 31 | } | 33 | } |
| 32 | 34 | ||
| 33 | mouse { | 35 | mouse { |
| 36 | + // off | ||
| 34 | // natural-scroll | 37 | // natural-scroll |
| 35 | // accel-speed 0.2 | 38 | // accel-speed 0.2 |
| 36 | // accel-profile "flat" | 39 | // accel-profile "flat" |
src/input/mod.rsmodified+22 -0
| @@ -2219,6 +2219,13 @@ pub fn apply_libinput_settings(config: &niri_config::Input, device: &mut input:: | |||
| 2219 | let is_touchpad = device.config_tap_finger_count() > 0; | 2219 | let is_touchpad = device.config_tap_finger_count() > 0; |
| 2220 | if is_touchpad { | 2220 | if is_touchpad { |
| 2221 | let c = &config.touchpad; | 2221 | let c = &config.touchpad; |
| 2222 | + let _ = device.config_send_events_set_mode(if c.off { | ||
| 2223 | + input::SendEventsMode::DISABLED | ||
| 2224 | + } else if c.disabled_on_external_mouse { | ||
| 2225 | + input::SendEventsMode::DISABLED_ON_EXTERNAL_MOUSE | ||
| 2226 | + } else { | ||
| 2227 | + input::SendEventsMode::ENABLED | ||
| 2228 | + }); | ||
| 2222 | let _ = device.config_tap_set_enabled(c.tap); | 2229 | let _ = device.config_tap_set_enabled(c.tap); |
| 2223 | let _ = device.config_dwt_set_enabled(c.dwt); | 2230 | let _ = device.config_dwt_set_enabled(c.dwt); |
| 2224 | let _ = device.config_dwtp_set_enabled(c.dwtp); | 2231 | let _ = device.config_dwtp_set_enabled(c.dwtp); |
| @@ -2272,6 +2279,11 @@ pub fn apply_libinput_settings(config: &niri_config::Input, device: &mut input:: | |||
| 2272 | && !is_trackpoint; | 2279 | && !is_trackpoint; |
| 2273 | if is_mouse { | 2280 | if is_mouse { |
| 2274 | let c = &config.mouse; | 2281 | let c = &config.mouse; |
| 2282 | + let _ = device.config_send_events_set_mode(if c.off { | ||
| 2283 | + input::SendEventsMode::DISABLED | ||
| 2284 | + } else { | ||
| 2285 | + input::SendEventsMode::ENABLED | ||
| 2286 | + }); | ||
| 2275 | let _ = device.config_scroll_set_natural_scroll_enabled(c.natural_scroll); | 2287 | let _ = device.config_scroll_set_natural_scroll_enabled(c.natural_scroll); |
| 2276 | let _ = device.config_accel_set_speed(c.accel_speed); | 2288 | let _ = device.config_accel_set_speed(c.accel_speed); |
| 2277 | let _ = device.config_left_handed_set(c.left_handed); | 2289 | let _ = device.config_left_handed_set(c.left_handed); |
| @@ -2291,6 +2303,11 @@ pub fn apply_libinput_settings(config: &niri_config::Input, device: &mut input:: | |||
| 2291 | 2303 | ||
| 2292 | if is_trackpoint { | 2304 | if is_trackpoint { |
| 2293 | let c = &config.trackpoint; | 2305 | let c = &config.trackpoint; |
| 2306 | + let _ = device.config_send_events_set_mode(if c.off { | ||
| 2307 | + input::SendEventsMode::DISABLED | ||
| 2308 | + } else { | ||
| 2309 | + input::SendEventsMode::ENABLED | ||
| 2310 | + }); | ||
| 2294 | let _ = device.config_scroll_set_natural_scroll_enabled(c.natural_scroll); | 2311 | let _ = device.config_scroll_set_natural_scroll_enabled(c.natural_scroll); |
| 2295 | let _ = device.config_accel_set_speed(c.accel_speed); | 2312 | let _ = device.config_accel_set_speed(c.accel_speed); |
| 2296 | 2313 | ||
| @@ -2310,6 +2327,11 @@ pub fn apply_libinput_settings(config: &niri_config::Input, device: &mut input:: | |||
| 2310 | let is_tablet = device.has_capability(input::DeviceCapability::TabletTool); | 2327 | let is_tablet = device.has_capability(input::DeviceCapability::TabletTool); |
| 2311 | if is_tablet { | 2328 | if is_tablet { |
| 2312 | let c = &config.tablet; | 2329 | let c = &config.tablet; |
| 2330 | + let _ = device.config_send_events_set_mode(if c.off { | ||
| 2331 | + input::SendEventsMode::DISABLED | ||
| 2332 | + } else { | ||
| 2333 | + input::SendEventsMode::ENABLED | ||
| 2334 | + }); | ||
| 2313 | let _ = device.config_left_handed_set(c.left_handed); | 2335 | let _ = device.config_left_handed_set(c.left_handed); |
| 2314 | } | 2336 | } |
| 2315 | } | 2337 | } |
wiki/Configuration:-Input.mdmodified+10 -0
| @@ -25,6 +25,7 @@ input { | |||
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | touchpad { | 27 | touchpad { |
| 28 | + // off | ||
| 28 | tap | 29 | tap |
| 29 | // dwt | 30 | // dwt |
| 30 | // dwtp | 31 | // dwtp |
| @@ -35,9 +36,11 @@ input { | |||
| 35 | // tap-button-map "left-middle-right" | 36 | // tap-button-map "left-middle-right" |
| 36 | // click-method "clickfinger" | 37 | // click-method "clickfinger" |
| 37 | // left-handed | 38 | // left-handed |
| 39 | + // disabled-on-external-mouse | ||
| 38 | } | 40 | } |
| 39 | 41 | ||
| 40 | mouse { | 42 | mouse { |
| 43 | + // off | ||
| 41 | // natural-scroll | 44 | // natural-scroll |
| 42 | // accel-speed 0.2 | 45 | // accel-speed 0.2 |
| 43 | // accel-profile "flat" | 46 | // accel-profile "flat" |
| @@ -46,6 +49,7 @@ input { | |||
| 46 | } | 49 | } |
| 47 | 50 | ||
| 48 | trackpoint { | 51 | trackpoint { |
| 52 | + // off | ||
| 49 | // natural-scroll | 53 | // natural-scroll |
| 50 | // accel-speed 0.2 | 54 | // accel-speed 0.2 |
| 51 | // accel-profile "flat" | 55 | // accel-profile "flat" |
| @@ -53,6 +57,7 @@ input { | |||
| 53 | } | 57 | } |
| 54 | 58 | ||
| 55 | tablet { | 59 | tablet { |
| 60 | + // off | ||
| 56 | map-to-output "eDP-1" | 61 | map-to-output "eDP-1" |
| 57 | // left-handed | 62 | // left-handed |
| 58 | } | 63 | } |
| @@ -122,6 +127,10 @@ Most settings for the pointing devices are passed directly to libinput. | |||
| 122 | Other Wayland compositors also use libinput, so it's likely you will find the same settings there. | 127 | Other Wayland compositors also use libinput, so it's likely you will find the same settings there. |
| 123 | For flags like `tap`, omit them or comment them out to disable the setting. | 128 | For flags like `tap`, omit them or comment them out to disable the setting. |
| 124 | 129 | ||
| 130 | +A few settings are common between input devices: | ||
| 131 | + | ||
| 132 | +- `off`: if set, no events will be sent from this device. | ||
| 133 | + | ||
| 125 | A few settings are common between `touchpad`, `mouse` and `trackpoint`: | 134 | A few settings are common between `touchpad`, `mouse` and `trackpoint`: |
| 126 | 135 | ||
| 127 | - `natural-scroll`: if set, inverts the scrolling direction. | 136 | - `natural-scroll`: if set, inverts the scrolling direction. |
| @@ -137,6 +146,7 @@ Settings specific to `touchpad`s: | |||
| 137 | - `dwtp`: disable-when-trackpointing. | 146 | - `dwtp`: disable-when-trackpointing. |
| 138 | - `tap-button-map`: can be `left-right-middle` or `left-middle-right`, controls which button corresponds to a two-finger tap and a three-finger tap. | 147 | - `tap-button-map`: can be `left-right-middle` or `left-middle-right`, controls which button corresponds to a two-finger tap and a three-finger tap. |
| 139 | - `click-method`: can be `button-areas` or `clickfinger`, changes the [click method](https://wayland.freedesktop.org/libinput/doc/latest/clickpad-softbuttons.html). | 148 | - `click-method`: can be `button-areas` or `clickfinger`, changes the [click method](https://wayland.freedesktop.org/libinput/doc/latest/clickpad-softbuttons.html). |
| 149 | +- `disabled-on-external-mouse`: do not send events while external pointer device is plugged in. | ||
| 140 | 150 | ||
| 141 | Settings specific to `touchpad`, `mouse` and `tablet`: | 151 | Settings specific to `touchpad`, `mouse` and `tablet`: |
| 142 | 152 | ||