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:
231 231
232 - `off`: if set, no events will be sent from this device.232 - `off`: if set, no events will be sent from this device.
233 233
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+
234 A few settings are common between `touchpad`, `mouse`, `trackpoint`, and `trackball`:237 A few settings are common between `touchpad`, `mouse`, `trackpoint`, and `trackball`:
235 238
236 - `natural-scroll`: if set, inverts the scrolling direction.239 - `natural-scroll`: if set, inverts the scrolling direction.
docs/wiki/Configuration:-Key-Bindings.mdmodified+16 -0
@@ -433,3 +433,19 @@ binds {
433 Super+Alt+L allow-inhibiting=false { spawn "swaylock"; }433 Super+Alt+L allow-inhibiting=false { spawn "swaylock"; }
434 }434 }
435 ```435 ```
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 {
112 ToggleDebugTint,112 ToggleDebugTint,
113 DebugToggleOpaqueRegions,113 DebugToggleOpaqueRegions,
114 DebugToggleDamage,114 DebugToggleDamage,
115+ ToggleTouchpad,
115 Spawn(#[knuffel(arguments)] Vec<String>),116 Spawn(#[knuffel(arguments)] Vec<String>),
116 SpawnSh(#[knuffel(argument)] String),117 SpawnSh(#[knuffel(argument)] String),
117 DoScreenTransition(#[knuffel(property(name = "delay-ms"))] Option<u16>),118 DoScreenTransition(#[knuffel(property(name = "delay-ms"))] Option<u16>),
@@ -668,6 +669,7 @@ impl From<niri_ipc::Action> for Action {
668 niri_ipc::Action::ToggleDebugTint {} => Self::ToggleDebugTint,669 niri_ipc::Action::ToggleDebugTint {} => Self::ToggleDebugTint,
669 niri_ipc::Action::DebugToggleOpaqueRegions {} => Self::DebugToggleOpaqueRegions,670 niri_ipc::Action::DebugToggleOpaqueRegions {} => Self::DebugToggleOpaqueRegions,
670 niri_ipc::Action::DebugToggleDamage {} => Self::DebugToggleDamage,671 niri_ipc::Action::DebugToggleDamage {} => Self::DebugToggleDamage,
672+ niri_ipc::Action::ToggleTouchpad {} => Self::ToggleTouchpad,
671 niri_ipc::Action::ToggleWindowFloating { id: None } => Self::ToggleWindowFloating,673 niri_ipc::Action::ToggleWindowFloating { id: None } => Self::ToggleWindowFloating,
672 niri_ipc::Action::ToggleWindowFloating { id: Some(id) } => {674 niri_ipc::Action::ToggleWindowFloating { id: Some(id) } => {
673 Self::ToggleWindowFloatingById(id)675 Self::ToggleWindowFloatingById(id)
niri-ipc/src/lib.rsmodified+2 -0
@@ -807,6 +807,8 @@ pub enum Action {
807 DebugToggleOpaqueRegions {},807 DebugToggleOpaqueRegions {},
808 /// Toggle visualization of output damage.808 /// Toggle visualization of output damage.
809 DebugToggleDamage {},809 DebugToggleDamage {},
810+ /// Toggle the touchpad on/off at runtime.
811+ ToggleTouchpad {},
810 /// Move the focused window between the floating and the tiling layout.812 /// Move the focused window between the floating and the tiling layout.
811 ToggleWindowFloating {813 ToggleWindowFloating {
812 /// Id of the window to move.814 /// Id of the window to move.
src/input/mod.rsmodified+25 -3
@@ -249,7 +249,11 @@ impl State {
249 self.niri.touch.insert(device.clone());249 self.niri.touch.insert(device.clone());
250 }250 }
251 251
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+ );
253 }257 }
254 InputEvent::DeviceRemoved { device } => {258 InputEvent::DeviceRemoved { device } => {
255 self.niri.touch.remove(device);259 self.niri.touch.remove(device);
@@ -739,6 +743,19 @@ impl State {
739 Action::DebugToggleDamage => {743 Action::DebugToggleDamage => {
740 self.niri.debug_toggle_damage();744 self.niri.debug_toggle_damage();
741 }745 }
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+ }
742 Action::Spawn(command) => {759 Action::Spawn(command) => {
743 let (token, _) = self.niri.activation_state.create_external_token(None);760 let (token, _) = self.niri.activation_state.create_external_token(None);
744 spawn(command, Some(token.clone()));761 spawn(command, Some(token.clone()));
@@ -4909,12 +4926,17 @@ fn hardcoded_overview_bind(raw: Keysym, mods: ModifiersState) -> Option<Bind> {
4909 })4926 })
4910 }4927 }
4911 4928
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+) {
4913 // According to Mutter code, this setting is specific to touchpads.4934 // According to Mutter code, this setting is specific to touchpads.
4914 let is_touchpad = device.config_tap_finger_count() > 0;4935 let is_touchpad = device.config_tap_finger_count() > 0;
4915 if is_touchpad {4936 if is_touchpad {
4916 let c = &config.touchpad;4937 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 {
4918 input::SendEventsMode::DISABLED4940 input::SendEventsMode::DISABLED
4919 } else if c.disabled_on_external_mouse {4941 } else if c.disabled_on_external_mouse {
4920 input::SendEventsMode::DISABLED_ON_EXTERNAL_MOUSE4942 input::SendEventsMode::DISABLED_ON_EXTERNAL_MOUSE
src/niri.rsmodified+9 -1
@@ -276,6 +276,9 @@ pub struct Niri {
276 /// startup, libinput will immediately send a closed event.276 /// startup, libinput will immediately send a closed event.
277 pub is_lid_closed: bool,277 pub is_lid_closed: bool,
278 278
279+ /// Runtime toggle for touchpad disabled state (combined with config.touchpad.off).
280+ pub touchpad_disabled_by_toggle: bool,
281+
279 pub devices: HashSet<input::Device>,282 pub devices: HashSet<input::Device>,
280 pub tablets: HashMap<input::Device, TabletData>,283 pub tablets: HashMap<input::Device, TabletData>,
281 pub touch: HashSet<input::Device>,284 pub touch: HashSet<input::Device>,
@@ -1782,7 +1785,11 @@ impl State {
1782 if libinput_config_changed {1785 if libinput_config_changed {
1783 let config = self.niri.config.borrow();1786 let config = self.niri.config.borrow();
1784 for mut device in self.niri.devices.iter().cloned() {1787 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+ );
1786 }1793 }
1787 }1794 }
1788 1795
@@ -2672,6 +2679,7 @@ impl Niri {
2672 blocker_cleared_rx,2679 blocker_cleared_rx,
2673 monitors_active: true,2680 monitors_active: true,
2674 is_lid_closed: false,2681 is_lid_closed: false,
2682+ touchpad_disabled_by_toggle: false,
2675 2683
2676 devices: HashSet::new(),2684 devices: HashSet::new(),
2677 tablets: HashMap::new(),2685 tablets: HashMap::new(),