mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-04-15 00:11:26 +03:00
fix compilation errors
This commit is contained in:
@@ -2,7 +2,9 @@ use async_trait::async_trait;
|
|||||||
use std::future;
|
use std::future;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
client::{ClientEvent, ClientHandle}, config::EmulationBackend, event::Event
|
client::{ClientEvent, ClientHandle},
|
||||||
|
config::EmulationBackend,
|
||||||
|
event::Event,
|
||||||
};
|
};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
||||||
@@ -43,7 +45,18 @@ pub trait InputEmulation: Send {
|
|||||||
async fn destroy(&mut self);
|
async fn destroy(&mut self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create(backend: Option<EmulationBackend>) -> Result<Box<dyn InputEmulation>, EmulationCreationError> {
|
pub async fn create(
|
||||||
|
backend: Option<EmulationBackend>,
|
||||||
|
) -> Result<Box<dyn InputEmulation>, EmulationCreationError> {
|
||||||
|
if let Some(backend) = backend {
|
||||||
|
return match backend {
|
||||||
|
EmulationBackend::Libei => Ok(Box::new(libei::LibeiEmulation::new().await?)),
|
||||||
|
EmulationBackend::Wlroots => Ok(Box::new(wlroots::WlrootsEmulation::new()?)),
|
||||||
|
EmulationBackend::X11 => Ok(Box::new(x11::X11Emulation::new()?)),
|
||||||
|
EmulationBackend::Dummy => Ok(Box::new(dummy::DummyEmulation::new())),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
match windows::WindowsEmulation::new() {
|
match windows::WindowsEmulation::new() {
|
||||||
Ok(c) => return Ok(Box::new(c)),
|
Ok(c) => return Ok(Box::new(c)),
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
use std::{fmt::Display, io};
|
use std::{fmt::Display, io};
|
||||||
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use wayland_client::{backend::WaylandError, globals::{BindError, GlobalError}, ConnectError, DispatchError};
|
use wayland_client::{
|
||||||
|
backend::WaylandError,
|
||||||
|
globals::{BindError, GlobalError},
|
||||||
|
ConnectError, DispatchError,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum EmulationCreationError {
|
pub enum EmulationCreationError {
|
||||||
@@ -20,9 +23,9 @@ impl Display for EmulationCreationError {
|
|||||||
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 {
|
||||||
EmulationCreationError::Wlroots(e) => format!("wlroots backend: {e}"),
|
EmulationCreationError::Wlroots(e) => format!("wlroots backend: {e}"),
|
||||||
EmulationCreationError::Libei(e) => todo!("libei backend: {e}"),
|
EmulationCreationError::Libei(e) => format!("libei backend: {e}"),
|
||||||
EmulationCreationError::Xdp(e) => todo!("desktop portal backend: {e}"),
|
EmulationCreationError::Xdp(e) => format!("desktop portal backend: {e}"),
|
||||||
EmulationCreationError::X11(e) => todo!("x11 backend: {e}"),
|
EmulationCreationError::X11(e) => format!("x11 backend: {e}"),
|
||||||
};
|
};
|
||||||
write!(f, "could not create input emulation backend: {reason}")
|
write!(f, "could not create input emulation backend: {reason}")
|
||||||
}
|
}
|
||||||
@@ -52,7 +55,6 @@ impl WaylandBindError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
#[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 {
|
||||||
@@ -84,15 +86,36 @@ impl Display for WlrootsEmulationCreationError {
|
|||||||
|
|
||||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum LibeiEmulationCreationError {}
|
pub enum LibeiEmulationCreationError {
|
||||||
|
Ashpd(#[from] ashpd::Error),
|
||||||
|
Io(#[from] io::Error),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||||
|
impl Display for LibeiEmulationCreationError {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
LibeiEmulationCreationError::Ashpd(e) => write!(f, "xdg-desktop-portal: {e}"),
|
||||||
|
LibeiEmulationCreationError::Io(e) => write!(f, "io error: {e}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(all(unix, feature = "xdg_desktop_portal", not(target_os = "macos")))]
|
#[cfg(all(unix, feature = "xdg_desktop_portal", not(target_os = "macos")))]
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum XdpEmulationCreationError {}
|
pub enum XdpEmulationCreationError {}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
|
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum X11EmulationCreationError {}
|
pub enum X11EmulationCreationError {
|
||||||
|
OpenDisplay,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
|
||||||
|
impl Display for X11EmulationCreationError {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
X11EmulationCreationError::OpenDisplay => write!(f, "could not open display!"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
|
io,
|
||||||
os::{fd::OwnedFd, unix::net::UnixStream},
|
os::{fd::OwnedFd, unix::net::UnixStream},
|
||||||
time::{SystemTime, UNIX_EPOCH},
|
time::{SystemTime, UNIX_EPOCH},
|
||||||
};
|
};
|
||||||
@@ -27,6 +28,8 @@ use crate::{
|
|||||||
event::Event,
|
event::Event,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use super::error::LibeiEmulationCreationError;
|
||||||
|
|
||||||
pub struct LibeiEmulation {
|
pub struct LibeiEmulation {
|
||||||
handshake: bool,
|
handshake: bool,
|
||||||
context: ei::Context,
|
context: ei::Context,
|
||||||
@@ -77,14 +80,14 @@ async fn get_ei_fd() -> Result<OwnedFd, ashpd::Error> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl LibeiEmulation {
|
impl LibeiEmulation {
|
||||||
pub async fn new() -> Result<Self> {
|
pub async fn new() -> Result<Self, LibeiEmulationCreationError> {
|
||||||
// fd is owned by the message, so we need to dup it
|
// fd is owned by the message, so we need to dup it
|
||||||
let eifd = get_ei_fd().await?;
|
let eifd = get_ei_fd().await?;
|
||||||
let stream = UnixStream::from(eifd);
|
let stream = UnixStream::from(eifd);
|
||||||
// let stream = UnixStream::connect("/run/user/1000/eis-0")?;
|
// let stream = UnixStream::connect("/run/user/1000/eis-0")?;
|
||||||
stream.set_nonblocking(true)?;
|
stream.set_nonblocking(true)?;
|
||||||
let context = ei::Context::new(stream)?;
|
let context = ei::Context::new(stream)?;
|
||||||
context.flush()?;
|
context.flush().map_err(|e| io::Error::new(e.kind(), e))?;
|
||||||
let events = EiEventStream::new(context.clone())?;
|
let events = EiEventStream::new(context.clone())?;
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
handshake: false,
|
handshake: false,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use crate::client::{ClientEvent, ClientHandle};
|
use crate::client::{ClientEvent, ClientHandle};
|
||||||
use crate::emulate::{InputEmulation, error::WlrootsEmulationCreationError};
|
use crate::emulate::{error::WlrootsEmulationCreationError, InputEmulation};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::io;
|
use std::io;
|
||||||
@@ -53,12 +53,15 @@ impl WlrootsEmulation {
|
|||||||
let (globals, queue) = registry_queue_init::<State>(&conn)?;
|
let (globals, queue) = registry_queue_init::<State>(&conn)?;
|
||||||
let qh = queue.handle();
|
let qh = queue.handle();
|
||||||
|
|
||||||
let seat: wl_seat::WlSeat = globals.bind(&qh, 7..=8, ())
|
let seat: wl_seat::WlSeat = globals
|
||||||
|
.bind(&qh, 7..=8, ())
|
||||||
.map_err(|e| WaylandBindError::new(e, "wl_seat 7..=8"))?;
|
.map_err(|e| WaylandBindError::new(e, "wl_seat 7..=8"))?;
|
||||||
|
|
||||||
let vpm: VpManager = globals.bind(&qh, 1..=1, ())
|
let vpm: VpManager = globals
|
||||||
|
.bind(&qh, 1..=1, ())
|
||||||
.map_err(|e| WaylandBindError::new(e, "wlr-virtual-pointer-unstable-v1"))?;
|
.map_err(|e| WaylandBindError::new(e, "wlr-virtual-pointer-unstable-v1"))?;
|
||||||
let vkm: VkManager = globals.bind(&qh, 1..=1, ())
|
let vkm: VkManager = globals
|
||||||
|
.bind(&qh, 1..=1, ())
|
||||||
.map_err(|e| WaylandBindError::new(e, "virtual-keyboard-unstable-v1"))?;
|
.map_err(|e| WaylandBindError::new(e, "virtual-keyboard-unstable-v1"))?;
|
||||||
|
|
||||||
let input_for_client: HashMap<ClientHandle, VirtualInput> = HashMap::new();
|
let input_for_client: HashMap<ClientHandle, VirtualInput> = HashMap::new();
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
use anyhow::{anyhow, Result};
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use x11::{
|
use x11::{
|
||||||
@@ -14,6 +13,8 @@ use crate::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use super::error::X11EmulationCreationError;
|
||||||
|
|
||||||
pub struct X11Emulation {
|
pub struct X11Emulation {
|
||||||
display: *mut xlib::Display,
|
display: *mut xlib::Display,
|
||||||
}
|
}
|
||||||
@@ -21,11 +22,11 @@ pub struct X11Emulation {
|
|||||||
unsafe impl Send for X11Emulation {}
|
unsafe impl Send for X11Emulation {}
|
||||||
|
|
||||||
impl X11Emulation {
|
impl X11Emulation {
|
||||||
pub fn new() -> Result<Self> {
|
pub fn new() -> Result<Self, X11EmulationCreationError> {
|
||||||
let display = unsafe {
|
let display = unsafe {
|
||||||
match xlib::XOpenDisplay(ptr::null()) {
|
match xlib::XOpenDisplay(ptr::null()) {
|
||||||
d if d == ptr::null::<xlib::Display>() as *mut xlib::Display => {
|
d if d == ptr::null::<xlib::Display>() as *mut xlib::Display => {
|
||||||
Err(anyhow!("could not open display"))
|
Err(X11EmulationCreationError::OpenDisplay)
|
||||||
}
|
}
|
||||||
display => Ok(display),
|
display => Ok(display),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,9 @@ fn run_service(config: &Config) -> Result<()> {
|
|||||||
log::info!("Press {:?} to release the mouse", config.release_bind);
|
log::info!("Press {:?} to release the mouse", config.release_bind);
|
||||||
|
|
||||||
let server = Server::new(config);
|
let server = Server::new(config);
|
||||||
server.run(config.capture_backend, config.emulation_backend).await?;
|
server
|
||||||
|
.run(config.capture_backend, config.emulation_backend)
|
||||||
|
.await?;
|
||||||
|
|
||||||
log::debug!("service exiting");
|
log::debug!("service exiting");
|
||||||
anyhow::Ok(())
|
anyhow::Ok(())
|
||||||
|
|||||||
@@ -7,7 +7,12 @@ use tokio::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
client::{ClientEvent, ClientHandle}, config::EmulationBackend, emulate::{self, error::EmulationCreationError, InputEmulation}, event::{Event, KeyboardEvent}, scancode, server::State
|
client::{ClientEvent, ClientHandle},
|
||||||
|
config::EmulationBackend,
|
||||||
|
emulate::{self, error::EmulationCreationError, InputEmulation},
|
||||||
|
event::{Event, KeyboardEvent},
|
||||||
|
scancode,
|
||||||
|
server::State,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{CaptureEvent, Server};
|
use super::{CaptureEvent, Server};
|
||||||
|
|||||||
Reference in New Issue
Block a user