Add toggle-touchpad action
Browse files at this commit4e3661b33e0df73fbff64c11fdd6cc2eae071dc4Parent: f8b7b7f6 changed files +57 -4
- docs/wiki/Configuration:-Input.md +3 -0
- docs/wiki/Configuration:-Key-Bindings.md +16 -0
- niri-config/src/binds.rs +2 -0
- niri-ipc/src/lib.rs +2 -0
- src/input/mod.rs +25 -3
- src/niri.rs +9 -1
docs/wiki/Configuration:-Input.mdmodified+3 -0
| @@ -231,6 +231,9 @@ A few settings are common between input devices: | ||
| 231 | 231 | |
| 232 | 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 | 237 | A few settings are common between `touchpad`, `mouse`, `trackpoint`, and `trackball`: |
| 235 | 238 | |
| 236 | 239 | - `natural-scroll`: if set, inverts the scrolling direction. |
docs/wiki/Configuration:-Key-Bindings.mdmodified+16 -0
| @@ -433,3 +433,19 @@ binds { | ||
| 433 | 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 | 112 | ToggleDebugTint, |
| 113 | 113 | DebugToggleOpaqueRegions, |
| 114 | 114 | DebugToggleDamage, |
| 115 | + ToggleTouchpad, | |
| 115 | 116 | Spawn(#[knuffel(arguments)] Vec<String>), |
| 116 | 117 | SpawnSh(#[knuffel(argument)] String), |
| 117 | 118 | DoScreenTransition(#[knuffel(property(name = "delay-ms"))] Option<u16>), |
| @@ -668,6 +669,7 @@ impl From<niri_ipc::Action> for Action { | ||
| 668 | 669 | niri_ipc::Action::ToggleDebugTint {} => Self::ToggleDebugTint, |
| 669 | 670 | niri_ipc::Action::DebugToggleOpaqueRegions {} => Self::DebugToggleOpaqueRegions, |
| 670 | 671 | niri_ipc::Action::DebugToggleDamage {} => Self::DebugToggleDamage, |
| 672 | + niri_ipc::Action::ToggleTouchpad {} => Self::ToggleTouchpad, | |
| 671 | 673 | niri_ipc::Action::ToggleWindowFloating { id: None } => Self::ToggleWindowFloating, |
| 672 | 674 | niri_ipc::Action::ToggleWindowFloating { id: Some(id) } => { |
| 673 | 675 | Self::ToggleWindowFloatingById(id) |
niri-ipc/src/lib.rsmodified+2 -0
| @@ -807,6 +807,8 @@ pub enum Action { | ||
| 807 | 807 | DebugToggleOpaqueRegions {}, |
| 808 | 808 | /// Toggle visualization of output damage. |
| 809 | 809 | DebugToggleDamage {}, |
| 810 | + /// Toggle the touchpad on/off at runtime. | |
| 811 | + ToggleTouchpad {}, | |
| 810 | 812 | /// Move the focused window between the floating and the tiling layout. |
| 811 | 813 | ToggleWindowFloating { |
| 812 | 814 | /// Id of the window to move. |
src/input/mod.rsmodified+25 -3
| @@ -249,7 +249,11 @@ impl State { | ||
| 249 | 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 | 258 | InputEvent::DeviceRemoved { device } => { |
| 255 | 259 | self.niri.touch.remove(device); |
| @@ -739,6 +743,19 @@ impl State { | ||
| 739 | 743 | Action::DebugToggleDamage => { |
| 740 | 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 | 759 | Action::Spawn(command) => { |
| 743 | 760 | let (token, _) = self.niri.activation_state.create_external_token(None); |
| 744 | 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 | 4934 | // According to Mutter code, this setting is specific to touchpads. |
| 4914 | 4935 | let is_touchpad = device.config_tap_finger_count() > 0; |
| 4915 | 4936 | if is_touchpad { |
| 4916 | 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 | 4940 | input::SendEventsMode::DISABLED |
| 4919 | 4941 | } else if c.disabled_on_external_mouse { |
| 4920 | 4942 | input::SendEventsMode::DISABLED_ON_EXTERNAL_MOUSE |
src/niri.rsmodified+9 -1
| @@ -276,6 +276,9 @@ pub struct Niri { | ||
| 276 | 276 | /// startup, libinput will immediately send a closed event. |
| 277 | 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 | 282 | pub devices: HashSet<input::Device>, |
| 280 | 283 | pub tablets: HashMap<input::Device, TabletData>, |
| 281 | 284 | pub touch: HashSet<input::Device>, |
| @@ -1782,7 +1785,11 @@ impl State { | ||
| 1782 | 1785 | if libinput_config_changed { |
| 1783 | 1786 | let config = self.niri.config.borrow(); |
| 1784 | 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 | 2679 | blocker_cleared_rx, |
| 2673 | 2680 | monitors_active: true, |
| 2674 | 2681 | is_lid_closed: false, |
| 2682 | + touchpad_disabled_by_toggle: false, | |
| 2675 | 2683 | |
| 2676 | 2684 | devices: HashSet::new(), |
| 2677 | 2685 | tablets: HashMap::new(), |