mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-04-04 23:01:28 +03:00
fix macos
This commit is contained in:
@@ -18,6 +18,8 @@ pub enum EmulationCreationError {
|
|||||||
Xdp(#[from] XdpEmulationCreationError),
|
Xdp(#[from] XdpEmulationCreationError),
|
||||||
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
|
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
|
||||||
X11(#[from] X11EmulationCreationError),
|
X11(#[from] X11EmulationCreationError),
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
MacOs(#[from] MacOSEmulationCreationError),
|
||||||
NoAvailableBackend,
|
NoAvailableBackend,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,6 +34,8 @@ impl Display for EmulationCreationError {
|
|||||||
EmulationCreationError::Xdp(e) => format!("desktop portal backend: {e}"),
|
EmulationCreationError::Xdp(e) => format!("desktop portal backend: {e}"),
|
||||||
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
|
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
|
||||||
EmulationCreationError::X11(e) => format!("x11 backend: {e}"),
|
EmulationCreationError::X11(e) => format!("x11 backend: {e}"),
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
EmulationCreationError::MacOs(e) => format!("macos backend: {e}"),
|
||||||
EmulationCreationError::NoAvailableBackend => format!("no backend available"),
|
EmulationCreationError::NoAvailableBackend => format!("no backend available"),
|
||||||
};
|
};
|
||||||
write!(f, "could not create input emulation backend: {reason}")
|
write!(f, "could not create input emulation backend: {reason}")
|
||||||
@@ -137,3 +141,18 @@ impl Display for X11EmulationCreationError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
#[derive(Debug, Error)]
|
||||||
|
pub enum MacOSEmulationCreationError {
|
||||||
|
EventSourceCreation,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
impl Display for MacOSEmulationCreationError {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
MacOSEmulationCreationError::EventSourceCreation => write!(f, "could not create event source"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
use crate::client::{ClientEvent, ClientHandle};
|
use crate::client::{ClientEvent, ClientHandle};
|
||||||
use crate::emulate::InputEmulation;
|
use crate::emulate::InputEmulation;
|
||||||
use crate::event::{Event, KeyboardEvent, PointerEvent};
|
use crate::event::{Event, KeyboardEvent, PointerEvent};
|
||||||
use anyhow::{anyhow, Result};
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use core_graphics::display::{CGDisplayBounds, CGMainDisplayID, CGPoint};
|
use core_graphics::display::{CGDisplayBounds, CGMainDisplayID, CGPoint};
|
||||||
use core_graphics::event::{
|
use core_graphics::event::{
|
||||||
@@ -13,6 +12,8 @@ use std::ops::{Index, IndexMut};
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tokio::task::AbortHandle;
|
use tokio::task::AbortHandle;
|
||||||
|
|
||||||
|
use super::error::MacOSEmulationCreationError;
|
||||||
|
|
||||||
const DEFAULT_REPEAT_DELAY: Duration = Duration::from_millis(500);
|
const DEFAULT_REPEAT_DELAY: Duration = Duration::from_millis(500);
|
||||||
const DEFAULT_REPEAT_INTERVAL: Duration = Duration::from_millis(32);
|
const DEFAULT_REPEAT_INTERVAL: Duration = Duration::from_millis(32);
|
||||||
|
|
||||||
@@ -53,11 +54,9 @@ impl IndexMut<CGMouseButton> for ButtonState {
|
|||||||
unsafe impl Send for MacOSEmulation {}
|
unsafe impl Send for MacOSEmulation {}
|
||||||
|
|
||||||
impl MacOSEmulation {
|
impl MacOSEmulation {
|
||||||
pub fn new() -> Result<Self> {
|
pub fn new() -> Result<Self, MacOSEmulationCreationError> {
|
||||||
let event_source = match CGEventSource::new(CGEventSourceStateID::CombinedSessionState) {
|
let event_source = CGEventSource::new(CGEventSourceStateID::CombinedSessionState)
|
||||||
Ok(e) => e,
|
.map_err(|_| MacOSEmulationCreationError::EventSourceCreation)?;
|
||||||
Err(_) => return Err(anyhow!("event source creation failed!")),
|
|
||||||
};
|
|
||||||
let button_state = ButtonState {
|
let button_state = ButtonState {
|
||||||
left: false,
|
left: false,
|
||||||
right: false,
|
right: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user