forge
Explore
Log in

Don't you dare go Hollow

ipc: Add TouchpadToggled to the event stream

Browse files at this commit

45739bc072f9875a674d335ae724f10d3b35c665Ivan MolodetskikhParent: d054395
niri-ipc/src/lib.rsmodified+8 -0
@@ -1748,6 +1748,14 @@ pub enum Event {
17481748 /// Stream ID of the stopped screencast.
17491749 stream_id: u64,
17501750 },
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+ },
17511759 }
17521760
17531761 impl From<Duration> for Timestamp {
niri-ipc/src/state.rsmodified+33 -0
@@ -49,6 +49,9 @@ pub struct EventStreamState {
4949
5050 /// State of screencasts.
5151 pub casts: CastsState,
52+
53+ /// State of touchpads.
54+ pub touchpad: TouchpadState,
5255 }
5356
5457 /// The workspaces state communicated over the event stream.
@@ -93,6 +96,18 @@ pub struct CastsState {
9396 pub casts: HashMap<u64, Cast>,
9497 }
9598
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+
96111 impl EventStreamStatePart for EventStreamState {
97112 fn replicate(&self) -> Vec<Event> {
98113 let mut events = Vec::new();
@@ -102,6 +117,7 @@ impl EventStreamStatePart for EventStreamState {
102117 events.extend(self.overview.replicate());
103118 events.extend(self.config.replicate());
104119 events.extend(self.casts.replicate());
120+ events.extend(self.touchpad.replicate());
105121 events
106122 }
107123
@@ -112,6 +128,7 @@ impl EventStreamStatePart for EventStreamState {
112128 let event = self.overview.apply(event)?;
113129 let event = self.config.apply(event)?;
114130 let event = self.casts.apply(event)?;
131+ let event = self.touchpad.apply(event)?;
115132 Some(event)
116133 }
117134 }
@@ -321,3 +338,19 @@ impl EventStreamStatePart for CastsState {
321338 None
322339 }
323340 }
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
522522 Event::CastStopped { stream_id } => {
523523 println!("Cast stopped: stream id {stream_id}");
524524 }
525+ Event::TouchpadToggled { on } => {
526+ println!("Touchpad enabled: {on}");
527+ }
525528 }
526529 }
527530 }
src/ipc/server.rsmodified+18 -0
@@ -962,6 +962,24 @@ impl State {
962962 }
963963 }
964964
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+
965983 pub fn ipc_config_loaded(&mut self, failed: bool) {
966984 let Some(server) = &self.niri.ipc_server else {
967985 return;
src/niri.rsmodified+1 -0
@@ -888,6 +888,7 @@ impl State {
888888 self.refresh_ipc_outputs();
889889 self.ipc_refresh_layout();
890890 self.ipc_refresh_keyboard_layout_index();
891+ self.ipc_refresh_touchpad();
891892
892893 // Needs to be called after updating the keyboard focus.
893894 #[cfg(feature = "dbus")]