diff --git a/src/capture.rs b/src/capture.rs index cfb05e3..731d8ee 100644 --- a/src/capture.rs +++ b/src/capture.rs @@ -3,10 +3,6 @@ use std::io; use futures_core::Stream; use crate::{ - capture::{ - dummy::DummyInputCapture, libei::LibeiInputCapture, wayland::WaylandInputCapture, - x11::X11InputCapture, - }, client::{ClientEvent, ClientHandle}, config::CaptureBackend, event::Event, @@ -34,22 +30,23 @@ pub mod x11; /// fallback input capture (does not produce events) pub mod dummy; +#[allow(unreachable_code)] pub async fn create( backend: Option, ) -> Result>>, CaptureCreationError> { if let Some(backend) = backend { return match backend { #[cfg(all(unix, feature = "libei", not(target_os = "macos")))] - CaptureBackend::InputCapturePortal => Ok(Box::new(LibeiInputCapture::new().await?)), + CaptureBackend::InputCapturePortal => Ok(Box::new(libei::LibeiInputCapture::new().await?)), #[cfg(all(unix, feature = "wayland", not(target_os = "macos")))] - CaptureBackend::LayerShell => Ok(Box::new(WaylandInputCapture::new()?)), + CaptureBackend::LayerShell => Ok(Box::new(wayland::WaylandInputCapture::new()?)), #[cfg(all(unix, feature = "x11", not(target_os = "macos")))] - CaptureBackend::X11 => Ok(Box::new(X11InputCapture::new()?)), + CaptureBackend::X11 => Ok(Box::new(x11::X11InputCapture::new()?)), #[cfg(windows)] - CaptureBackend::Windows => Box::new(WindowsInputCapture::new()?), + CaptureBackend::Windows => Ok(Box::new(windows::WindowsInputCapture::new())), #[cfg(target_os = "macos")] CaptureBackend::MacOs => Box::new(MacOSInputCapture::new()?), - CaptureBackend::Dummy => Ok(Box::new(DummyInputCapture::new())), + CaptureBackend::Dummy => Ok(Box::new(dummy::DummyInputCapture::new())), }; } @@ -60,10 +57,7 @@ pub async fn create( } #[cfg(windows)] - match windows::WindowsInputCapture::new() { - Ok(p) => return Ok(Box::new(p)), - Err(e) => log::info!("windows input capture not available: {e}"), - } + return Ok(Box::new(windows::WindowsInputCapture::new())); #[cfg(all(unix, feature = "libei", not(target_os = "macos")))] match libei::LibeiInputCapture::new().await { diff --git a/src/capture/error.rs b/src/capture/error.rs index 54dc245..760764e 100644 --- a/src/capture/error.rs +++ b/src/capture/error.rs @@ -1,6 +1,6 @@ -use std::{fmt::Display, io}; - use thiserror::Error; + +#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))] use wayland_client::{ backend::WaylandError, globals::{BindError, GlobalError}, @@ -11,25 +11,26 @@ use wayland_client::{ pub enum CaptureCreationError { #[cfg(all(unix, feature = "libei", not(target_os = "macos")))] Libei(#[from] LibeiCaptureCreationError), + #[cfg(all(unix, feature = "wayland", not(target_os = "macos")))] LayerShell(#[from] LayerShellCaptureCreationError), + #[cfg(all(unix, feature = "x11", not(target_os = "macos")))] X11(#[from] X11InputCaptureCreationError), } -impl Display for CaptureCreationError { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let reason = match self { - #[cfg(all(unix, feature = "libei", not(target_os = "macos")))] - CaptureCreationError::Libei(reason) => { - format!("error creating portal backend: {reason}") - } - CaptureCreationError::LayerShell(reason) => { - format!("error creating layer-shell backend: {reason}") - } - CaptureCreationError::X11(e) => format!("{e}"), - }; - write!(f, "could not create input capture: {reason}") - } -} +// impl Display for CaptureCreationError { +// fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +// let reason = match self { +// CaptureCreationError::Libei(reason) => { +// format!("error creating portal backend: {reason}") +// } +// CaptureCreationError::LayerShell(reason) => { +// format!("error creating layer-shell backend: {reason}") +// } +// CaptureCreationError::X11(e) => format!("{e}"), +// }; +// write!(f, "could not create input capture: {reason}") +// } +// } #[cfg(all(unix, feature = "libei", not(target_os = "macos")))] #[derive(Debug, Error)] @@ -46,17 +47,20 @@ impl Display for LibeiCaptureCreationError { } } +#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))] #[derive(Debug, Error)] pub struct WaylandBindError { inner: BindError, protocol: &'static str, } +#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))] impl WaylandBindError { pub(crate) fn new(inner: BindError, protocol: &'static str) -> Self { Self { inner, protocol } } } +#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))] impl Display for WaylandBindError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!( @@ -96,11 +100,13 @@ impl Display for LayerShellCaptureCreationError { } } +#[cfg(all(unix, feature = "x11", not(target_os = "macos")))] #[derive(Debug, Error)] pub enum X11InputCaptureCreationError { NotImplemented, } +#[cfg(all(unix, feature = "x11", not(target_os = "macos")))] impl Display for X11InputCaptureCreationError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "X11 input capture is not yet implemented :(") diff --git a/src/capture/windows.rs b/src/capture/windows.rs index cd93bf5..eff4f9c 100644 --- a/src/capture/windows.rs +++ b/src/capture/windows.rs @@ -575,7 +575,7 @@ fn update_clients(client_event: ClientEvent) { } impl WindowsInputCapture { - pub(crate) fn new() -> Result { + pub(crate) fn new() -> Self { unsafe { let (tx, rx) = channel(10); EVENT_TX.replace(tx); @@ -583,10 +583,10 @@ impl WindowsInputCapture { let msg_thread = Some(thread::spawn(|| message_thread(ready_tx))); /* wait for thread to set its id */ ready_rx.recv().expect("channel closed"); - Ok(Self { + Self { msg_thread, event_rx: rx, - }) + } } } }