forge
Explore
Log in

Don't you dare go Hollow

Add "off" and "disabled-on-external-mouse" properties to input devices

Browse files at this commit

c8e46b9d172dfa2ca89d82b87055b8e39622f80cYuya NishiharaParent: f2ce84b
This is called "events <mode>" in Sway, but we decided to use more abstracted
form for consistency with the other config items. "disabled-on-external-mouse"
is added only to touchpads, but there might be other devices that support this
option.

I think "off" also applies to keyboards, but I'm not going to add the one
because we don't have libinput machinery for the keyboard config, and it's
unlikely that user wants to disable _all_ keyboards. OTOH, pointer devices can
be disabled per type. Perhaps, this should be revisited after implementing #371.
niri-config/src/lib.rsmodified+17 -0
@@ -155,6 +155,8 @@ pub enum TrackLayout {
155155 // FIXME: Add the rest of the settings.
156156 #[derive(knuffel::Decode, Debug, Default, PartialEq)]
157157 pub struct Touchpad {
158+ #[knuffel(child)]
159+ pub off: bool,
158160 #[knuffel(child)]
159161 pub tap: bool,
160162 #[knuffel(child)]
@@ -175,10 +177,14 @@ pub struct Touchpad {
175177 pub tap_button_map: Option<TapButtonMap>,
176178 #[knuffel(child)]
177179 pub left_handed: bool,
180+ #[knuffel(child)]
181+ pub disabled_on_external_mouse: bool,
178182 }
179183
180184 #[derive(knuffel::Decode, Debug, Default, PartialEq)]
181185 pub struct Mouse {
186+ #[knuffel(child)]
187+ pub off: bool,
182188 #[knuffel(child)]
183189 pub natural_scroll: bool,
184190 #[knuffel(child, unwrap(argument), default)]
@@ -193,6 +199,8 @@ pub struct Mouse {
193199
194200 #[derive(knuffel::Decode, Debug, Default, PartialEq)]
195201 pub struct Trackpoint {
202+ #[knuffel(child)]
203+ pub off: bool,
196204 #[knuffel(child)]
197205 pub natural_scroll: bool,
198206 #[knuffel(child, unwrap(argument), default)]
@@ -269,6 +277,8 @@ impl From<TapButtonMap> for input::TapButtonMap {
269277
270278 #[derive(knuffel::Decode, Debug, Default, PartialEq)]
271279 pub struct Tablet {
280+ #[knuffel(child)]
281+ pub off: bool,
272282 #[knuffel(child, unwrap(argument))]
273283 pub map_to_output: Option<String>,
274284 #[knuffel(child)]
@@ -2342,6 +2352,7 @@ mod tests {
23422352 accel-profile "flat"
23432353 scroll-method "two-finger"
23442354 tap-button-map "left-middle-right"
2355+ disabled-on-external-mouse
23452356 }
23462357
23472358 mouse {
@@ -2352,6 +2363,7 @@ mod tests {
23522363 }
23532364
23542365 trackpoint {
2366+ off
23552367 natural-scroll
23562368 accel-speed 0.0
23572369 accel-profile "flat"
@@ -2504,6 +2516,7 @@ mod tests {
25042516 track_layout: TrackLayout::Window,
25052517 },
25062518 touchpad: Touchpad {
2519+ off: false,
25072520 tap: true,
25082521 dwt: true,
25092522 dwtp: true,
@@ -2514,8 +2527,10 @@ mod tests {
25142527 scroll_method: Some(ScrollMethod::TwoFinger),
25152528 tap_button_map: Some(TapButtonMap::LeftMiddleRight),
25162529 left_handed: false,
2530+ disabled_on_external_mouse: true,
25172531 },
25182532 mouse: Mouse {
2533+ off: false,
25192534 natural_scroll: true,
25202535 accel_speed: 0.4,
25212536 accel_profile: Some(AccelProfile::Flat),
@@ -2523,12 +2538,14 @@ mod tests {
25232538 left_handed: false,
25242539 },
25252540 trackpoint: Trackpoint {
2541+ off: true,
25262542 natural_scroll: true,
25272543 accel_speed: 0.0,
25282544 accel_profile: Some(AccelProfile::Flat),
25292545 scroll_method: Some(ScrollMethod::OnButtonDown),
25302546 },
25312547 tablet: Tablet {
2548+ off: false,
25322549 map_to_output: Some("eDP-1".to_owned()),
25332550 left_handed: false,
25342551 },
resources/default-config.kdlmodified+3 -0
@@ -21,6 +21,7 @@ input {
2121 // Next sections include libinput settings.
2222 // Omitting settings disables them, or leaves them at their default values.
2323 touchpad {
24+ // off
2425 tap
2526 // dwt
2627 // dwtp
@@ -28,9 +29,11 @@ input {
2829 // accel-speed 0.2
2930 // accel-profile "flat"
3031 // scroll-method "two-finger"
32+ // disabled-on-external-mouse
3133 }
3234
3335 mouse {
36+ // off
3437 // natural-scroll
3538 // accel-speed 0.2
3639 // 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::
22192219 let is_touchpad = device.config_tap_finger_count() > 0;
22202220 if is_touchpad {
22212221 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+ });
22222229 let _ = device.config_tap_set_enabled(c.tap);
22232230 let _ = device.config_dwt_set_enabled(c.dwt);
22242231 let _ = device.config_dwtp_set_enabled(c.dwtp);
@@ -2272,6 +2279,11 @@ pub fn apply_libinput_settings(config: &niri_config::Input, device: &mut input::
22722279 && !is_trackpoint;
22732280 if is_mouse {
22742281 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+ });
22752287 let _ = device.config_scroll_set_natural_scroll_enabled(c.natural_scroll);
22762288 let _ = device.config_accel_set_speed(c.accel_speed);
22772289 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::
22912303
22922304 if is_trackpoint {
22932305 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+ });
22942311 let _ = device.config_scroll_set_natural_scroll_enabled(c.natural_scroll);
22952312 let _ = device.config_accel_set_speed(c.accel_speed);
22962313
@@ -2310,6 +2327,11 @@ pub fn apply_libinput_settings(config: &niri_config::Input, device: &mut input::
23102327 let is_tablet = device.has_capability(input::DeviceCapability::TabletTool);
23112328 if is_tablet {
23122329 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+ });
23132335 let _ = device.config_left_handed_set(c.left_handed);
23142336 }
23152337 }
wiki/Configuration:-Input.mdmodified+10 -0
@@ -25,6 +25,7 @@ input {
2525 }
2626
2727 touchpad {
28+ // off
2829 tap
2930 // dwt
3031 // dwtp
@@ -35,9 +36,11 @@ input {
3536 // tap-button-map "left-middle-right"
3637 // click-method "clickfinger"
3738 // left-handed
39+ // disabled-on-external-mouse
3840 }
3941
4042 mouse {
43+ // off
4144 // natural-scroll
4245 // accel-speed 0.2
4346 // accel-profile "flat"
@@ -46,6 +49,7 @@ input {
4649 }
4750
4851 trackpoint {
52+ // off
4953 // natural-scroll
5054 // accel-speed 0.2
5155 // accel-profile "flat"
@@ -53,6 +57,7 @@ input {
5357 }
5458
5559 tablet {
60+ // off
5661 map-to-output "eDP-1"
5762 // left-handed
5863 }
@@ -122,6 +127,10 @@ Most settings for the pointing devices are passed directly to libinput.
122127 Other Wayland compositors also use libinput, so it's likely you will find the same settings there.
123128 For flags like `tap`, omit them or comment them out to disable the setting.
124129
130+A few settings are common between input devices:
131+
132+- `off`: if set, no events will be sent from this device.
133+
125134 A few settings are common between `touchpad`, `mouse` and `trackpoint`:
126135
127136 - `natural-scroll`: if set, inverts the scrolling direction.
@@ -137,6 +146,7 @@ Settings specific to `touchpad`s:
137146 - `dwtp`: disable-when-trackpointing.
138147 - `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.
139148 - `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.
140150
141151 Settings specific to `touchpad`, `mouse` and `tablet`:
142152