ipc: Add pw_node_id to PipeWire Casts
Browse files at this commit9015ff8e366eda75106c10edbba1d31eeaeac6cfParent: e546b334 changed files +20 -1
- niri-ipc/src/lib.rs +5 -0
- src/ipc/client.rs +4 -0
- src/ipc/server.rs +7 -1
- src/screencasting/pw_utils.rs +4 -0
niri-ipc/src/lib.rsmodified+5 -0
| @@ -1509,6 +1509,11 @@ pub struct Cast { | ||
| 1509 | 1509 | /// |
| 1510 | 1510 | /// Currently, only wlr-screencopy screencasts can have a pid. |
| 1511 | 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 | 1519 | /// Kind of screencast. |
src/ipc/client.rsmodified+4 -0
| @@ -768,6 +768,10 @@ fn print_cast(cast: &Cast) { | ||
| 768 | 768 | if let Some(pid) = cast.pid { |
| 769 | 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 | 777 | fn fmt_rounded(x: f64) -> String { |
src/ipc/server.rsmodified+7 -1
| @@ -830,6 +830,7 @@ impl State { | ||
| 830 | 830 | is_dynamic_target: true, |
| 831 | 831 | is_active: false, |
| 832 | 832 | pid: None, |
| 833 | + pw_node_id: None, | |
| 833 | 834 | }; |
| 834 | 835 | events.push(Event::CastStartedOrChanged { cast }); |
| 835 | 836 | } |
| @@ -840,9 +841,12 @@ impl State { | ||
| 840 | 841 | let stream_id = cast.stream_id.get(); |
| 841 | 842 | seen.insert(stream_id); |
| 842 | 843 | |
| 844 | + let pw_node_id = cast.node_id(); | |
| 843 | 845 | if state.casts.get(&stream_id).is_none_or(|existing| { |
| 844 | 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 | 851 | let cast = niri_ipc::Cast { |
| 848 | 852 | session_id: cast.session_id.get(), |
| @@ -852,6 +856,7 @@ impl State { | ||
| 852 | 856 | is_dynamic_target: cast.dynamic_target, |
| 853 | 857 | is_active: cast.is_active(), |
| 854 | 858 | pid: None, |
| 859 | + pw_node_id, | |
| 855 | 860 | }; |
| 856 | 861 | events.push(Event::CastStartedOrChanged { cast }); |
| 857 | 862 | } |
| @@ -886,6 +891,7 @@ impl State { | ||
| 886 | 891 | is_dynamic_target: false, |
| 887 | 892 | is_active: true, |
| 888 | 893 | pid: queue.credentials().map(|creds| creds.pid), |
| 894 | + pw_node_id: None, | |
| 889 | 895 | }; |
| 890 | 896 | events.push(Event::CastStartedOrChanged { cast }); |
| 891 | 897 | } |
src/screencasting/pw_utils.rsmodified+4 -0
| @@ -819,6 +819,10 @@ impl Cast { | ||
| 819 | 819 | 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 | 826 | pub fn ensure_size(&self, size: Size<i32, Physical>) -> anyhow::Result<CastSizeChange> { |
| 823 | 827 | let mut inner = self.inner.borrow_mut(); |
| 824 | 828 |