diff --git a/Cargo.lock b/Cargo.lock index 4714f34..1a1bc3d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1194,7 +1194,6 @@ dependencies = [ name = "input-capture" version = "0.1.0" dependencies = [ - "anyhow", "ashpd", "async-trait", "core-graphics", diff --git a/input-capture/Cargo.toml b/input-capture/Cargo.toml index 0a92017..aedfae5 100644 --- a/input-capture/Cargo.toml +++ b/input-capture/Cargo.toml @@ -7,7 +7,6 @@ license = "GPL-3.0-or-later" repository = "https://github.com/ferdinandschober/lan-mouse" [dependencies] -anyhow = "1.0.86" futures = "0.3.28" futures-core = "0.3.30" log = "0.4.22" @@ -15,25 +14,42 @@ input-event = { path = "../input-event", version = "0.1.0" } memmap = "0.7" tempfile = "3.8" thiserror = "1.0.61" -tokio = { version = "1.32.0", features = ["io-util", "io-std", "macros", "net", "process", "rt", "sync", "signal"] } +tokio = { version = "1.32.0", features = [ + "io-util", + "io-std", + "macros", + "net", + "process", + "rt", + "sync", + "signal", +] } once_cell = "1.19.0" async-trait = "0.1.81" tokio-util = "0.7.11" [target.'cfg(all(unix, not(target_os="macos")))'.dependencies] -wayland-client = { version="0.31.1", optional = true } -wayland-protocols = { version="0.32.1", features=["client", "staging", "unstable"], optional = true } -wayland-protocols-wlr = { version="0.3.1", features=["client"], optional = true } +wayland-client = { version = "0.31.1", optional = true } +wayland-protocols = { version = "0.32.1", features = [ + "client", + "staging", + "unstable", +], optional = true } +wayland-protocols-wlr = { version = "0.3.1", features = [ + "client", +], optional = true } x11 = { version = "2.21.0", features = ["xlib", "xtest"], optional = true } -ashpd = { version = "0.8", default-features = false, features = ["tokio"], optional = true } -reis = { version = "0.2", features = [ "tokio" ], optional = true } +ashpd = { version = "0.8", default-features = false, features = [ + "tokio", +], optional = true } +reis = { version = "0.2", features = ["tokio"], optional = true } [target.'cfg(target_os="macos")'.dependencies] core-graphics = { version = "0.23", features = ["highsierra"] } [target.'cfg(windows)'.dependencies] -windows = { version = "0.57.0", features = [ +windows = { version = "0.57.0", features = [ "Win32_System_LibraryLoader", "Win32_System_Threading", "Win32_Foundation", @@ -45,6 +61,10 @@ windows = { version = "0.57.0", features = [ [features] default = ["wayland", "x11", "libei"] -wayland = ["dep:wayland-client", "dep:wayland-protocols", "dep:wayland-protocols-wlr" ] +wayland = [ + "dep:wayland-client", + "dep:wayland-protocols", + "dep:wayland-protocols-wlr", +] x11 = ["dep:x11"] libei = ["dep:reis", "dep:ashpd"] diff --git a/input-capture/src/error.rs b/input-capture/src/error.rs index 2541649..2866c82 100644 --- a/input-capture/src/error.rs +++ b/input-capture/src/error.rs @@ -1,5 +1,13 @@ use thiserror::Error; +#[derive(Debug, Error)] +pub enum InputCaptureError { + #[error("error creating input-capture: `{0}`")] + Create(#[from] CaptureCreationError), + #[error("error while capturing input: `{0}`")] + Capture(#[from] CaptureError), +} + #[cfg(all(unix, feature = "wayland", not(target_os = "macos")))] use std::io; #[cfg(all(unix, feature = "wayland", not(target_os = "macos")))] diff --git a/input-capture/src/lib.rs b/input-capture/src/lib.rs index ca0aea7..53505aa 100644 --- a/input-capture/src/lib.rs +++ b/input-capture/src/lib.rs @@ -5,7 +5,7 @@ use futures_core::Stream; use input_event::Event; -pub use error::{CaptureCreationError, CaptureError}; +pub use error::{CaptureCreationError, CaptureError, InputCaptureError}; pub mod error; diff --git a/input-emulation/src/error.rs b/input-emulation/src/error.rs index 3fd8ca4..bb54b90 100644 --- a/input-emulation/src/error.rs +++ b/input-emulation/src/error.rs @@ -1,3 +1,11 @@ +#[derive(Debug, Error)] +pub enum InputEmulationError { + #[error("error creating input-emulation: `{0}`")] + Create(#[from] EmulationCreationError), + #[error("error emulating input: `{0}`")] + Emulate(#[from] EmulationError), +} + #[cfg(all(unix, feature = "libei", not(target_os = "macos")))] use ashpd::{desktop::ResponseError, Error::Response}; #[cfg(all(unix, feature = "libei", not(target_os = "macos")))] diff --git a/input-emulation/src/lib.rs b/input-emulation/src/lib.rs index 3e7d0cd..f9adf3e 100644 --- a/input-emulation/src/lib.rs +++ b/input-emulation/src/lib.rs @@ -1,10 +1,9 @@ use async_trait::async_trait; -use error::EmulationError; use std::fmt::Display; use input_event::Event; -use self::error::EmulationCreationError; +pub use self::error::{EmulationCreationError, EmulationError, InputEmulationError}; #[cfg(windows)] pub mod windows; diff --git a/src/capture_test.rs b/src/capture_test.rs index d1df408..4eafc05 100644 --- a/src/capture_test.rs +++ b/src/capture_test.rs @@ -1,11 +1,10 @@ use crate::config::Config; -use anyhow::Result; use futures::StreamExt; -use input_capture::{self, CaptureError, InputCapture, Position}; +use input_capture::{self, CaptureError, InputCapture, InputCaptureError, Position}; use input_event::{Event, KeyboardEvent}; use tokio::task::LocalSet; -pub fn run() -> Result<()> { +pub fn run() -> anyhow::Result<()> { log::info!("running input capture test"); let runtime = tokio::runtime::Builder::new_current_thread() .enable_io() @@ -14,10 +13,10 @@ pub fn run() -> Result<()> { let config = Config::new()?; - runtime.block_on(LocalSet::new().run_until(input_capture_test(config))) + Ok(runtime.block_on(LocalSet::new().run_until(input_capture_test(config)))?) } -async fn input_capture_test(config: Config) -> Result<()> { +async fn input_capture_test(config: Config) -> Result<(), InputCaptureError> { log::info!("creating input capture"); let backend = config.capture_backend.map(|b| b.into()); loop { diff --git a/src/dns.rs b/src/dns.rs index 4decdc5..bdbabee 100644 --- a/src/dns.rs +++ b/src/dns.rs @@ -1,4 +1,3 @@ -use anyhow::Result; use std::net::IpAddr; use tokio::sync::mpsc::Receiver; @@ -12,7 +11,7 @@ pub(crate) struct DnsResolver { } impl DnsResolver { - pub(crate) fn new(dns_request: Receiver) -> Result { + pub(crate) fn new(dns_request: Receiver) -> Result { let resolver = TokioAsyncResolver::tokio_from_system_conf()?; Ok(Self { resolver, diff --git a/src/server/capture_task.rs b/src/server/capture_task.rs index 17001ca..616016b 100644 --- a/src/server/capture_task.rs +++ b/src/server/capture_task.rs @@ -1,6 +1,5 @@ use futures::StreamExt; use std::{collections::HashSet, net::SocketAddr}; -use thiserror::Error; use tokio::{ process::Command, @@ -8,9 +7,7 @@ use tokio::{ task::JoinHandle, }; -use input_capture::{ - self, error::CaptureCreationError, CaptureError, CaptureHandle, InputCapture, Position, -}; +use input_capture::{self, CaptureError, CaptureHandle, InputCapture, InputCaptureError, Position}; use input_event::{scancode, Event, KeyboardEvent}; @@ -18,14 +15,6 @@ use crate::{client::ClientHandle, frontend::Status, server::State}; use super::Server; -#[derive(Debug, Error)] -pub(crate) enum LanMouseCaptureError { - #[error("error creating input-capture: `{0}`")] - Create(#[from] CaptureCreationError), - #[error("error while capturing input: `{0}`")] - Capture(#[from] CaptureError), -} - #[derive(Clone, Copy, Debug)] pub(crate) enum CaptureEvent { /// capture must release the mouse @@ -76,7 +65,7 @@ async fn do_capture( server: &Server, sender_tx: &Sender<(Event, SocketAddr)>, notify_rx: &mut Receiver, -) -> Result<(), LanMouseCaptureError> { +) -> Result<(), InputCaptureError> { /* allow cancelling capture request */ let mut capture = tokio::select! { r = input_capture::create(backend) => { diff --git a/src/server/emulation_task.rs b/src/server/emulation_task.rs index f788e95..e111dbb 100644 --- a/src/server/emulation_task.rs +++ b/src/server/emulation_task.rs @@ -1,6 +1,5 @@ use std::net::SocketAddr; -use thiserror::Error; use tokio::{ sync::mpsc::{Receiver, Sender}, task::JoinHandle, @@ -11,11 +10,7 @@ use crate::{ frontend::Status, server::State, }; -use input_emulation::{ - self, - error::{EmulationCreationError, EmulationError}, - EmulationHandle, InputEmulation, -}; +use input_emulation::{self, EmulationError, EmulationHandle, InputEmulation, InputEmulationError}; use input_event::{Event, KeyboardEvent}; use super::{network_task::NetworkError, CaptureEvent, Server}; @@ -41,14 +36,6 @@ pub(crate) fn new( tokio::task::spawn_local(emulation_task) } -#[derive(Debug, Error)] -pub enum LanMouseEmulationError { - #[error("error creating input-emulation: `{0}`")] - Create(#[from] EmulationCreationError), - #[error("error emulating input: `{0}`")] - Emulate(#[from] EmulationError), -} - async fn emulation_task( server: Server, mut rx: Receiver, @@ -82,7 +69,7 @@ async fn do_emulation( udp_rx: &mut Receiver>, sender_tx: &Sender<(Event, SocketAddr)>, capture_tx: &Sender, -) -> Result<(), LanMouseEmulationError> { +) -> Result<(), InputEmulationError> { let backend = server.config.emulation_backend.map(|b| b.into()); log::info!("creating input emulation..."); let mut emulation = tokio::select! { @@ -117,7 +104,7 @@ async fn do_emulation_session( udp_rx: &mut Receiver>, sender_tx: &Sender<(Event, SocketAddr)>, capture_tx: &Sender, -) -> Result<(), LanMouseEmulationError> { +) -> Result<(), InputEmulationError> { let mut last_ignored = None; loop {