@@ -2,6 +2,7 @@ use std::{
22 collections:: { HashMap , HashSet , VecDeque } ,
33 fmt:: Display ,
44 mem:: swap,
5+ sync:: { Arc , Mutex } ,
56 task:: { Poll , ready} ,
67} ;
78
@@ -129,6 +130,23 @@ pub struct InputCapture {
129130 pending : VecDeque < ( CaptureHandle , CaptureEvent ) > ,
130131}
131132
133+ #[ derive( Clone , Debug ) ]
134+ pub enum WindowIdentifier {
135+ Wayland ( String ) ,
136+ X11 ( u32 ) ,
137+ }
138+
139+ impl Into < ashpd:: WindowIdentifier > for WindowIdentifier {
140+ fn into ( self ) -> ashpd:: WindowIdentifier {
141+ match self {
142+ WindowIdentifier :: Wayland ( handle) => {
143+ ashpd:: WindowIdentifier :: from_xdg_foreign_exported_v2 ( handle)
144+ }
145+ WindowIdentifier :: X11 ( _) => todo ! ( ) ,
146+ }
147+ }
148+ }
149+
132150impl InputCapture {
133151 /// create a new client with the given id
134152 pub async fn create ( & mut self , id : CaptureHandle , pos : Position ) -> Result < ( ) , CaptureError > {
@@ -177,8 +195,11 @@ impl InputCapture {
177195 }
178196
179197 /// creates a new [`InputCapture`]
180- pub async fn new ( backend : Option < Backend > ) -> Result < Self , CaptureCreationError > {
181- let capture = create ( backend) . await ?;
198+ pub async fn new (
199+ backend : Option < Backend > ,
200+ window_identifier : Arc < Mutex < Option < WindowIdentifier > > > ,
201+ ) -> Result < Self , CaptureCreationError > {
202+ let capture = create ( backend, window_identifier) . await ?;
182203 Ok ( Self {
183204 capture,
184205 id_map : Default :: default ( ) ,
@@ -280,13 +301,16 @@ trait Capture: Stream<Item = Result<(Position, CaptureEvent), CaptureError>> + U
280301
281302async fn create_backend (
282303 backend : Backend ,
304+ window_identifier : Arc < Mutex < Option < WindowIdentifier > > > ,
283305) -> Result <
284306 Box < dyn Capture < Item = Result < ( Position , CaptureEvent ) , CaptureError > > > ,
285307 CaptureCreationError ,
286308> {
287309 match backend {
288310 #[ cfg( all( unix, feature = "libei" , not( target_os = "macos" ) ) ) ]
289- Backend :: InputCapturePortal => Ok ( Box :: new ( libei:: LibeiInputCapture :: new ( ) . await ?) ) ,
311+ Backend :: InputCapturePortal => Ok ( Box :: new (
312+ libei:: LibeiInputCapture :: new ( window_identifier) . await ?,
313+ ) ) ,
290314 #[ cfg( all( unix, feature = "layer_shell" , not( target_os = "macos" ) ) ) ]
291315 Backend :: LayerShell => Ok ( Box :: new ( layer_shell:: LayerShellInputCapture :: new ( ) ?) ) ,
292316 #[ cfg( all( unix, feature = "x11" , not( target_os = "macos" ) ) ) ]
@@ -301,12 +325,13 @@ async fn create_backend(
301325
302326async fn create (
303327 backend : Option < Backend > ,
328+ window_identifier : Arc < Mutex < Option < WindowIdentifier > > > ,
304329) -> Result <
305330 Box < dyn Capture < Item = Result < ( Position , CaptureEvent ) , CaptureError > > > ,
306331 CaptureCreationError ,
307332> {
308333 if let Some ( backend) = backend {
309- let b = create_backend ( backend) . await ;
334+ let b = create_backend ( backend, window_identifier ) . await ;
310335 if b. is_ok ( ) {
311336 log:: info!( "using capture backend: {backend}" ) ;
312337 }
@@ -325,7 +350,7 @@ async fn create(
325350 #[ cfg( target_os = "macos" ) ]
326351 Backend :: MacOs ,
327352 ] {
328- match create_backend ( backend) . await {
353+ match create_backend ( backend, window_identifier . clone ( ) ) . await {
329354 Ok ( b) => {
330355 log:: info!( "using capture backend: {backend}" ) ;
331356 return Ok ( b) ;
0 commit comments