ipc: Add TouchpadToggled to the event stream
Browse files at this commit45739bc072f9875a674d335ae724f10d3b35c665Parent: d0543955 changed files +63 -0
- niri-ipc/src/lib.rs +8 -0
- niri-ipc/src/state.rs +33 -0
- src/ipc/client.rs +3 -0
- src/ipc/server.rs +18 -0
- src/niri.rs +1 -0
niri-ipc/src/lib.rsmodified+8 -0
| @@ -1748,6 +1748,14 @@ pub enum Event { | ||
| 1748 | 1748 | /// Stream ID of the stopped screencast. |
| 1749 | 1749 | stream_id: u64, |
| 1750 | 1750 | }, |
| 1751 | + /// Touchpad toggled on/off via [`Action::ToggleTouchpad`]. | |
| 1752 | + TouchpadToggled { | |
| 1753 | + /// Whether the touchpad is now enabled. | |
| 1754 | + /// | |
| 1755 | + /// Note that this only indicates the [`Action::ToggleTouchpad`] state. The touchpad can be | |
| 1756 | + /// disabled in hardware, or via `input { touchpad { off; } }`—this is not reflected here. | |
| 1757 | + on: bool, | |
| 1758 | + }, | |
| 1751 | 1759 | } |
| 1752 | 1760 | |
| 1753 | 1761 | impl From<Duration> for Timestamp { |
niri-ipc/src/state.rsmodified+33 -0
| @@ -49,6 +49,9 @@ pub struct EventStreamState { | ||
| 49 | 49 | |
| 50 | 50 | /// State of screencasts. |
| 51 | 51 | pub casts: CastsState, |
| 52 | + | |
| 53 | + /// State of touchpads. | |
| 54 | + pub touchpad: TouchpadState, | |
| 52 | 55 | } |
| 53 | 56 | |
| 54 | 57 | /// The workspaces state communicated over the event stream. |
| @@ -93,6 +96,18 @@ pub struct CastsState { | ||
| 93 | 96 | pub casts: HashMap<u64, Cast>, |
| 94 | 97 | } |
| 95 | 98 | |
| 99 | +/// The touchpad state communicated over the event stream. | |
| 100 | +#[derive(Debug, Default)] | |
| 101 | +pub struct TouchpadState { | |
| 102 | + /// Whether the touchpad is currently on. | |
| 103 | + /// | |
| 104 | + /// Note that this only indicates the [`Action::ToggleTouchpad`] state. The touchpad can be | |
| 105 | + /// disabled in hardware, or via `input { touchpad { off; } }`—this is not reflected here. | |
| 106 | + /// | |
| 107 | + /// [`Action::ToggleTouchpad`]: crate::Action::ToggleTouchpad | |
| 108 | + pub on: bool, | |
| 109 | +} | |
| 110 | + | |
| 96 | 111 | impl EventStreamStatePart for EventStreamState { |
| 97 | 112 | fn replicate(&self) -> Vec<Event> { |
| 98 | 113 | let mut events = Vec::new(); |
| @@ -102,6 +117,7 @@ impl EventStreamStatePart for EventStreamState { | ||
| 102 | 117 | events.extend(self.overview.replicate()); |
| 103 | 118 | events.extend(self.config.replicate()); |
| 104 | 119 | events.extend(self.casts.replicate()); |
| 120 | + events.extend(self.touchpad.replicate()); | |
| 105 | 121 | events |
| 106 | 122 | } |
| 107 | 123 | |
| @@ -112,6 +128,7 @@ impl EventStreamStatePart for EventStreamState { | ||
| 112 | 128 | let event = self.overview.apply(event)?; |
| 113 | 129 | let event = self.config.apply(event)?; |
| 114 | 130 | let event = self.casts.apply(event)?; |
| 131 | + let event = self.touchpad.apply(event)?; | |
| 115 | 132 | Some(event) |
| 116 | 133 | } |
| 117 | 134 | } |
| @@ -321,3 +338,19 @@ impl EventStreamStatePart for CastsState { | ||
| 321 | 338 | None |
| 322 | 339 | } |
| 323 | 340 | } |
| 341 | + | |
| 342 | +impl EventStreamStatePart for TouchpadState { | |
| 343 | + fn replicate(&self) -> Vec<Event> { | |
| 344 | + vec![Event::TouchpadToggled { on: self.on }] | |
| 345 | + } | |
| 346 | + | |
| 347 | + fn apply(&mut self, event: Event) -> Option<Event> { | |
| 348 | + match event { | |
| 349 | + Event::TouchpadToggled { on } => { | |
| 350 | + self.on = on; | |
| 351 | + } | |
| 352 | + event => return Some(event), | |
| 353 | + } | |
| 354 | + None | |
| 355 | + } | |
| 356 | +} |
src/ipc/client.rsmodified+3 -0
| @@ -522,6 +522,9 @@ pub fn handle_msg(mut msg: Msg, json: bool, print_request: bool) -> anyhow::Resu | ||
| 522 | 522 | Event::CastStopped { stream_id } => { |
| 523 | 523 | println!("Cast stopped: stream id {stream_id}"); |
| 524 | 524 | } |
| 525 | + Event::TouchpadToggled { on } => { | |
| 526 | + println!("Touchpad enabled: {on}"); | |
| 527 | + } | |
| 525 | 528 | } |
| 526 | 529 | } |
| 527 | 530 | } |
src/ipc/server.rsmodified+18 -0
| @@ -962,6 +962,24 @@ impl State { | ||
| 962 | 962 | } |
| 963 | 963 | } |
| 964 | 964 | |
| 965 | + pub fn ipc_refresh_touchpad(&mut self) { | |
| 966 | + let Some(server) = &self.niri.ipc_server else { | |
| 967 | + return; | |
| 968 | + }; | |
| 969 | + | |
| 970 | + let mut state = server.event_stream_state.borrow_mut(); | |
| 971 | + let state = &mut state.touchpad; | |
| 972 | + let on = !self.niri.touchpad_disabled_by_toggle; | |
| 973 | + | |
| 974 | + if state.on == on { | |
| 975 | + return; | |
| 976 | + } | |
| 977 | + | |
| 978 | + let event = Event::TouchpadToggled { on }; | |
| 979 | + state.apply(event.clone()); | |
| 980 | + server.send_event(event); | |
| 981 | + } | |
| 982 | + | |
| 965 | 983 | pub fn ipc_config_loaded(&mut self, failed: bool) { |
| 966 | 984 | let Some(server) = &self.niri.ipc_server else { |
| 967 | 985 | return; |
src/niri.rsmodified+1 -0
| @@ -888,6 +888,7 @@ impl State { | ||
| 888 | 888 | self.refresh_ipc_outputs(); |
| 889 | 889 | self.ipc_refresh_layout(); |
| 890 | 890 | self.ipc_refresh_keyboard_layout_index(); |
| 891 | + self.ipc_refresh_touchpad(); | |
| 891 | 892 | |
| 892 | 893 | // Needs to be called after updating the keyboard focus. |
| 893 | 894 | #[cfg(feature = "dbus")] |