forge
Explore
Log in

Don't you dare go Hollow

Add toggle-touchpad action

Browse files at this commit

4e3661b33e0df73fbff64c11fdd6cc2eae071dc4barrulusParent: f8b7b7f
Adds a new action to toggle the touchpad on/off at runtime without
editing the config file. Can be bound to a key or invoked via IPC
with `niri msg action toggle-touchpad`.

The toggle state is combined with the config's `off` setting - both
must allow the touchpad for it to be enabled. State resets on restart
and applies to newly hot-plugged touchpads.
docs/wiki/Configuration:-Input.mdmodified+3 -0
@@ -231,6 +231,9 @@ A few settings are common between input devices:
231231
232232 - `off`: if set, no events will be sent from this device.
233233
234+> [!TIP]
235+> <sup>Since: next release</sup> 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.
236+
234237 A few settings are common between `touchpad`, `mouse`, `trackpoint`, and `trackball`:
235238
236239 - `natural-scroll`: if set, inverts the scrolling direction.
docs/wiki/Configuration:-Key-Bindings.mdmodified+16 -0
@@ -433,3 +433,19 @@ binds {
433433 Super+Alt+L allow-inhibiting=false { spawn "swaylock"; }
434434 }
435435 ```
436+
437+#### `toggle-touchpad`
438+
439+<sup>Since: next release</sup>
440+
441+Toggle the touchpad on or off at runtime.
442+This provides a quick way to disable the touchpad without editing the config file.
443+
444+```kdl
445+binds {
446+ Mod+F9 { toggle-touchpad; }
447+}
448+```
449+
450+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.
451+The toggle state resets when niri restarts, and applies to newly hot-plugged touchpads.
niri-config/src/binds.rsmodified+2 -0
@@ -112,6 +112,7 @@ pub enum Action {
112112 ToggleDebugTint,
113113 DebugToggleOpaqueRegions,
114114 DebugToggleDamage,
115+ ToggleTouchpad,
115116 Spawn(#[knuffel(arguments)] Vec<String>),
116117 SpawnSh(#[knuffel(argument)] String),
117118 DoScreenTransition(#[knuffel(property(name = "delay-ms"))] Option<u16>),
@@ -668,6 +669,7 @@ impl From<niri_ipc::Action> for Action {
668669 niri_ipc::Action::ToggleDebugTint {} => Self::ToggleDebugTint,
669670 niri_ipc::Action::DebugToggleOpaqueRegions {} => Self::DebugToggleOpaqueRegions,
670671 niri_ipc::Action::DebugToggleDamage {} => Self::DebugToggleDamage,
672+ niri_ipc::Action::ToggleTouchpad {} => Self::ToggleTouchpad,
671673 niri_ipc::Action::ToggleWindowFloating { id: None } => Self::ToggleWindowFloating,
672674 niri_ipc::Action::ToggleWindowFloating { id: Some(id) } => {
673675 Self::ToggleWindowFloatingById(id)
niri-ipc/src/lib.rsmodified+2 -0
@@ -807,6 +807,8 @@ pub enum Action {
807807 DebugToggleOpaqueRegions {},
808808 /// Toggle visualization of output damage.
809809 DebugToggleDamage {},
810+ /// Toggle the touchpad on/off at runtime.
811+ ToggleTouchpad {},
810812 /// Move the focused window between the floating and the tiling layout.
811813 ToggleWindowFloating {
812814 /// Id of the window to move.
src/input/mod.rsmodified+25 -3
@@ -249,7 +249,11 @@ impl State {
249249 self.niri.touch.insert(device.clone());
250250 }
251251
252- apply_libinput_settings(&self.niri.config.borrow().input, device);
252+ apply_libinput_settings(
253+ &self.niri.config.borrow().input,
254+ device,
255+ self.niri.touchpad_disabled_by_toggle,
256+ );
253257 }
254258 InputEvent::DeviceRemoved { device } => {
255259 self.niri.touch.remove(device);
@@ -739,6 +743,19 @@ impl State {
739743 Action::DebugToggleDamage => {
740744 self.niri.debug_toggle_damage();
741745 }
746+ Action::ToggleTouchpad => {
747+ self.niri.touchpad_disabled_by_toggle = !self.niri.touchpad_disabled_by_toggle;
748+ let config = self.niri.config.borrow();
749+ for mut device in self.niri.devices.iter().cloned() {
750+ if device.config_tap_finger_count() > 0 {
751+ apply_libinput_settings(
752+ &config.input,
753+ &mut device,
754+ self.niri.touchpad_disabled_by_toggle,
755+ );
756+ }
757+ }
758+ }
742759 Action::Spawn(command) => {
743760 let (token, _) = self.niri.activation_state.create_external_token(None);
744761 spawn(command, Some(token.clone()));
@@ -4909,12 +4926,17 @@ fn hardcoded_overview_bind(raw: Keysym, mods: ModifiersState) -> Option<Bind> {
49094926 })
49104927 }
49114928
4912-pub fn apply_libinput_settings(config: &niri_config::Input, device: &mut input::Device) {
4929+pub fn apply_libinput_settings(
4930+ config: &niri_config::Input,
4931+ device: &mut input::Device,
4932+ touchpad_disabled_by_toggle: bool,
4933+) {
49134934 // According to Mutter code, this setting is specific to touchpads.
49144935 let is_touchpad = device.config_tap_finger_count() > 0;
49154936 if is_touchpad {
49164937 let c = &config.touchpad;
4917- let _ = device.config_send_events_set_mode(if c.off {
4938+ let is_off = c.off || touchpad_disabled_by_toggle;
4939+ let _ = device.config_send_events_set_mode(if is_off {
49184940 input::SendEventsMode::DISABLED
49194941 } else if c.disabled_on_external_mouse {
49204942 input::SendEventsMode::DISABLED_ON_EXTERNAL_MOUSE
src/niri.rsmodified+9 -1
@@ -276,6 +276,9 @@ pub struct Niri {
276276 /// startup, libinput will immediately send a closed event.
277277 pub is_lid_closed: bool,
278278
279+ /// Runtime toggle for touchpad disabled state (combined with config.touchpad.off).
280+ pub touchpad_disabled_by_toggle: bool,
281+
279282 pub devices: HashSet<input::Device>,
280283 pub tablets: HashMap<input::Device, TabletData>,
281284 pub touch: HashSet<input::Device>,
@@ -1782,7 +1785,11 @@ impl State {
17821785 if libinput_config_changed {
17831786 let config = self.niri.config.borrow();
17841787 for mut device in self.niri.devices.iter().cloned() {
1785- apply_libinput_settings(&config.input, &mut device);
1788+ apply_libinput_settings(
1789+ &config.input,
1790+ &mut device,
1791+ self.niri.touchpad_disabled_by_toggle,
1792+ );
17861793 }
17871794 }
17881795
@@ -2672,6 +2679,7 @@ impl Niri {
26722679 blocker_cleared_rx,
26732680 monitors_active: true,
26742681 is_lid_closed: false,
2682+ touchpad_disabled_by_toggle: false,
26752683
26762684 devices: HashSet::new(),
26772685 tablets: HashMap::new(),