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 {
1748 /// Stream ID of the stopped screencast.1748 /// Stream ID of the stopped screencast.
1749 stream_id: u64,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 impl From<Duration> for Timestamp {1761 impl From<Duration> for Timestamp {
niri-ipc/src/state.rsmodified+33 -0
@@ -49,6 +49,9 @@ pub struct EventStreamState {
49 49
50 /// State of screencasts.50 /// State of screencasts.
51 pub casts: CastsState,51 pub casts: CastsState,
52+
53+ /// State of touchpads.
54+ pub touchpad: TouchpadState,
52 }55 }
53 56
54 /// The workspaces state communicated over the event stream.57 /// The workspaces state communicated over the event stream.
@@ -93,6 +96,18 @@ pub struct CastsState {
93 pub casts: HashMap<u64, Cast>,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 impl EventStreamStatePart for EventStreamState {111 impl EventStreamStatePart for EventStreamState {
97 fn replicate(&self) -> Vec<Event> {112 fn replicate(&self) -> Vec<Event> {
98 let mut events = Vec::new();113 let mut events = Vec::new();
@@ -102,6 +117,7 @@ impl EventStreamStatePart for EventStreamState {
102 events.extend(self.overview.replicate());117 events.extend(self.overview.replicate());
103 events.extend(self.config.replicate());118 events.extend(self.config.replicate());
104 events.extend(self.casts.replicate());119 events.extend(self.casts.replicate());
120+ events.extend(self.touchpad.replicate());
105 events121 events
106 }122 }
107 123
@@ -112,6 +128,7 @@ impl EventStreamStatePart for EventStreamState {
112 let event = self.overview.apply(event)?;128 let event = self.overview.apply(event)?;
113 let event = self.config.apply(event)?;129 let event = self.config.apply(event)?;
114 let event = self.casts.apply(event)?;130 let event = self.casts.apply(event)?;
131+ let event = self.touchpad.apply(event)?;
115 Some(event)132 Some(event)
116 }133 }
117 }134 }
@@ -321,3 +338,19 @@ impl EventStreamStatePart for CastsState {
321 None338 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 Event::CastStopped { stream_id } => {522 Event::CastStopped { stream_id } => {
523 println!("Cast stopped: stream id {stream_id}");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 pub fn ipc_config_loaded(&mut self, failed: bool) {983 pub fn ipc_config_loaded(&mut self, failed: bool) {
966 let Some(server) = &self.niri.ipc_server else {984 let Some(server) = &self.niri.ipc_server else {
967 return;985 return;
src/niri.rsmodified+1 -0
@@ -888,6 +888,7 @@ impl State {
888 self.refresh_ipc_outputs();888 self.refresh_ipc_outputs();
889 self.ipc_refresh_layout();889 self.ipc_refresh_layout();
890 self.ipc_refresh_keyboard_layout_index();890 self.ipc_refresh_keyboard_layout_index();
891+ self.ipc_refresh_touchpad();
891 892
892 // Needs to be called after updating the keyboard focus.893 // Needs to be called after updating the keyboard focus.
893 #[cfg(feature = "dbus")]894 #[cfg(feature = "dbus")]