forge
Explore
Log in

Don't you dare go Hollow

ipc: Add pw_node_id to PipeWire Casts

Browse files at this commit

9015ff8e366eda75106c10edbba1d31eeaeac6cfIvan MolodetskikhParent: e546b33
niri-ipc/src/lib.rsmodified+5 -0
@@ -1509,6 +1509,11 @@ pub struct Cast {
15091509 ///
15101510 /// Currently, only wlr-screencopy screencasts can have a pid.
15111511 pub pid: Option<i32>,
1512+ /// PipeWire node ID of the screencast stream.
1513+ ///
1514+ /// This is `None` for wlr-screencopy casts, and also for PipeWire casts before the node is
1515+ /// created (when the cast is just starting up).
1516+ pub pw_node_id: Option<u32>,
15121517 }
15131518
15141519 /// Kind of screencast.
src/ipc/client.rsmodified+4 -0
@@ -768,6 +768,10 @@ fn print_cast(cast: &Cast) {
768768 if let Some(pid) = cast.pid {
769769 println!(" PID: {pid}");
770770 }
771+
772+ if let Some(node_id) = cast.pw_node_id {
773+ println!(" PipeWire node ID: {node_id}");
774+ }
771775 }
772776
773777 fn fmt_rounded(x: f64) -> String {
src/ipc/server.rsmodified+7 -1
@@ -830,6 +830,7 @@ impl State {
830830 is_dynamic_target: true,
831831 is_active: false,
832832 pid: None,
833+ pw_node_id: None,
833834 };
834835 events.push(Event::CastStartedOrChanged { cast });
835836 }
@@ -840,9 +841,12 @@ impl State {
840841 let stream_id = cast.stream_id.get();
841842 seen.insert(stream_id);
842843
844+ let pw_node_id = cast.node_id();
843845 if state.casts.get(&stream_id).is_none_or(|existing| {
844846 // Only these properties can change.
845- existing.is_active != cast.is_active() || !cast.target.matches(&existing.target)
847+ existing.is_active != cast.is_active()
848+ || !cast.target.matches(&existing.target)
849+ || existing.pw_node_id != pw_node_id
846850 }) {
847851 let cast = niri_ipc::Cast {
848852 session_id: cast.session_id.get(),
@@ -852,6 +856,7 @@ impl State {
852856 is_dynamic_target: cast.dynamic_target,
853857 is_active: cast.is_active(),
854858 pid: None,
859+ pw_node_id,
855860 };
856861 events.push(Event::CastStartedOrChanged { cast });
857862 }
@@ -886,6 +891,7 @@ impl State {
886891 is_dynamic_target: false,
887892 is_active: true,
888893 pid: queue.credentials().map(|creds| creds.pid),
894+ pw_node_id: None,
889895 };
890896 events.push(Event::CastStartedOrChanged { cast });
891897 }
src/screencasting/pw_utils.rsmodified+4 -0
@@ -819,6 +819,10 @@ impl Cast {
819819 self.inner.borrow().is_active
820820 }
821821
822+ pub fn node_id(&self) -> Option<u32> {
823+ self.inner.borrow().node_id
824+ }
825+
822826 pub fn ensure_size(&self, size: Size<i32, Physical>) -> anyhow::Result<CastSizeChange> {
823827 let mut inner = self.inner.borrow_mut();
824828