mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-04-18 07:21:29 +03:00
adapt windows
This commit is contained in:
@@ -3,10 +3,6 @@ use std::io;
|
|||||||
use futures_core::Stream;
|
use futures_core::Stream;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
capture::{
|
|
||||||
dummy::DummyInputCapture, libei::LibeiInputCapture, wayland::WaylandInputCapture,
|
|
||||||
x11::X11InputCapture,
|
|
||||||
},
|
|
||||||
client::{ClientEvent, ClientHandle},
|
client::{ClientEvent, ClientHandle},
|
||||||
config::CaptureBackend,
|
config::CaptureBackend,
|
||||||
event::Event,
|
event::Event,
|
||||||
@@ -34,22 +30,23 @@ pub mod x11;
|
|||||||
/// fallback input capture (does not produce events)
|
/// fallback input capture (does not produce events)
|
||||||
pub mod dummy;
|
pub mod dummy;
|
||||||
|
|
||||||
|
#[allow(unreachable_code)]
|
||||||
pub async fn create(
|
pub async fn create(
|
||||||
backend: Option<CaptureBackend>,
|
backend: Option<CaptureBackend>,
|
||||||
) -> Result<Box<dyn InputCapture<Item = io::Result<(ClientHandle, Event)>>>, CaptureCreationError> {
|
) -> Result<Box<dyn InputCapture<Item = io::Result<(ClientHandle, Event)>>>, CaptureCreationError> {
|
||||||
if let Some(backend) = backend {
|
if let Some(backend) = backend {
|
||||||
return match backend {
|
return match backend {
|
||||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
#[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")))]
|
#[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")))]
|
#[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)]
|
#[cfg(windows)]
|
||||||
CaptureBackend::Windows => Box::new(WindowsInputCapture::new()?),
|
CaptureBackend::Windows => Ok(Box::new(windows::WindowsInputCapture::new())),
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
CaptureBackend::MacOs => Box::new(MacOSInputCapture::new()?),
|
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)]
|
#[cfg(windows)]
|
||||||
match windows::WindowsInputCapture::new() {
|
return Ok(Box::new(windows::WindowsInputCapture::new()));
|
||||||
Ok(p) => return Ok(Box::new(p)),
|
|
||||||
Err(e) => log::info!("windows input capture not available: {e}"),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||||
match libei::LibeiInputCapture::new().await {
|
match libei::LibeiInputCapture::new().await {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::{fmt::Display, io};
|
|
||||||
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
|
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
||||||
use wayland_client::{
|
use wayland_client::{
|
||||||
backend::WaylandError,
|
backend::WaylandError,
|
||||||
globals::{BindError, GlobalError},
|
globals::{BindError, GlobalError},
|
||||||
@@ -11,25 +11,26 @@ use wayland_client::{
|
|||||||
pub enum CaptureCreationError {
|
pub enum CaptureCreationError {
|
||||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||||
Libei(#[from] LibeiCaptureCreationError),
|
Libei(#[from] LibeiCaptureCreationError),
|
||||||
|
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
||||||
LayerShell(#[from] LayerShellCaptureCreationError),
|
LayerShell(#[from] LayerShellCaptureCreationError),
|
||||||
|
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
|
||||||
X11(#[from] X11InputCaptureCreationError),
|
X11(#[from] X11InputCaptureCreationError),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for CaptureCreationError {
|
// impl Display for CaptureCreationError {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
// fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
let reason = match self {
|
// let reason = match self {
|
||||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
// CaptureCreationError::Libei(reason) => {
|
||||||
CaptureCreationError::Libei(reason) => {
|
// format!("error creating portal backend: {reason}")
|
||||||
format!("error creating portal backend: {reason}")
|
// }
|
||||||
}
|
// CaptureCreationError::LayerShell(reason) => {
|
||||||
CaptureCreationError::LayerShell(reason) => {
|
// format!("error creating layer-shell backend: {reason}")
|
||||||
format!("error creating layer-shell backend: {reason}")
|
// }
|
||||||
}
|
// CaptureCreationError::X11(e) => format!("{e}"),
|
||||||
CaptureCreationError::X11(e) => format!("{e}"),
|
// };
|
||||||
};
|
// write!(f, "could not create input capture: {reason}")
|
||||||
write!(f, "could not create input capture: {reason}")
|
// }
|
||||||
}
|
// }
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
@@ -46,17 +47,20 @@ impl Display for LibeiCaptureCreationError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub struct WaylandBindError {
|
pub struct WaylandBindError {
|
||||||
inner: BindError,
|
inner: BindError,
|
||||||
protocol: &'static str,
|
protocol: &'static str,
|
||||||
}
|
}
|
||||||
|
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
||||||
impl WaylandBindError {
|
impl WaylandBindError {
|
||||||
pub(crate) fn new(inner: BindError, protocol: &'static str) -> Self {
|
pub(crate) fn new(inner: BindError, protocol: &'static str) -> Self {
|
||||||
Self { inner, protocol }
|
Self { inner, protocol }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
||||||
impl Display for WaylandBindError {
|
impl Display for WaylandBindError {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
write!(
|
write!(
|
||||||
@@ -96,11 +100,13 @@ impl Display for LayerShellCaptureCreationError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum X11InputCaptureCreationError {
|
pub enum X11InputCaptureCreationError {
|
||||||
NotImplemented,
|
NotImplemented,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
|
||||||
impl Display for X11InputCaptureCreationError {
|
impl Display for X11InputCaptureCreationError {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
write!(f, "X11 input capture is not yet implemented :(")
|
write!(f, "X11 input capture is not yet implemented :(")
|
||||||
|
|||||||
@@ -575,7 +575,7 @@ fn update_clients(client_event: ClientEvent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl WindowsInputCapture {
|
impl WindowsInputCapture {
|
||||||
pub(crate) fn new() -> Result<Self> {
|
pub(crate) fn new() -> Self {
|
||||||
unsafe {
|
unsafe {
|
||||||
let (tx, rx) = channel(10);
|
let (tx, rx) = channel(10);
|
||||||
EVENT_TX.replace(tx);
|
EVENT_TX.replace(tx);
|
||||||
@@ -583,10 +583,10 @@ impl WindowsInputCapture {
|
|||||||
let msg_thread = Some(thread::spawn(|| message_thread(ready_tx)));
|
let msg_thread = Some(thread::spawn(|| message_thread(ready_tx)));
|
||||||
/* wait for thread to set its id */
|
/* wait for thread to set its id */
|
||||||
ready_rx.recv().expect("channel closed");
|
ready_rx.recv().expect("channel closed");
|
||||||
Ok(Self {
|
Self {
|
||||||
msg_thread,
|
msg_thread,
|
||||||
event_rx: rx,
|
event_rx: rx,
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user