diff --git a/docs/wiki/Configuration:-Input.md b/docs/wiki/Configuration:-Input.md index 187f2dca..af645910 100644 --- a/docs/wiki/Configuration:-Input.md +++ b/docs/wiki/Configuration:-Input.md @@ -231,6 +231,9 @@ A few settings are common between input devices: - `off`: if set, no events will be sent from this device. +> [!TIP] +> Since: next release For touchpads, you can also toggle them on/off at runtime using the [`toggle-touchpad` action](./Configuration:-Key-Bindings.md#toggle-touchpad), without editing the config. + A few settings are common between `touchpad`, `mouse`, `trackpoint`, and `trackball`: - `natural-scroll`: if set, inverts the scrolling direction. diff --git a/docs/wiki/Configuration:-Key-Bindings.md b/docs/wiki/Configuration:-Key-Bindings.md index 113809de..f8ee0188 100644 --- a/docs/wiki/Configuration:-Key-Bindings.md +++ b/docs/wiki/Configuration:-Key-Bindings.md @@ -433,3 +433,19 @@ binds { Super+Alt+L allow-inhibiting=false { spawn "swaylock"; } } ``` + +#### `toggle-touchpad` + +Since: next release + +Toggle the touchpad on or off at runtime. +This provides a quick way to disable the touchpad without editing the config file. + +```kdl +binds { + Mod+F9 { toggle-touchpad; } +} +``` + +The toggle state is combined with the [`off` setting](./Configuration:-Input.md#pointing-devices) in the config: both the config and the toggle must allow the touchpad for it to be enabled. +The toggle state resets when niri restarts, and applies to newly hot-plugged touchpads. diff --git a/niri-config/src/binds.rs b/niri-config/src/binds.rs index d02aa595..2266d877 100644 --- a/niri-config/src/binds.rs +++ b/niri-config/src/binds.rs @@ -112,6 +112,7 @@ pub enum Action { ToggleDebugTint, DebugToggleOpaqueRegions, DebugToggleDamage, + ToggleTouchpad, Spawn(#[knuffel(arguments)] Vec), SpawnSh(#[knuffel(argument)] String), DoScreenTransition(#[knuffel(property(name = "delay-ms"))] Option), @@ -668,6 +669,7 @@ impl From for Action { niri_ipc::Action::ToggleDebugTint {} => Self::ToggleDebugTint, niri_ipc::Action::DebugToggleOpaqueRegions {} => Self::DebugToggleOpaqueRegions, niri_ipc::Action::DebugToggleDamage {} => Self::DebugToggleDamage, + niri_ipc::Action::ToggleTouchpad {} => Self::ToggleTouchpad, niri_ipc::Action::ToggleWindowFloating { id: None } => Self::ToggleWindowFloating, niri_ipc::Action::ToggleWindowFloating { id: Some(id) } => { Self::ToggleWindowFloatingById(id) diff --git a/niri-ipc/src/lib.rs b/niri-ipc/src/lib.rs index dfbe59a0..c11f2bf6 100644 --- a/niri-ipc/src/lib.rs +++ b/niri-ipc/src/lib.rs @@ -807,6 +807,8 @@ pub enum Action { DebugToggleOpaqueRegions {}, /// Toggle visualization of output damage. DebugToggleDamage {}, + /// Toggle the touchpad on/off at runtime. + ToggleTouchpad {}, /// Move the focused window between the floating and the tiling layout. ToggleWindowFloating { /// Id of the window to move. diff --git a/src/input/mod.rs b/src/input/mod.rs index 75958c41..65951a99 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -249,7 +249,11 @@ impl State { self.niri.touch.insert(device.clone()); } - apply_libinput_settings(&self.niri.config.borrow().input, device); + apply_libinput_settings( + &self.niri.config.borrow().input, + device, + self.niri.touchpad_disabled_by_toggle, + ); } InputEvent::DeviceRemoved { device } => { self.niri.touch.remove(device); @@ -739,6 +743,19 @@ impl State { Action::DebugToggleDamage => { self.niri.debug_toggle_damage(); } + Action::ToggleTouchpad => { + self.niri.touchpad_disabled_by_toggle = !self.niri.touchpad_disabled_by_toggle; + let config = self.niri.config.borrow(); + for mut device in self.niri.devices.iter().cloned() { + if device.config_tap_finger_count() > 0 { + apply_libinput_settings( + &config.input, + &mut device, + self.niri.touchpad_disabled_by_toggle, + ); + } + } + } Action::Spawn(command) => { let (token, _) = self.niri.activation_state.create_external_token(None); spawn(command, Some(token.clone())); @@ -4909,12 +4926,17 @@ fn hardcoded_overview_bind(raw: Keysym, mods: ModifiersState) -> Option { }) } -pub fn apply_libinput_settings(config: &niri_config::Input, device: &mut input::Device) { +pub fn apply_libinput_settings( + config: &niri_config::Input, + device: &mut input::Device, + touchpad_disabled_by_toggle: bool, +) { // According to Mutter code, this setting is specific to touchpads. let is_touchpad = device.config_tap_finger_count() > 0; if is_touchpad { let c = &config.touchpad; - let _ = device.config_send_events_set_mode(if c.off { + let is_off = c.off || touchpad_disabled_by_toggle; + let _ = device.config_send_events_set_mode(if is_off { input::SendEventsMode::DISABLED } else if c.disabled_on_external_mouse { input::SendEventsMode::DISABLED_ON_EXTERNAL_MOUSE diff --git a/src/niri.rs b/src/niri.rs index 426411a4..b05afd21 100644 --- a/src/niri.rs +++ b/src/niri.rs @@ -276,6 +276,9 @@ pub struct Niri { /// startup, libinput will immediately send a closed event. pub is_lid_closed: bool, + /// Runtime toggle for touchpad disabled state (combined with config.touchpad.off). + pub touchpad_disabled_by_toggle: bool, + pub devices: HashSet, pub tablets: HashMap, pub touch: HashSet, @@ -1782,7 +1785,11 @@ impl State { if libinput_config_changed { let config = self.niri.config.borrow(); for mut device in self.niri.devices.iter().cloned() { - apply_libinput_settings(&config.input, &mut device); + apply_libinput_settings( + &config.input, + &mut device, + self.niri.touchpad_disabled_by_toggle, + ); } } @@ -2672,6 +2679,7 @@ impl Niri { blocker_cleared_rx, monitors_active: true, is_lid_closed: false, + touchpad_disabled_by_toggle: false, devices: HashSet::new(), tablets: HashMap::new(),