diff --git a/input-capture/src/dummy.rs b/input-capture/src/dummy.rs index 12b1463..2605c96 100644 --- a/input-capture/src/dummy.rs +++ b/input-capture/src/dummy.rs @@ -39,7 +39,7 @@ impl<'a> InputCapture for DummyInputCapture { Ok(()) } - async fn async_drop(&mut self) -> Result<(), CaptureError> { + async fn terminate(&mut self) -> Result<(), CaptureError> { Ok(()) } } diff --git a/input-capture/src/lib.rs b/input-capture/src/lib.rs index c5380e6..9e72160 100644 --- a/input-capture/src/lib.rs +++ b/input-capture/src/lib.rs @@ -107,7 +107,7 @@ pub trait InputCapture: async fn release(&mut self) -> io::Result<()>; /// destroy the input acpture - async fn async_drop(&mut self) -> Result<(), CaptureError>; + async fn terminate(&mut self) -> Result<(), CaptureError>; } pub async fn create_backend( diff --git a/input-capture/src/libei.rs b/input-capture/src/libei.rs index da84c19..034d798 100644 --- a/input-capture/src/libei.rs +++ b/input-capture/src/libei.rs @@ -668,7 +668,7 @@ impl<'a> LanMouseInputCapture for LibeiInputCapture<'a> { Ok(()) } - async fn async_drop(&mut self) -> Result<(), CaptureError> { + async fn terminate(&mut self) -> Result<(), CaptureError> { let event_rx = self.event_rx.take().expect("no channel"); std::mem::drop(event_rx); self.cancellation_token.cancel(); diff --git a/input-capture/src/macos.rs b/input-capture/src/macos.rs index b549f5d..31a6ca7 100644 --- a/input-capture/src/macos.rs +++ b/input-capture/src/macos.rs @@ -1,6 +1,7 @@ use crate::{ error::MacOSInputCaptureCreationError, CaptureError, CaptureHandle, InputCapture, Position, }; +use async_trait::async_trait; use futures_core::Stream; use input_event::Event; use std::task::{Context, Poll}; @@ -22,16 +23,21 @@ impl Stream for MacOSInputCapture { } } +#[async_trait] impl InputCapture for MacOSInputCapture { - fn create(&mut self, _id: CaptureHandle, _pos: Position) -> io::Result<()> { + async fn create(&mut self, _id: CaptureHandle, _pos: Position) -> io::Result<()> { Ok(()) } - fn destroy(&mut self, _id: CaptureHandle) -> io::Result<()> { + async fn destroy(&mut self, _id: CaptureHandle) -> io::Result<()> { Ok(()) } - fn release(&mut self) -> io::Result<()> { + async fn release(&mut self) -> io::Result<()> { + Ok(()) + } + + async fn terminate(&mut self) -> Result<(), CaptureError> { Ok(()) } } diff --git a/input-capture/src/wayland.rs b/input-capture/src/wayland.rs index f8e83ea..cbaf1d9 100644 --- a/input-capture/src/wayland.rs +++ b/input-capture/src/wayland.rs @@ -585,7 +585,7 @@ impl InputCapture for WaylandInputCapture { inner.flush_events() } - async fn async_drop(&mut self) -> Result<(), CaptureError> { + async fn terminate(&mut self) -> Result<(), CaptureError> { Ok(()) } } diff --git a/input-capture/src/windows.rs b/input-capture/src/windows.rs index bf9ad4e..54bee50 100644 --- a/input-capture/src/windows.rs +++ b/input-capture/src/windows.rs @@ -1,3 +1,4 @@ +use async_trait::async_trait; use core::task::{Context, Poll}; use futures::Stream; use once_cell::unsync::Lazy; @@ -62,8 +63,9 @@ unsafe fn signal_message_thread(event_type: EventType) { } } +#[async_trait] impl InputCapture for WindowsInputCapture { - fn create(&mut self, handle: CaptureHandle, pos: Position) -> io::Result<()> { + async fn create(&mut self, handle: CaptureHandle, pos: Position) -> io::Result<()> { unsafe { { let mut requests = REQUEST_BUFFER.lock().unwrap(); @@ -73,7 +75,8 @@ impl InputCapture for WindowsInputCapture { } Ok(()) } - fn destroy(&mut self, handle: CaptureHandle) -> io::Result<()> { + + async fn destroy(&mut self, handle: CaptureHandle) -> io::Result<()> { unsafe { { let mut requests = REQUEST_BUFFER.lock().unwrap(); @@ -84,10 +87,14 @@ impl InputCapture for WindowsInputCapture { Ok(()) } - fn release(&mut self) -> io::Result<()> { + async fn release(&mut self) -> io::Result<()> { unsafe { signal_message_thread(EventType::Release) }; Ok(()) } + + async fn terminate(&mut self) -> Result<(), CaptureError> { + Ok(()) + } } static mut REQUEST_BUFFER: Mutex> = Mutex::new(Vec::new()); diff --git a/input-capture/src/x11.rs b/input-capture/src/x11.rs index 02dcfe4..b7eb485 100644 --- a/input-capture/src/x11.rs +++ b/input-capture/src/x11.rs @@ -34,7 +34,7 @@ impl InputCapture for X11InputCapture { Ok(()) } - async fn async_drop(&mut self) -> Result<(), CaptureError> { + async fn terminate(&mut self) -> Result<(), CaptureError> { Ok(()) } } diff --git a/src/capture_test.rs b/src/capture_test.rs index a809809..aff63ba 100644 --- a/src/capture_test.rs +++ b/src/capture_test.rs @@ -62,7 +62,7 @@ async fn input_capture_test(config: Config) -> Result<()> { break; } } - input_capture.take().unwrap().async_drop().await.unwrap(); + input_capture.take().unwrap().terminate().await.unwrap(); } Ok(()) } diff --git a/src/server/capture_task.rs b/src/server/capture_task.rs index e1b4dff..387317d 100644 --- a/src/server/capture_task.rs +++ b/src/server/capture_task.rs @@ -59,7 +59,7 @@ pub fn new( CaptureEvent::Destroy(h) => capture.destroy(h).await?, CaptureEvent::Restart => { let clients = server.client_manager.borrow().get_client_states().map(|(h, (c,_))| (h, c.pos)).collect::>(); - capture.async_drop().await?; + capture.terminate().await?; capture = input_capture::create(backend).await?; for (handle, pos) in clients { capture.create(handle, pos.into()).await?;