11use ashpd:: {
2- desktop:: screencast:: { CursorMode , Screencast } ,
2+ desktop:: {
3+ Session ,
4+ screencast:: { CursorMode , Screencast } ,
5+ } ,
36 enumflags2:: BitFlags ,
47} ;
58use std:: { os:: fd:: OwnedFd , thread} ;
@@ -168,8 +171,8 @@ pub struct CapturedDmaBufferSync {
168171#[ error( "Stream has been closed" ) ]
169172pub struct StreamClosedError ;
170173
171- #[ derive( Clone ) ]
172174pub struct StreamHandle {
175+ session : Session < ' static , Screencast < ' static > > ,
173176 sender : pipewire:: channel:: Sender < stream:: Command > ,
174177}
175178
@@ -186,7 +189,11 @@ impl StreamHandle {
186189 . map_err ( |_| StreamClosedError )
187190 }
188191
189- pub fn close ( & self ) -> Result < ( ) , StreamClosedError > {
192+ pub async fn close ( & self ) -> Result < ( ) , StreamClosedError > {
193+ if let Err ( e) = self . session . close ( ) . await {
194+ log:: warn!( "Failed to close xdg session properly {e}" ) ;
195+ }
196+
190197 self . sender
191198 . send ( stream:: Command :: Close )
192199 . map_err ( |_| StreamClosedError )
@@ -279,5 +286,5 @@ async fn start_screen_capture_boxed(
279286 . await
280287 . map_err ( |_| StartCaptureError :: CaptureThreadPanicked ) ??;
281288
282- Ok ( StreamHandle { sender } )
289+ Ok ( StreamHandle { session , sender } )
283290}
0 commit comments