fix windows/mac + rename async_drop to terminate

This commit is contained in:
Ferdinand Schober
2024-07-10 22:33:37 +02:00
parent ebf7897caa
commit ae3ea2c497
9 changed files with 26 additions and 13 deletions

View File

@@ -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(())
}
}

View File

@@ -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(

View File

@@ -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();

View File

@@ -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(())
}
}

View File

@@ -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(())
}
}

View File

@@ -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<Vec<Request>> = Mutex::new(Vec::new());

View File

@@ -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(())
}
}