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 {
1509 ///1509 ///
1510 /// Currently, only wlr-screencopy screencasts can have a pid.1510 /// Currently, only wlr-screencopy screencasts can have a pid.
1511 pub pid: Option<i32>,1511 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>,
1512 }1517 }
1513 1518
1514 /// Kind of screencast.1519 /// Kind of screencast.
src/ipc/client.rsmodified+4 -0
@@ -768,6 +768,10 @@ fn print_cast(cast: &Cast) {
768 if let Some(pid) = cast.pid {768 if let Some(pid) = cast.pid {
769 println!(" PID: {pid}");769 println!(" PID: {pid}");
770 }770 }
771+
772+ if let Some(node_id) = cast.pw_node_id {
773+ println!(" PipeWire node ID: {node_id}");
774+ }
771 }775 }
772 776
773 fn fmt_rounded(x: f64) -> String {777 fn fmt_rounded(x: f64) -> String {
src/ipc/server.rsmodified+7 -1
@@ -830,6 +830,7 @@ impl State {
830 is_dynamic_target: true,830 is_dynamic_target: true,
831 is_active: false,831 is_active: false,
832 pid: None,832 pid: None,
833+ pw_node_id: None,
833 };834 };
834 events.push(Event::CastStartedOrChanged { cast });835 events.push(Event::CastStartedOrChanged { cast });
835 }836 }
@@ -840,9 +841,12 @@ impl State {
840 let stream_id = cast.stream_id.get();841 let stream_id = cast.stream_id.get();
841 seen.insert(stream_id);842 seen.insert(stream_id);
842 843
844+ let pw_node_id = cast.node_id();
843 if state.casts.get(&stream_id).is_none_or(|existing| {845 if state.casts.get(&stream_id).is_none_or(|existing| {
844 // Only these properties can change.846 // 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
846 }) {850 }) {
847 let cast = niri_ipc::Cast {851 let cast = niri_ipc::Cast {
848 session_id: cast.session_id.get(),852 session_id: cast.session_id.get(),
@@ -852,6 +856,7 @@ impl State {
852 is_dynamic_target: cast.dynamic_target,856 is_dynamic_target: cast.dynamic_target,
853 is_active: cast.is_active(),857 is_active: cast.is_active(),
854 pid: None,858 pid: None,
859+ pw_node_id,
855 };860 };
856 events.push(Event::CastStartedOrChanged { cast });861 events.push(Event::CastStartedOrChanged { cast });
857 }862 }
@@ -886,6 +891,7 @@ impl State {
886 is_dynamic_target: false,891 is_dynamic_target: false,
887 is_active: true,892 is_active: true,
888 pid: queue.credentials().map(|creds| creds.pid),893 pid: queue.credentials().map(|creds| creds.pid),
894+ pw_node_id: None,
889 };895 };
890 events.push(Event::CastStartedOrChanged { cast });896 events.push(Event::CastStartedOrChanged { cast });
891 }897 }
src/screencasting/pw_utils.rsmodified+4 -0
@@ -819,6 +819,10 @@ impl Cast {
819 self.inner.borrow().is_active819 self.inner.borrow().is_active
820 }820 }
821 821
822+ pub fn node_id(&self) -> Option<u32> {
823+ self.inner.borrow().node_id
824+ }
825+
822 pub fn ensure_size(&self, size: Size<i32, Physical>) -> anyhow::Result<CastSizeChange> {826 pub fn ensure_size(&self, size: Size<i32, Physical>) -> anyhow::Result<CastSizeChange> {
823 let mut inner = self.inner.borrow_mut();827 let mut inner = self.inner.borrow_mut();
824 828