mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-03-19 11:10:55 +03:00
Configurable capture backend (#150)
capture backend can now be configured via the `capture_backend` cli argument / config entry
This commit is contained in:
committed by
GitHub
parent
232c048c19
commit
3528ef4fae
@@ -4,9 +4,14 @@ use futures_core::Stream;
|
||||
|
||||
use crate::{
|
||||
client::{ClientEvent, ClientHandle},
|
||||
config::CaptureBackend,
|
||||
event::Event,
|
||||
};
|
||||
|
||||
use self::error::CaptureCreationError;
|
||||
|
||||
pub mod error;
|
||||
|
||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||
pub mod libei;
|
||||
|
||||
@@ -25,24 +30,42 @@ pub mod x11;
|
||||
/// fallback input capture (does not produce events)
|
||||
pub mod dummy;
|
||||
|
||||
pub async fn create() -> Box<dyn InputCapture<Item = io::Result<(ClientHandle, Event)>>> {
|
||||
#[allow(unreachable_code)]
|
||||
pub async fn create(
|
||||
backend: Option<CaptureBackend>,
|
||||
) -> Result<Box<dyn InputCapture<Item = io::Result<(ClientHandle, Event)>>>, CaptureCreationError> {
|
||||
if let Some(backend) = backend {
|
||||
return match backend {
|
||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||
CaptureBackend::InputCapturePortal => {
|
||||
Ok(Box::new(libei::LibeiInputCapture::new().await?))
|
||||
}
|
||||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
||||
CaptureBackend::LayerShell => Ok(Box::new(wayland::WaylandInputCapture::new()?)),
|
||||
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
|
||||
CaptureBackend::X11 => Ok(Box::new(x11::X11InputCapture::new()?)),
|
||||
#[cfg(windows)]
|
||||
CaptureBackend::Windows => Ok(Box::new(windows::WindowsInputCapture::new())),
|
||||
#[cfg(target_os = "macos")]
|
||||
CaptureBackend::MacOs => Ok(Box::new(macos::MacOSInputCapture::new()?)),
|
||||
CaptureBackend::Dummy => Ok(Box::new(dummy::DummyInputCapture::new())),
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
match macos::MacOSInputCapture::new() {
|
||||
Ok(p) => return Box::new(p),
|
||||
Ok(p) => return Ok(Box::new(p)),
|
||||
Err(e) => log::info!("macos input capture not available: {e}"),
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
match windows::WindowsInputCapture::new() {
|
||||
Ok(p) => return 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 {
|
||||
Ok(p) => {
|
||||
log::info!("using libei input capture");
|
||||
return Box::new(p);
|
||||
return Ok(Box::new(p));
|
||||
}
|
||||
Err(e) => log::info!("libei input capture not available: {e}"),
|
||||
}
|
||||
@@ -51,7 +74,7 @@ pub async fn create() -> Box<dyn InputCapture<Item = io::Result<(ClientHandle, E
|
||||
match wayland::WaylandInputCapture::new() {
|
||||
Ok(p) => {
|
||||
log::info!("using layer-shell input capture");
|
||||
return Box::new(p);
|
||||
return Ok(Box::new(p));
|
||||
}
|
||||
Err(e) => log::info!("layer_shell input capture not available: {e}"),
|
||||
}
|
||||
@@ -60,13 +83,13 @@ pub async fn create() -> Box<dyn InputCapture<Item = io::Result<(ClientHandle, E
|
||||
match x11::X11InputCapture::new() {
|
||||
Ok(p) => {
|
||||
log::info!("using x11 input capture");
|
||||
return Box::new(p);
|
||||
return Ok(Box::new(p));
|
||||
}
|
||||
Err(e) => log::info!("x11 input capture not available: {e}"),
|
||||
}
|
||||
|
||||
log::error!("falling back to dummy input capture");
|
||||
Box::new(dummy::DummyInputCapture::new())
|
||||
Ok(Box::new(dummy::DummyInputCapture::new()))
|
||||
}
|
||||
|
||||
pub trait InputCapture: Stream<Item = io::Result<(ClientHandle, Event)>> + Unpin {
|
||||
|
||||
Reference in New Issue
Block a user