From 9015ff8e366eda75106c10edbba1d31eeaeac6cf Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Wed, 14 Jan 2026 17:48:30 +0300 Subject: [PATCH] ipc: Add pw_node_id to PipeWire Casts --- niri-ipc/src/lib.rs | 5 +++++ src/ipc/client.rs | 4 ++++ src/ipc/server.rs | 8 +++++++- src/screencasting/pw_utils.rs | 4 ++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/niri-ipc/src/lib.rs b/niri-ipc/src/lib.rs index 8eba86e6..61b5578a 100644 --- a/niri-ipc/src/lib.rs +++ b/niri-ipc/src/lib.rs @@ -1509,6 +1509,11 @@ pub struct Cast { /// /// Currently, only wlr-screencopy screencasts can have a pid. pub pid: Option, + /// PipeWire node ID of the screencast stream. + /// + /// This is `None` for wlr-screencopy casts, and also for PipeWire casts before the node is + /// created (when the cast is just starting up). + pub pw_node_id: Option, } /// Kind of screencast. diff --git a/src/ipc/client.rs b/src/ipc/client.rs index 923cfd0a..3c826bff 100644 --- a/src/ipc/client.rs +++ b/src/ipc/client.rs @@ -768,6 +768,10 @@ fn print_cast(cast: &Cast) { if let Some(pid) = cast.pid { println!(" PID: {pid}"); } + + if let Some(node_id) = cast.pw_node_id { + println!(" PipeWire node ID: {node_id}"); + } } fn fmt_rounded(x: f64) -> String { diff --git a/src/ipc/server.rs b/src/ipc/server.rs index ee7d9e02..48c1234d 100644 --- a/src/ipc/server.rs +++ b/src/ipc/server.rs @@ -830,6 +830,7 @@ impl State { is_dynamic_target: true, is_active: false, pid: None, + pw_node_id: None, }; events.push(Event::CastStartedOrChanged { cast }); } @@ -840,9 +841,12 @@ impl State { let stream_id = cast.stream_id.get(); seen.insert(stream_id); + let pw_node_id = cast.node_id(); if state.casts.get(&stream_id).is_none_or(|existing| { // Only these properties can change. - existing.is_active != cast.is_active() || !cast.target.matches(&existing.target) + existing.is_active != cast.is_active() + || !cast.target.matches(&existing.target) + || existing.pw_node_id != pw_node_id }) { let cast = niri_ipc::Cast { session_id: cast.session_id.get(), @@ -852,6 +856,7 @@ impl State { is_dynamic_target: cast.dynamic_target, is_active: cast.is_active(), pid: None, + pw_node_id, }; events.push(Event::CastStartedOrChanged { cast }); } @@ -886,6 +891,7 @@ impl State { is_dynamic_target: false, is_active: true, pid: queue.credentials().map(|creds| creds.pid), + pw_node_id: None, }; events.push(Event::CastStartedOrChanged { cast }); } diff --git a/src/screencasting/pw_utils.rs b/src/screencasting/pw_utils.rs index 0dcaf014..048e1b7e 100644 --- a/src/screencasting/pw_utils.rs +++ b/src/screencasting/pw_utils.rs @@ -819,6 +819,10 @@ impl Cast { self.inner.borrow().is_active } + pub fn node_id(&self) -> Option { + self.inner.borrow().node_id + } + pub fn ensure_size(&self, size: Size) -> anyhow::Result { let mut inner = self.inner.borrow_mut();