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 | 155 | // FIXME: Add the rest of the settings. |
| 156 | 156 | #[derive(knuffel::Decode, Debug, Default, PartialEq)] |
| 157 | 157 | pub struct Touchpad { |
| 158 | + #[knuffel(child)] | |
| 159 | + pub off: bool, | |
| 158 | 160 | #[knuffel(child)] |
| 159 | 161 | pub tap: bool, |
| 160 | 162 | #[knuffel(child)] |
| @@ -175,10 +177,14 @@ pub struct Touchpad { | ||
| 175 | 177 | pub tap_button_map: Option<TapButtonMap>, |
| 176 | 178 | #[knuffel(child)] |
| 177 | 179 | pub left_handed: bool, |
| 180 | + #[knuffel(child)] | |
| 181 | + pub disabled_on_external_mouse: bool, | |
| 178 | 182 | } |
| 179 | 183 | |
| 180 | 184 | #[derive(knuffel::Decode, Debug, Default, PartialEq)] |
| 181 | 185 | pub struct Mouse { |
| 186 | + #[knuffel(child)] | |
| 187 | + pub off: bool, | |
| 182 | 188 | #[knuffel(child)] |
| 183 | 189 | pub natural_scroll: bool, |
| 184 | 190 | #[knuffel(child, unwrap(argument), default)] |
| @@ -193,6 +199,8 @@ pub struct Mouse { | ||
| 193 | 199 | |
| 194 | 200 | #[derive(knuffel::Decode, Debug, Default, PartialEq)] |
| 195 | 201 | pub struct Trackpoint { |
| 202 | + #[knuffel(child)] | |
| 203 | + pub off: bool, | |
| 196 | 204 | #[knuffel(child)] |
| 197 | 205 | pub natural_scroll: bool, |
| 198 | 206 | #[knuffel(child, unwrap(argument), default)] |
| @@ -269,6 +277,8 @@ impl From<TapButtonMap> for input::TapButtonMap { | ||
| 269 | 277 | |
| 270 | 278 | #[derive(knuffel::Decode, Debug, Default, PartialEq)] |
| 271 | 279 | pub struct Tablet { |
| 280 | + #[knuffel(child)] | |
| 281 | + pub off: bool, | |
| 272 | 282 | #[knuffel(child, unwrap(argument))] |
| 273 | 283 | pub map_to_output: Option<String>, |
| 274 | 284 | #[knuffel(child)] |
| @@ -2342,6 +2352,7 @@ mod tests { | ||
| 2342 | 2352 | accel-profile "flat" |
| 2343 | 2353 | scroll-method "two-finger" |
| 2344 | 2354 | tap-button-map "left-middle-right" |
| 2355 | + disabled-on-external-mouse | |
| 2345 | 2356 | } |
| 2346 | 2357 | |
| 2347 | 2358 | mouse { |
| @@ -2352,6 +2363,7 @@ mod tests { | ||
| 2352 | 2363 | } |
| 2353 | 2364 | |
| 2354 | 2365 | trackpoint { |
| 2366 | + off | |
| 2355 | 2367 | natural-scroll |
| 2356 | 2368 | accel-speed 0.0 |
| 2357 | 2369 | accel-profile "flat" |
| @@ -2504,6 +2516,7 @@ mod tests { | ||
| 2504 | 2516 | track_layout: TrackLayout::Window, |
| 2505 | 2517 | }, |
| 2506 | 2518 | touchpad: Touchpad { |
| 2519 | + off: false, | |
| 2507 | 2520 | tap: true, |
| 2508 | 2521 | dwt: true, |
| 2509 | 2522 | dwtp: true, |
| @@ -2514,8 +2527,10 @@ mod tests { | ||
| 2514 | 2527 | scroll_method: Some(ScrollMethod::TwoFinger), |
| 2515 | 2528 | tap_button_map: Some(TapButtonMap::LeftMiddleRight), |
| 2516 | 2529 | left_handed: false, |
| 2530 | + disabled_on_external_mouse: true, | |
| 2517 | 2531 | }, |
| 2518 | 2532 | mouse: Mouse { |
| 2533 | + off: false, | |
| 2519 | 2534 | natural_scroll: true, |
| 2520 | 2535 | accel_speed: 0.4, |
| 2521 | 2536 | accel_profile: Some(AccelProfile::Flat), |
| @@ -2523,12 +2538,14 @@ mod tests { | ||
| 2523 | 2538 | left_handed: false, |
| 2524 | 2539 | }, |
| 2525 | 2540 | trackpoint: Trackpoint { |
| 2541 | + off: true, | |
| 2526 | 2542 | natural_scroll: true, |
| 2527 | 2543 | accel_speed: 0.0, |
| 2528 | 2544 | accel_profile: Some(AccelProfile::Flat), |
| 2529 | 2545 | scroll_method: Some(ScrollMethod::OnButtonDown), |
| 2530 | 2546 | }, |
| 2531 | 2547 | tablet: Tablet { |
| 2548 | + off: false, | |
| 2532 | 2549 | map_to_output: Some("eDP-1".to_owned()), |
| 2533 | 2550 | left_handed: false, |
| 2534 | 2551 | }, |
resources/default-config.kdlmodified+3 -0
| @@ -21,6 +21,7 @@ input { | ||
| 21 | 21 | // Next sections include libinput settings. |
| 22 | 22 | // Omitting settings disables them, or leaves them at their default values. |
| 23 | 23 | touchpad { |
| 24 | + // off | |
| 24 | 25 | tap |
| 25 | 26 | // dwt |
| 26 | 27 | // dwtp |
| @@ -28,9 +29,11 @@ input { | ||
| 28 | 29 | // accel-speed 0.2 |
| 29 | 30 | // accel-profile "flat" |
| 30 | 31 | // scroll-method "two-finger" |
| 32 | + // disabled-on-external-mouse | |
| 31 | 33 | } |
| 32 | 34 | |
| 33 | 35 | mouse { |
| 36 | + // off | |
| 34 | 37 | // natural-scroll |
| 35 | 38 | // accel-speed 0.2 |
| 36 | 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 | 2219 | let is_touchpad = device.config_tap_finger_count() > 0; |
| 2220 | 2220 | if is_touchpad { |
| 2221 | 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 | 2229 | let _ = device.config_tap_set_enabled(c.tap); |
| 2223 | 2230 | let _ = device.config_dwt_set_enabled(c.dwt); |
| 2224 | 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 | 2279 | && !is_trackpoint; |
| 2273 | 2280 | if is_mouse { |
| 2274 | 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 | 2287 | let _ = device.config_scroll_set_natural_scroll_enabled(c.natural_scroll); |
| 2276 | 2288 | let _ = device.config_accel_set_speed(c.accel_speed); |
| 2277 | 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 | 2304 | if is_trackpoint { |
| 2293 | 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 | 2311 | let _ = device.config_scroll_set_natural_scroll_enabled(c.natural_scroll); |
| 2295 | 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 | 2327 | let is_tablet = device.has_capability(input::DeviceCapability::TabletTool); |
| 2311 | 2328 | if is_tablet { |
| 2312 | 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 | 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 | 27 | touchpad { |
| 28 | + // off | |
| 28 | 29 | tap |
| 29 | 30 | // dwt |
| 30 | 31 | // dwtp |
| @@ -35,9 +36,11 @@ input { | ||
| 35 | 36 | // tap-button-map "left-middle-right" |
| 36 | 37 | // click-method "clickfinger" |
| 37 | 38 | // left-handed |
| 39 | + // disabled-on-external-mouse | |
| 38 | 40 | } |
| 39 | 41 | |
| 40 | 42 | mouse { |
| 43 | + // off | |
| 41 | 44 | // natural-scroll |
| 42 | 45 | // accel-speed 0.2 |
| 43 | 46 | // accel-profile "flat" |
| @@ -46,6 +49,7 @@ input { | ||
| 46 | 49 | } |
| 47 | 50 | |
| 48 | 51 | trackpoint { |
| 52 | + // off | |
| 49 | 53 | // natural-scroll |
| 50 | 54 | // accel-speed 0.2 |
| 51 | 55 | // accel-profile "flat" |
| @@ -53,6 +57,7 @@ input { | ||
| 53 | 57 | } |
| 54 | 58 | |
| 55 | 59 | tablet { |
| 60 | + // off | |
| 56 | 61 | map-to-output "eDP-1" |
| 57 | 62 | // left-handed |
| 58 | 63 | } |
| @@ -122,6 +127,10 @@ Most settings for the pointing devices are passed directly to libinput. | ||
| 122 | 127 | Other Wayland compositors also use libinput, so it's likely you will find the same settings there. |
| 123 | 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 | 134 | A few settings are common between `touchpad`, `mouse` and `trackpoint`: |
| 126 | 135 | |
| 127 | 136 | - `natural-scroll`: if set, inverts the scrolling direction. |
| @@ -137,6 +146,7 @@ Settings specific to `touchpad`s: | ||
| 137 | 146 | - `dwtp`: disable-when-trackpointing. |
| 138 | 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 | 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 | 151 | Settings specific to `touchpad`, `mouse` and `tablet`: |
| 142 | 152 |