mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-04-24 15:23:19 +03:00
Compare commits
5 Commits
drop-dispa
...
split-crat
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f29cd2df43 | ||
|
|
7056ff697e | ||
|
|
ef09cd4806 | ||
|
|
c093c3e0c4 | ||
|
|
dd7f931a10 |
51
Cargo.lock
generated
51
Cargo.lock
generated
@@ -1210,7 +1210,7 @@ dependencies = [
|
|||||||
"wayland-client",
|
"wayland-client",
|
||||||
"wayland-protocols",
|
"wayland-protocols",
|
||||||
"wayland-protocols-wlr",
|
"wayland-protocols-wlr",
|
||||||
"windows 0.57.0",
|
"windows 0.54.0",
|
||||||
"x11",
|
"x11",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -1226,7 +1226,6 @@ dependencies = [
|
|||||||
"input-event",
|
"input-event",
|
||||||
"keycode",
|
"keycode",
|
||||||
"log",
|
"log",
|
||||||
"once_cell",
|
|
||||||
"reis",
|
"reis",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tokio",
|
"tokio",
|
||||||
@@ -1234,7 +1233,7 @@ dependencies = [
|
|||||||
"wayland-protocols",
|
"wayland-protocols",
|
||||||
"wayland-protocols-misc",
|
"wayland-protocols-misc",
|
||||||
"wayland-protocols-wlr",
|
"wayland-protocols-wlr",
|
||||||
"windows 0.57.0",
|
"windows 0.54.0",
|
||||||
"x11",
|
"x11",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -2233,9 +2232,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wayland-protocols"
|
name = "wayland-protocols"
|
||||||
version = "0.32.1"
|
version = "0.31.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "83d0f1056570486e26a3773ec633885124d79ae03827de05ba6c85f79904026c"
|
checksum = "8f81f365b8b4a97f422ac0e8737c438024b5951734506b0e1d775c73030561f4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.6.0",
|
"bitflags 2.6.0",
|
||||||
"wayland-backend",
|
"wayland-backend",
|
||||||
@@ -2245,9 +2244,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wayland-protocols-misc"
|
name = "wayland-protocols-misc"
|
||||||
version = "0.3.1"
|
version = "0.2.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e76311e1866c955afbbc46ae97e57542acda1dc9b0298358263a8550b5247331"
|
checksum = "bfa5933740b200188c9b4c38601b8212e8c154d7de0d2cb171944e137a77de1e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.6.0",
|
"bitflags 2.6.0",
|
||||||
"wayland-backend",
|
"wayland-backend",
|
||||||
@@ -2258,9 +2257,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wayland-protocols-wlr"
|
name = "wayland-protocols-wlr"
|
||||||
version = "0.3.1"
|
version = "0.2.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a7dab47671043d9f5397035975fe1cac639e5bca5cc0b3c32d09f01612e34d24"
|
checksum = "ad1f61b76b6c2d8742e10f9ba5c3737f6530b4c243132c2a2ccc8aa96fe25cd6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.6.0",
|
"bitflags 2.6.0",
|
||||||
"wayland-backend",
|
"wayland-backend",
|
||||||
@@ -2331,11 +2330,11 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows"
|
name = "windows"
|
||||||
version = "0.57.0"
|
version = "0.54.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143"
|
checksum = "9252e5725dbed82865af151df558e754e4a3c2c30818359eb17465f1346a1b49"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-core 0.57.0",
|
"windows-core 0.54.0",
|
||||||
"windows-targets 0.52.5",
|
"windows-targets 0.52.5",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -2350,38 +2349,14 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-core"
|
name = "windows-core"
|
||||||
version = "0.57.0"
|
version = "0.54.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d2ed2439a290666cd67ecce2b0ffaad89c2a56b976b736e6ece670297897832d"
|
checksum = "12661b9c89351d684a50a8a643ce5f608e20243b9fb84687800163429f161d65"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-implement",
|
|
||||||
"windows-interface",
|
|
||||||
"windows-result",
|
"windows-result",
|
||||||
"windows-targets 0.52.5",
|
"windows-targets 0.52.5",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows-implement"
|
|
||||||
version = "0.57.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows-interface"
|
|
||||||
version = "0.57.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-result"
|
name = "windows-result"
|
||||||
version = "0.1.2"
|
version = "0.1.2"
|
||||||
|
|||||||
@@ -18,9 +18,9 @@ strip = true
|
|||||||
lto = "fat"
|
lto = "fat"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
input-event = { path = "input-event", version = "0.1.0" }
|
input-event = { path = "input-event" }
|
||||||
input-emulation = { path = "input-emulation", version = "0.1.0", default-features = false }
|
input-emulation = { path = "input-emulation", default-features = false }
|
||||||
input-capture = { path = "input-capture", version = "0.1.0", default-features = false }
|
input-capture = { path = "input-capture", default-features = false }
|
||||||
|
|
||||||
hickory-resolver = "0.24.1"
|
hickory-resolver = "0.24.1"
|
||||||
toml = "0.8"
|
toml = "0.8"
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ anyhow = "1.0.86"
|
|||||||
futures = "0.3.28"
|
futures = "0.3.28"
|
||||||
futures-core = "0.3.30"
|
futures-core = "0.3.30"
|
||||||
log = "0.4.22"
|
log = "0.4.22"
|
||||||
input-event = { path = "../input-event", version = "0.1.0" }
|
input-event = { path = "../input-event" }
|
||||||
memmap = "0.7"
|
memmap = "0.7"
|
||||||
tempfile = "3.8"
|
tempfile = "3.8"
|
||||||
thiserror = "1.0.61"
|
thiserror = "1.0.61"
|
||||||
@@ -21,8 +21,8 @@ once_cell = "1.19.0"
|
|||||||
|
|
||||||
[target.'cfg(all(unix, not(target_os="macos")))'.dependencies]
|
[target.'cfg(all(unix, not(target_os="macos")))'.dependencies]
|
||||||
wayland-client = { version="0.31.1", optional = true }
|
wayland-client = { version="0.31.1", optional = true }
|
||||||
wayland-protocols = { version="0.32.1", features=["client", "staging", "unstable"], optional = true }
|
wayland-protocols = { version="0.31.0", features=["client", "staging", "unstable"], optional = true }
|
||||||
wayland-protocols-wlr = { version="0.3.1", features=["client"], optional = true }
|
wayland-protocols-wlr = { version="0.2.0", features=["client"], optional = true }
|
||||||
x11 = { version = "2.21.0", features = ["xlib", "xtest"], optional = true }
|
x11 = { version = "2.21.0", features = ["xlib", "xtest"], optional = true }
|
||||||
ashpd = { version = "0.8", default-features = false, features = ["tokio"], optional = true }
|
ashpd = { version = "0.8", default-features = false, features = ["tokio"], optional = true }
|
||||||
reis = { version = "0.2", features = [ "tokio" ], optional = true }
|
reis = { version = "0.2", features = [ "tokio" ], optional = true }
|
||||||
@@ -31,7 +31,7 @@ reis = { version = "0.2", features = [ "tokio" ], optional = true }
|
|||||||
core-graphics = { version = "0.23", features = ["highsierra"] }
|
core-graphics = { version = "0.23", features = ["highsierra"] }
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
windows = { version = "0.57.0", features = [
|
windows = { version = "0.54.0", features = [
|
||||||
"Win32_System_LibraryLoader",
|
"Win32_System_LibraryLoader",
|
||||||
"Win32_System_Threading",
|
"Win32_System_Threading",
|
||||||
"Win32_Foundation",
|
"Win32_Foundation",
|
||||||
|
|||||||
@@ -565,7 +565,7 @@ fn message_thread(ready_tx: mpsc::Sender<()>) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* other messages for window_procs */
|
/* other messages for window_procs */
|
||||||
let _ = TranslateMessage(&msg);
|
TranslateMessage(&msg);
|
||||||
DispatchMessageW(&msg);
|
DispatchMessageW(&msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,16 +11,15 @@ anyhow = "1.0.86"
|
|||||||
async-trait = "0.1.80"
|
async-trait = "0.1.80"
|
||||||
futures = "0.3.28"
|
futures = "0.3.28"
|
||||||
log = "0.4.22"
|
log = "0.4.22"
|
||||||
input-event = { path = "../input-event", version = "0.1.0" }
|
input-event = { path = "../input-event" }
|
||||||
thiserror = "1.0.61"
|
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"
|
|
||||||
|
|
||||||
[target.'cfg(all(unix, not(target_os="macos")))'.dependencies]
|
[target.'cfg(all(unix, not(target_os="macos")))'.dependencies]
|
||||||
wayland-client = { version="0.31.1", optional = true }
|
wayland-client = { version="0.31.1", optional = true }
|
||||||
wayland-protocols = { version="0.32.1", features=["client", "staging", "unstable"], optional = true }
|
wayland-protocols = { version="0.31.0", features=["client", "staging", "unstable"], optional = true }
|
||||||
wayland-protocols-wlr = { version="0.3.1", features=["client"], optional = true }
|
wayland-protocols-wlr = { version="0.2.0", features=["client"], optional = true }
|
||||||
wayland-protocols-misc = { version="0.3.1", features=["client"], optional = true }
|
wayland-protocols-misc = { version="0.2.0", features=["client"], optional = true }
|
||||||
x11 = { version = "2.21.0", features = ["xlib", "xtest"], optional = true }
|
x11 = { version = "2.21.0", features = ["xlib", "xtest"], optional = true }
|
||||||
ashpd = { version = "0.8", default-features = false, features = ["tokio"], optional = true }
|
ashpd = { version = "0.8", default-features = false, features = ["tokio"], optional = true }
|
||||||
reis = { version = "0.2", features = [ "tokio" ], optional = true }
|
reis = { version = "0.2", features = [ "tokio" ], optional = true }
|
||||||
@@ -30,7 +29,7 @@ core-graphics = { version = "0.23", features = ["highsierra"] }
|
|||||||
keycode = "0.4.0"
|
keycode = "0.4.0"
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
windows = { version = "0.57.0", features = [
|
windows = { version = "0.54.0", features = [
|
||||||
"Win32_System_LibraryLoader",
|
"Win32_System_LibraryLoader",
|
||||||
"Win32_System_Threading",
|
"Win32_System_Threading",
|
||||||
"Win32_Foundation",
|
"Win32_Foundation",
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use input_event::Event;
|
use input_event::Event;
|
||||||
|
|
||||||
use crate::error::EmulationError;
|
|
||||||
|
|
||||||
use super::{EmulationHandle, InputEmulation};
|
use super::{EmulationHandle, InputEmulation};
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
@@ -16,13 +14,8 @@ impl DummyEmulation {
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl InputEmulation for DummyEmulation {
|
impl InputEmulation for DummyEmulation {
|
||||||
async fn consume(
|
async fn consume(&mut self, event: Event, client_handle: EmulationHandle) {
|
||||||
&mut self,
|
|
||||||
event: Event,
|
|
||||||
client_handle: EmulationHandle,
|
|
||||||
) -> Result<(), EmulationError> {
|
|
||||||
log::info!("received event: ({client_handle}) {event}");
|
log::info!("received event: ({client_handle}) {event}");
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
async fn create(&mut self, _: EmulationHandle) {}
|
async fn create(&mut self, _: EmulationHandle) {}
|
||||||
async fn destroy(&mut self, _: EmulationHandle) {}
|
async fn destroy(&mut self, _: EmulationHandle) {}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use std::{fmt::Display, io};
|
use std::fmt::Display;
|
||||||
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
||||||
@@ -8,28 +8,6 @@ use wayland_client::{
|
|||||||
ConnectError, DispatchError,
|
ConnectError, DispatchError,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
|
||||||
use reis::tokio::HandshakeError;
|
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
|
||||||
pub enum EmulationError {
|
|
||||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
|
||||||
#[error("libei error flushing events: `{0}`")]
|
|
||||||
Libei(#[from] reis::event::Error),
|
|
||||||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
|
||||||
#[error("wayland error: `{0}`")]
|
|
||||||
Wayland(#[from] wayland_client::backend::WaylandError),
|
|
||||||
#[cfg(all(
|
|
||||||
unix,
|
|
||||||
any(feature = "xdg_desktop_portal", feature = "libei"),
|
|
||||||
not(target_os = "macos")
|
|
||||||
))]
|
|
||||||
#[error("xdg-desktop-portal: `{0}`")]
|
|
||||||
Ashpd(#[from] ashpd::Error),
|
|
||||||
#[error("io error: `{0}`")]
|
|
||||||
Io(#[from] io::Error),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum EmulationCreationError {
|
pub enum EmulationCreationError {
|
||||||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
||||||
@@ -126,7 +104,6 @@ impl Display for WlrootsEmulationCreationError {
|
|||||||
pub enum LibeiEmulationCreationError {
|
pub enum LibeiEmulationCreationError {
|
||||||
Ashpd(#[from] ashpd::Error),
|
Ashpd(#[from] ashpd::Error),
|
||||||
Io(#[from] std::io::Error),
|
Io(#[from] std::io::Error),
|
||||||
Handshake(#[from] HandshakeError),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||||
@@ -135,7 +112,6 @@ impl Display for LibeiEmulationCreationError {
|
|||||||
match self {
|
match self {
|
||||||
LibeiEmulationCreationError::Ashpd(e) => write!(f, "xdg-desktop-portal: {e}"),
|
LibeiEmulationCreationError::Ashpd(e) => write!(f, "xdg-desktop-portal: {e}"),
|
||||||
LibeiEmulationCreationError::Io(e) => write!(f, "io error: {e}"),
|
LibeiEmulationCreationError::Io(e) => write!(f, "io error: {e}"),
|
||||||
LibeiEmulationCreationError::Handshake(e) => write!(f, "error in libei handshake: {e}"),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use error::EmulationError;
|
use std::{fmt::Display, future};
|
||||||
use std::fmt::Display;
|
|
||||||
|
|
||||||
use input_event::Event;
|
use input_event::Event;
|
||||||
|
|
||||||
@@ -71,13 +70,14 @@ impl Display for Backend {
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait InputEmulation: Send {
|
pub trait InputEmulation: Send {
|
||||||
async fn consume(
|
async fn consume(&mut self, event: Event, handle: EmulationHandle);
|
||||||
&mut self,
|
|
||||||
event: Event,
|
|
||||||
handle: EmulationHandle,
|
|
||||||
) -> Result<(), EmulationError>;
|
|
||||||
async fn create(&mut self, handle: EmulationHandle);
|
async fn create(&mut self, handle: EmulationHandle);
|
||||||
async fn destroy(&mut self, handle: EmulationHandle);
|
async fn destroy(&mut self, handle: EmulationHandle);
|
||||||
|
/// this function is waited on continuously and can be used to handle events
|
||||||
|
async fn dispatch(&mut self) -> Result<()> {
|
||||||
|
let _: () = future::pending().await;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create_backend(
|
pub async fn create_backend(
|
||||||
|
|||||||
@@ -1,17 +1,10 @@
|
|||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use futures::StreamExt;
|
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
io,
|
io,
|
||||||
os::{fd::OwnedFd, unix::net::UnixStream},
|
os::{fd::OwnedFd, unix::net::UnixStream},
|
||||||
sync::{
|
|
||||||
atomic::{AtomicU32, Ordering},
|
|
||||||
Arc, RwLock,
|
|
||||||
},
|
|
||||||
time::{SystemTime, UNIX_EPOCH},
|
time::{SystemTime, UNIX_EPOCH},
|
||||||
};
|
};
|
||||||
use tokio::task::JoinHandle;
|
|
||||||
|
|
||||||
use ashpd::{
|
use ashpd::{
|
||||||
desktop::{
|
desktop::{
|
||||||
@@ -21,51 +14,34 @@ use ashpd::{
|
|||||||
WindowIdentifier,
|
WindowIdentifier,
|
||||||
};
|
};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
use futures::StreamExt;
|
||||||
|
|
||||||
use reis::{
|
use reis::{
|
||||||
ei::{
|
ei::{self, button::ButtonState, handshake::ContextType, keyboard::KeyState},
|
||||||
self, button::ButtonState, handshake::ContextType, keyboard::KeyState, Button, Keyboard,
|
tokio::EiEventStream,
|
||||||
Pointer, Scroll,
|
PendingRequestResult,
|
||||||
},
|
|
||||||
event::{DeviceCapability, DeviceEvent, EiEvent, SeatEvent},
|
|
||||||
tokio::{ei_handshake, EiConvertEventStream, EiEventStream},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use input_event::{Event, KeyboardEvent, PointerEvent};
|
use input_event::{Event, KeyboardEvent, PointerEvent};
|
||||||
|
|
||||||
use crate::error::EmulationError;
|
|
||||||
|
|
||||||
use super::{error::LibeiEmulationCreationError, EmulationHandle, InputEmulation};
|
use super::{error::LibeiEmulationCreationError, EmulationHandle, InputEmulation};
|
||||||
|
|
||||||
static INTERFACES: Lazy<HashMap<&'static str, u32>> = Lazy::new(|| {
|
|
||||||
let mut m = HashMap::new();
|
|
||||||
m.insert("ei_connection", 1);
|
|
||||||
m.insert("ei_callback", 1);
|
|
||||||
m.insert("ei_pingpong", 1);
|
|
||||||
m.insert("ei_seat", 1);
|
|
||||||
m.insert("ei_device", 2);
|
|
||||||
m.insert("ei_pointer", 1);
|
|
||||||
m.insert("ei_pointer_absolute", 1);
|
|
||||||
m.insert("ei_scroll", 1);
|
|
||||||
m.insert("ei_button", 1);
|
|
||||||
m.insert("ei_keyboard", 1);
|
|
||||||
m.insert("ei_touchscreen", 1);
|
|
||||||
m
|
|
||||||
});
|
|
||||||
|
|
||||||
#[derive(Clone, Default)]
|
|
||||||
struct Devices {
|
|
||||||
pointer: Arc<RwLock<Option<(ei::Device, ei::Pointer)>>>,
|
|
||||||
scroll: Arc<RwLock<Option<(ei::Device, ei::Scroll)>>>,
|
|
||||||
button: Arc<RwLock<Option<(ei::Device, ei::Button)>>>,
|
|
||||||
keyboard: Arc<RwLock<Option<(ei::Device, ei::Keyboard)>>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct LibeiEmulation {
|
pub struct LibeiEmulation {
|
||||||
|
handshake: bool,
|
||||||
context: ei::Context,
|
context: ei::Context,
|
||||||
devices: Devices,
|
events: EiEventStream,
|
||||||
serial: AtomicU32,
|
pointer: Option<(ei::Device, ei::Pointer)>,
|
||||||
ei_task: JoinHandle<Result<()>>,
|
has_pointer: bool,
|
||||||
|
scroll: Option<(ei::Device, ei::Scroll)>,
|
||||||
|
has_scroll: bool,
|
||||||
|
button: Option<(ei::Device, ei::Button)>,
|
||||||
|
has_button: bool,
|
||||||
|
keyboard: Option<(ei::Device, ei::Keyboard)>,
|
||||||
|
has_keyboard: bool,
|
||||||
|
capabilities: HashMap<String, u64>,
|
||||||
|
capability_mask: u64,
|
||||||
|
sequence: u32,
|
||||||
|
serial: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_ei_fd() -> Result<OwnedFd, ashpd::Error> {
|
async fn get_ei_fd() -> Result<OwnedFd, ashpd::Error> {
|
||||||
@@ -101,48 +77,37 @@ async fn get_ei_fd() -> Result<OwnedFd, ashpd::Error> {
|
|||||||
|
|
||||||
impl LibeiEmulation {
|
impl LibeiEmulation {
|
||||||
pub async fn new() -> Result<Self, LibeiEmulationCreationError> {
|
pub async fn new() -> Result<Self, LibeiEmulationCreationError> {
|
||||||
|
// 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")?;
|
||||||
stream.set_nonblocking(true)?;
|
stream.set_nonblocking(true)?;
|
||||||
let context = ei::Context::new(stream)?;
|
let context = ei::Context::new(stream)?;
|
||||||
context.flush().map_err(|e| io::Error::new(e.kind(), e))?;
|
context.flush().map_err(|e| io::Error::new(e.kind(), e))?;
|
||||||
let mut events = EiEventStream::new(context.clone())?;
|
let events = EiEventStream::new(context.clone())?;
|
||||||
let handshake = ei_handshake(
|
|
||||||
&mut events,
|
|
||||||
"de.feschber.LanMouse",
|
|
||||||
ContextType::Sender,
|
|
||||||
&INTERFACES,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
let events = EiConvertEventStream::new(events, handshake.serial);
|
|
||||||
let devices = Devices::default();
|
|
||||||
let ei_task =
|
|
||||||
tokio::task::spawn_local(ei_event_handler(events, context.clone(), devices.clone()));
|
|
||||||
|
|
||||||
let serial = AtomicU32::new(handshake.serial);
|
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
serial,
|
handshake: false,
|
||||||
context,
|
context,
|
||||||
ei_task,
|
events,
|
||||||
devices,
|
pointer: None,
|
||||||
|
button: None,
|
||||||
|
scroll: None,
|
||||||
|
keyboard: None,
|
||||||
|
has_pointer: false,
|
||||||
|
has_button: false,
|
||||||
|
has_scroll: false,
|
||||||
|
has_keyboard: false,
|
||||||
|
capabilities: HashMap::new(),
|
||||||
|
capability_mask: 0,
|
||||||
|
sequence: 0,
|
||||||
|
serial: 0,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for LibeiEmulation {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
self.ei_task.abort();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl InputEmulation for LibeiEmulation {
|
impl InputEmulation for LibeiEmulation {
|
||||||
async fn consume(
|
async fn consume(&mut self, event: Event, _client_handle: EmulationHandle) {
|
||||||
&mut self,
|
|
||||||
event: Event,
|
|
||||||
_handle: EmulationHandle,
|
|
||||||
) -> Result<(), EmulationError> {
|
|
||||||
let now = SystemTime::now()
|
let now = SystemTime::now()
|
||||||
.duration_since(UNIX_EPOCH)
|
.duration_since(UNIX_EPOCH)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@@ -154,10 +119,12 @@ impl InputEmulation for LibeiEmulation {
|
|||||||
relative_x,
|
relative_x,
|
||||||
relative_y,
|
relative_y,
|
||||||
} => {
|
} => {
|
||||||
let pointer_device = self.devices.pointer.read().unwrap();
|
if !self.has_pointer {
|
||||||
if let Some((d, p)) = pointer_device.as_ref() {
|
return;
|
||||||
|
}
|
||||||
|
if let Some((d, p)) = self.pointer.as_mut() {
|
||||||
p.motion_relative(relative_x as f32, relative_y as f32);
|
p.motion_relative(relative_x as f32, relative_y as f32);
|
||||||
d.frame(self.serial.load(Ordering::SeqCst), now);
|
d.frame(self.serial, now);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PointerEvent::Button {
|
PointerEvent::Button {
|
||||||
@@ -165,8 +132,10 @@ impl InputEmulation for LibeiEmulation {
|
|||||||
button,
|
button,
|
||||||
state,
|
state,
|
||||||
} => {
|
} => {
|
||||||
let button_device = self.devices.button.read().unwrap();
|
if !self.has_button {
|
||||||
if let Some((d, b)) = button_device.as_ref() {
|
return;
|
||||||
|
}
|
||||||
|
if let Some((d, b)) = self.button.as_mut() {
|
||||||
b.button(
|
b.button(
|
||||||
button,
|
button,
|
||||||
match state {
|
match state {
|
||||||
@@ -174,7 +143,7 @@ impl InputEmulation for LibeiEmulation {
|
|||||||
_ => ButtonState::Press,
|
_ => ButtonState::Press,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
d.frame(self.serial.load(Ordering::SeqCst), now);
|
d.frame(self.serial, now);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PointerEvent::Axis {
|
PointerEvent::Axis {
|
||||||
@@ -182,23 +151,27 @@ impl InputEmulation for LibeiEmulation {
|
|||||||
axis,
|
axis,
|
||||||
value,
|
value,
|
||||||
} => {
|
} => {
|
||||||
let scroll_device = self.devices.scroll.read().unwrap();
|
if !self.has_scroll {
|
||||||
if let Some((d, s)) = scroll_device.as_ref() {
|
return;
|
||||||
|
}
|
||||||
|
if let Some((d, s)) = self.scroll.as_mut() {
|
||||||
match axis {
|
match axis {
|
||||||
0 => s.scroll(0., value as f32),
|
0 => s.scroll(0., value as f32),
|
||||||
_ => s.scroll(value as f32, 0.),
|
_ => s.scroll(value as f32, 0.),
|
||||||
}
|
}
|
||||||
d.frame(self.serial.load(Ordering::SeqCst), now);
|
d.frame(self.serial, now);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PointerEvent::AxisDiscrete120 { axis, value } => {
|
PointerEvent::AxisDiscrete120 { axis, value } => {
|
||||||
let scroll_device = self.devices.scroll.read().unwrap();
|
if !self.has_scroll {
|
||||||
if let Some((d, s)) = scroll_device.as_ref() {
|
return;
|
||||||
|
}
|
||||||
|
if let Some((d, s)) = self.scroll.as_mut() {
|
||||||
match axis {
|
match axis {
|
||||||
0 => s.scroll_discrete(0, value),
|
0 => s.scroll_discrete(0, value),
|
||||||
_ => s.scroll_discrete(value, 0),
|
_ => s.scroll_discrete(value, 0),
|
||||||
}
|
}
|
||||||
d.frame(self.serial.load(Ordering::SeqCst), now);
|
d.frame(self.serial, now);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PointerEvent::Frame {} => {}
|
PointerEvent::Frame {} => {}
|
||||||
@@ -209,8 +182,10 @@ impl InputEmulation for LibeiEmulation {
|
|||||||
key,
|
key,
|
||||||
state,
|
state,
|
||||||
} => {
|
} => {
|
||||||
let keyboard_device = self.devices.keyboard.read().unwrap();
|
if !self.has_keyboard {
|
||||||
if let Some((d, k)) = keyboard_device.as_ref() {
|
return;
|
||||||
|
}
|
||||||
|
if let Some((d, k)) = &mut self.keyboard {
|
||||||
k.key(
|
k.key(
|
||||||
key,
|
key,
|
||||||
match state {
|
match state {
|
||||||
@@ -218,119 +193,205 @@ impl InputEmulation for LibeiEmulation {
|
|||||||
_ => KeyState::Press,
|
_ => KeyState::Press,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
d.frame(self.serial.load(Ordering::SeqCst), now);
|
d.frame(self.serial, now);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
KeyboardEvent::Modifiers { .. } => {}
|
KeyboardEvent::Modifiers { .. } => {}
|
||||||
},
|
},
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
self.context
|
self.context.flush().unwrap();
|
||||||
.flush()
|
}
|
||||||
.map_err(|e| io::Error::new(e.kind(), e))?;
|
|
||||||
|
async fn dispatch(&mut self) -> Result<()> {
|
||||||
|
let event = match self.events.next().await {
|
||||||
|
Some(e) => e?,
|
||||||
|
None => return Err(anyhow!("libei connection lost")),
|
||||||
|
};
|
||||||
|
let event = match event {
|
||||||
|
PendingRequestResult::Request(result) => result,
|
||||||
|
PendingRequestResult::ParseError(e) => {
|
||||||
|
return Err(anyhow!("libei protocol violation: {e}"))
|
||||||
|
}
|
||||||
|
PendingRequestResult::InvalidObject(e) => return Err(anyhow!("invalid object {e}")),
|
||||||
|
};
|
||||||
|
match event {
|
||||||
|
ei::Event::Handshake(handshake, request) => match request {
|
||||||
|
ei::handshake::Event::HandshakeVersion { version } => {
|
||||||
|
if self.handshake {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
log::info!("libei version {}", version);
|
||||||
|
// sender means we are sending events _to_ the eis server
|
||||||
|
handshake.handshake_version(version); // FIXME
|
||||||
|
handshake.context_type(ContextType::Sender);
|
||||||
|
handshake.name("ei-demo-client");
|
||||||
|
handshake.interface_version("ei_connection", 1);
|
||||||
|
handshake.interface_version("ei_callback", 1);
|
||||||
|
handshake.interface_version("ei_pingpong", 1);
|
||||||
|
handshake.interface_version("ei_seat", 1);
|
||||||
|
handshake.interface_version("ei_device", 2);
|
||||||
|
handshake.interface_version("ei_pointer", 1);
|
||||||
|
handshake.interface_version("ei_pointer_absolute", 1);
|
||||||
|
handshake.interface_version("ei_scroll", 1);
|
||||||
|
handshake.interface_version("ei_button", 1);
|
||||||
|
handshake.interface_version("ei_keyboard", 1);
|
||||||
|
handshake.interface_version("ei_touchscreen", 1);
|
||||||
|
handshake.finish();
|
||||||
|
self.handshake = true;
|
||||||
|
}
|
||||||
|
ei::handshake::Event::InterfaceVersion { name, version } => {
|
||||||
|
log::debug!("handshake: Interface {name} @ {version}");
|
||||||
|
}
|
||||||
|
ei::handshake::Event::Connection { serial, connection } => {
|
||||||
|
connection.sync(1);
|
||||||
|
self.serial = serial;
|
||||||
|
}
|
||||||
|
_ => unreachable!(),
|
||||||
|
},
|
||||||
|
ei::Event::Connection(_connection, request) => match request {
|
||||||
|
ei::connection::Event::Seat { seat } => {
|
||||||
|
log::debug!("connected to seat: {seat:?}");
|
||||||
|
}
|
||||||
|
ei::connection::Event::Ping { ping } => {
|
||||||
|
ping.done(0);
|
||||||
|
}
|
||||||
|
ei::connection::Event::Disconnected {
|
||||||
|
last_serial: _,
|
||||||
|
reason,
|
||||||
|
explanation,
|
||||||
|
} => {
|
||||||
|
log::debug!("ei - disconnected: reason: {reason:?}: {explanation}")
|
||||||
|
}
|
||||||
|
ei::connection::Event::InvalidObject {
|
||||||
|
last_serial,
|
||||||
|
invalid_id,
|
||||||
|
} => {
|
||||||
|
return Err(anyhow!(
|
||||||
|
"invalid object: id: {invalid_id}, serial: {last_serial}"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
_ => unreachable!(),
|
||||||
|
},
|
||||||
|
ei::Event::Device(device, request) => match request {
|
||||||
|
ei::device::Event::Destroyed { serial } => {
|
||||||
|
log::debug!("device destroyed: {device:?} - serial: {serial}")
|
||||||
|
}
|
||||||
|
ei::device::Event::Name { name } => {
|
||||||
|
log::debug!("device name: {name}")
|
||||||
|
}
|
||||||
|
ei::device::Event::DeviceType { device_type } => {
|
||||||
|
log::debug!("device type: {device_type:?}")
|
||||||
|
}
|
||||||
|
ei::device::Event::Dimensions { width, height } => {
|
||||||
|
log::debug!("device dimensions: {width}x{height}")
|
||||||
|
}
|
||||||
|
ei::device::Event::Region {
|
||||||
|
offset_x,
|
||||||
|
offset_y,
|
||||||
|
width,
|
||||||
|
hight,
|
||||||
|
scale,
|
||||||
|
} => log::debug!(
|
||||||
|
"device region: {width}x{hight} @ ({offset_x},{offset_y}), scale: {scale}"
|
||||||
|
),
|
||||||
|
ei::device::Event::Interface { object } => {
|
||||||
|
log::debug!("device interface: {object:?}");
|
||||||
|
if object.interface().eq("ei_pointer") {
|
||||||
|
log::debug!("GOT POINTER DEVICE");
|
||||||
|
self.pointer.replace((device, object.downcast().unwrap()));
|
||||||
|
} else if object.interface().eq("ei_button") {
|
||||||
|
log::debug!("GOT BUTTON DEVICE");
|
||||||
|
self.button.replace((device, object.downcast().unwrap()));
|
||||||
|
} else if object.interface().eq("ei_scroll") {
|
||||||
|
log::debug!("GOT SCROLL DEVICE");
|
||||||
|
self.scroll.replace((device, object.downcast().unwrap()));
|
||||||
|
} else if object.interface().eq("ei_keyboard") {
|
||||||
|
log::debug!("GOT KEYBOARD DEVICE");
|
||||||
|
self.keyboard.replace((device, object.downcast().unwrap()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ei::device::Event::Done => {
|
||||||
|
log::debug!("device: done {device:?}");
|
||||||
|
}
|
||||||
|
ei::device::Event::Resumed { serial } => {
|
||||||
|
self.serial = serial;
|
||||||
|
device.start_emulating(serial, self.sequence);
|
||||||
|
self.sequence += 1;
|
||||||
|
log::debug!("resumed: {device:?}");
|
||||||
|
if let Some((d, _)) = &mut self.pointer {
|
||||||
|
if d == &device {
|
||||||
|
log::debug!("pointer resumed {serial}");
|
||||||
|
self.has_pointer = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some((d, _)) = &mut self.button {
|
||||||
|
if d == &device {
|
||||||
|
log::debug!("button resumed {serial}");
|
||||||
|
self.has_button = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some((d, _)) = &mut self.scroll {
|
||||||
|
if d == &device {
|
||||||
|
log::debug!("scroll resumed {serial}");
|
||||||
|
self.has_scroll = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some((d, _)) = &mut self.keyboard {
|
||||||
|
if d == &device {
|
||||||
|
log::debug!("keyboard resumed {serial}");
|
||||||
|
self.has_keyboard = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ei::device::Event::Paused { serial } => {
|
||||||
|
self.has_pointer = false;
|
||||||
|
self.has_button = false;
|
||||||
|
self.serial = serial;
|
||||||
|
}
|
||||||
|
ei::device::Event::StartEmulating { serial, sequence } => {
|
||||||
|
log::debug!("start emulating {serial}, {sequence}")
|
||||||
|
}
|
||||||
|
ei::device::Event::StopEmulating { serial } => {
|
||||||
|
log::debug!("stop emulating {serial}")
|
||||||
|
}
|
||||||
|
ei::device::Event::Frame { serial, timestamp } => {
|
||||||
|
log::debug!("frame: {serial}, {timestamp}");
|
||||||
|
}
|
||||||
|
ei::device::Event::RegionMappingId { mapping_id } => {
|
||||||
|
log::debug!("RegionMappingId {mapping_id}")
|
||||||
|
}
|
||||||
|
e => log::debug!("invalid event: {e:?}"),
|
||||||
|
},
|
||||||
|
ei::Event::Seat(seat, request) => match request {
|
||||||
|
ei::seat::Event::Destroyed { serial } => {
|
||||||
|
self.serial = serial;
|
||||||
|
log::debug!("seat destroyed: {seat:?}");
|
||||||
|
}
|
||||||
|
ei::seat::Event::Name { name } => {
|
||||||
|
log::debug!("seat name: {name}");
|
||||||
|
}
|
||||||
|
ei::seat::Event::Capability { mask, interface } => {
|
||||||
|
log::debug!("seat capabilities: {mask}, interface: {interface:?}");
|
||||||
|
self.capabilities.insert(interface, mask);
|
||||||
|
self.capability_mask |= mask;
|
||||||
|
}
|
||||||
|
ei::seat::Event::Done => {
|
||||||
|
log::debug!("seat done");
|
||||||
|
log::debug!("binding capabilities: {}", self.capability_mask);
|
||||||
|
seat.bind(self.capability_mask);
|
||||||
|
}
|
||||||
|
ei::seat::Event::Device { device } => {
|
||||||
|
log::debug!("seat: new device - {device:?}");
|
||||||
|
}
|
||||||
|
_ => todo!(),
|
||||||
|
},
|
||||||
|
e => log::debug!("unhandled event: {e:?}"),
|
||||||
|
}
|
||||||
|
self.context.flush()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(&mut self, _: EmulationHandle) {}
|
async fn create(&mut self, _: EmulationHandle) {}
|
||||||
async fn destroy(&mut self, _: EmulationHandle) {}
|
async fn destroy(&mut self, _: EmulationHandle) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn ei_event_handler(
|
|
||||||
mut events: EiConvertEventStream,
|
|
||||||
context: ei::Context,
|
|
||||||
devices: Devices,
|
|
||||||
) -> Result<()> {
|
|
||||||
loop {
|
|
||||||
let event = events
|
|
||||||
.next()
|
|
||||||
.await
|
|
||||||
.ok_or(anyhow!("ei stream closed"))?
|
|
||||||
.map_err(|e| anyhow!("libei error: {e:?}"))?;
|
|
||||||
const CAPABILITIES: &[DeviceCapability] = &[
|
|
||||||
DeviceCapability::Pointer,
|
|
||||||
DeviceCapability::PointerAbsolute,
|
|
||||||
DeviceCapability::Keyboard,
|
|
||||||
DeviceCapability::Touch,
|
|
||||||
DeviceCapability::Scroll,
|
|
||||||
DeviceCapability::Button,
|
|
||||||
];
|
|
||||||
log::debug!("{event:?}");
|
|
||||||
match event {
|
|
||||||
EiEvent::Disconnected(e) => {
|
|
||||||
log::debug!("ei disconnected: {e:?}");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
EiEvent::SeatAdded(e) => {
|
|
||||||
e.seat().bind_capabilities(CAPABILITIES);
|
|
||||||
}
|
|
||||||
EiEvent::SeatRemoved(e) => {
|
|
||||||
log::debug!("seat removed: {:?}", e.seat());
|
|
||||||
}
|
|
||||||
EiEvent::DeviceAdded(e) => {
|
|
||||||
let device_type = e.device().device_type();
|
|
||||||
log::debug!("device added: {device_type:?}");
|
|
||||||
e.device().device();
|
|
||||||
let device = e.device();
|
|
||||||
if let Some(pointer) = e.device().interface::<Pointer>() {
|
|
||||||
devices
|
|
||||||
.pointer
|
|
||||||
.write()
|
|
||||||
.unwrap()
|
|
||||||
.replace((device.device().clone(), pointer));
|
|
||||||
}
|
|
||||||
if let Some(keyboard) = e.device().interface::<Keyboard>() {
|
|
||||||
devices
|
|
||||||
.keyboard
|
|
||||||
.write()
|
|
||||||
.unwrap()
|
|
||||||
.replace((device.device().clone(), keyboard));
|
|
||||||
}
|
|
||||||
if let Some(scroll) = e.device().interface::<Scroll>() {
|
|
||||||
devices
|
|
||||||
.scroll
|
|
||||||
.write()
|
|
||||||
.unwrap()
|
|
||||||
.replace((device.device().clone(), scroll));
|
|
||||||
}
|
|
||||||
if let Some(button) = e.device().interface::<Button>() {
|
|
||||||
devices
|
|
||||||
.button
|
|
||||||
.write()
|
|
||||||
.unwrap()
|
|
||||||
.replace((device.device().clone(), button));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
EiEvent::DeviceRemoved(e) => {
|
|
||||||
log::debug!("device removed: {:?}", e.device().device_type());
|
|
||||||
}
|
|
||||||
EiEvent::DevicePaused(e) => {
|
|
||||||
log::debug!("device paused: {:?}", e.device().device_type());
|
|
||||||
}
|
|
||||||
EiEvent::DeviceResumed(e) => {
|
|
||||||
log::debug!("device resumed: {:?}", e.device().device_type());
|
|
||||||
e.device().device().start_emulating(0, 0);
|
|
||||||
}
|
|
||||||
EiEvent::KeyboardModifiers(e) => {
|
|
||||||
log::debug!("modifiers: {e:?}");
|
|
||||||
}
|
|
||||||
// only for receiver context
|
|
||||||
// EiEvent::Frame(_) => { },
|
|
||||||
// EiEvent::DeviceStartEmulating(_) => { },
|
|
||||||
// EiEvent::DeviceStopEmulating(_) => { },
|
|
||||||
// EiEvent::PointerMotion(_) => { },
|
|
||||||
// EiEvent::PointerMotionAbsolute(_) => { },
|
|
||||||
// EiEvent::Button(_) => { },
|
|
||||||
// EiEvent::ScrollDelta(_) => { },
|
|
||||||
// EiEvent::ScrollStop(_) => { },
|
|
||||||
// EiEvent::ScrollCancel(_) => { },
|
|
||||||
// EiEvent::ScrollDiscrete(_) => { },
|
|
||||||
// EiEvent::KeyboardKey(_) => { },
|
|
||||||
// EiEvent::TouchDown(_) => { },
|
|
||||||
// EiEvent::TouchUp(_) => { },
|
|
||||||
// EiEvent::TouchMotion(_) => { },
|
|
||||||
_ => unreachable!("unexpected ei event"),
|
|
||||||
}
|
|
||||||
context.flush()?;
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use super::{error::EmulationError, EmulationHandle, InputEmulation};
|
use super::{EmulationHandle, InputEmulation};
|
||||||
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::{
|
||||||
@@ -107,11 +107,7 @@ fn key_event(event_source: CGEventSource, key: u16, state: u8) {
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl InputEmulation for MacOSEmulation {
|
impl InputEmulation for MacOSEmulation {
|
||||||
async fn consume(
|
async fn consume(&mut self, event: Event, _handle: EmulationHandle) {
|
||||||
&mut self,
|
|
||||||
event: Event,
|
|
||||||
_handle: EmulationHandle,
|
|
||||||
) -> Result<(), EmulationError> {
|
|
||||||
match event {
|
match event {
|
||||||
Event::Pointer(pointer_event) => match pointer_event {
|
Event::Pointer(pointer_event) => match pointer_event {
|
||||||
PointerEvent::Motion {
|
PointerEvent::Motion {
|
||||||
@@ -133,7 +129,7 @@ impl InputEmulation for MacOSEmulation {
|
|||||||
Some(l) => l,
|
Some(l) => l,
|
||||||
None => {
|
None => {
|
||||||
log::warn!("could not get mouse location!");
|
log::warn!("could not get mouse location!");
|
||||||
return Ok(());
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -157,7 +153,7 @@ impl InputEmulation for MacOSEmulation {
|
|||||||
Ok(e) => e,
|
Ok(e) => e,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
log::warn!("mouse event creation failed!");
|
log::warn!("mouse event creation failed!");
|
||||||
return Ok(());
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
event.set_integer_value_field(
|
event.set_integer_value_field(
|
||||||
@@ -196,7 +192,7 @@ impl InputEmulation for MacOSEmulation {
|
|||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
log::warn!("invalid button event: {button},{state}");
|
log::warn!("invalid button event: {button},{state}");
|
||||||
return Ok(());
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// store button state
|
// store button state
|
||||||
@@ -212,7 +208,7 @@ impl InputEmulation for MacOSEmulation {
|
|||||||
Ok(e) => e,
|
Ok(e) => e,
|
||||||
Err(()) => {
|
Err(()) => {
|
||||||
log::warn!("mouse event creation failed!");
|
log::warn!("mouse event creation failed!");
|
||||||
return Ok(());
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
event.post(CGEventTapLocation::HID);
|
event.post(CGEventTapLocation::HID);
|
||||||
@@ -228,7 +224,7 @@ impl InputEmulation for MacOSEmulation {
|
|||||||
1 => (2, 0, value, 0), // 1 = horizontal => 2 scroll wheel devices (y, x) -> (0, x)
|
1 => (2, 0, value, 0), // 1 = horizontal => 2 scroll wheel devices (y, x) -> (0, x)
|
||||||
_ => {
|
_ => {
|
||||||
log::warn!("invalid scroll event: {axis}, {value}");
|
log::warn!("invalid scroll event: {axis}, {value}");
|
||||||
return Ok(());
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let event = match CGEvent::new_scroll_event(
|
let event = match CGEvent::new_scroll_event(
|
||||||
@@ -242,7 +238,7 @@ impl InputEmulation for MacOSEmulation {
|
|||||||
Ok(e) => e,
|
Ok(e) => e,
|
||||||
Err(()) => {
|
Err(()) => {
|
||||||
log::warn!("scroll event creation failed!");
|
log::warn!("scroll event creation failed!");
|
||||||
return Ok(());
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
event.post(CGEventTapLocation::HID);
|
event.post(CGEventTapLocation::HID);
|
||||||
@@ -253,7 +249,7 @@ impl InputEmulation for MacOSEmulation {
|
|||||||
1 => (2, 0, value, 0), // 1 = horizontal => 2 scroll wheel devices (y, x) -> (0, x)
|
1 => (2, 0, value, 0), // 1 = horizontal => 2 scroll wheel devices (y, x) -> (0, x)
|
||||||
_ => {
|
_ => {
|
||||||
log::warn!("invalid scroll event: {axis}, {value}");
|
log::warn!("invalid scroll event: {axis}, {value}");
|
||||||
return Ok(());
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let event = match CGEvent::new_scroll_event(
|
let event = match CGEvent::new_scroll_event(
|
||||||
@@ -267,7 +263,7 @@ impl InputEmulation for MacOSEmulation {
|
|||||||
Ok(e) => e,
|
Ok(e) => e,
|
||||||
Err(()) => {
|
Err(()) => {
|
||||||
log::warn!("scroll event creation failed!");
|
log::warn!("scroll event creation failed!");
|
||||||
return Ok(());
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
event.post(CGEventTapLocation::HID);
|
event.post(CGEventTapLocation::HID);
|
||||||
@@ -284,7 +280,7 @@ impl InputEmulation for MacOSEmulation {
|
|||||||
Ok(k) => k.mac as CGKeyCode,
|
Ok(k) => k.mac as CGKeyCode,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
log::warn!("unable to map key event");
|
log::warn!("unable to map key event");
|
||||||
return Ok(());
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
match state {
|
match state {
|
||||||
@@ -298,8 +294,6 @@ impl InputEmulation for MacOSEmulation {
|
|||||||
},
|
},
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
// FIXME
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(&mut self, _handle: EmulationHandle) {}
|
async fn create(&mut self, _handle: EmulationHandle) {}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use super::error::{EmulationError, WindowsEmulationCreationError};
|
use super::error::WindowsEmulationCreationError;
|
||||||
use input_event::{
|
use input_event::{
|
||||||
scancode, Event, KeyboardEvent, PointerEvent, BTN_BACK, BTN_FORWARD, BTN_LEFT, BTN_MIDDLE,
|
scancode, Event, KeyboardEvent, PointerEvent, BTN_BACK, BTN_FORWARD, BTN_LEFT, BTN_MIDDLE,
|
||||||
BTN_RIGHT,
|
BTN_RIGHT,
|
||||||
@@ -36,7 +36,7 @@ impl WindowsEmulation {
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl InputEmulation for WindowsEmulation {
|
impl InputEmulation for WindowsEmulation {
|
||||||
async fn consume(&mut self, event: Event, _: EmulationHandle) -> Result<(), EmulationError> {
|
async fn consume(&mut self, event: Event, _: EmulationHandle) {
|
||||||
match event {
|
match event {
|
||||||
Event::Pointer(pointer_event) => match pointer_event {
|
Event::Pointer(pointer_event) => match pointer_event {
|
||||||
PointerEvent::Motion {
|
PointerEvent::Motion {
|
||||||
@@ -77,8 +77,6 @@ impl InputEmulation for WindowsEmulation {
|
|||||||
},
|
},
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
// FIXME
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(&mut self, _handle: EmulationHandle) {}
|
async fn create(&mut self, _handle: EmulationHandle) {}
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
use crate::error::EmulationError;
|
|
||||||
|
|
||||||
use super::{error::WlrootsEmulationCreationError, InputEmulation};
|
use super::{error::WlrootsEmulationCreationError, InputEmulation};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
@@ -117,40 +115,38 @@ impl State {
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl InputEmulation for WlrootsEmulation {
|
impl InputEmulation for WlrootsEmulation {
|
||||||
async fn consume(
|
async fn consume(&mut self, event: Event, handle: EmulationHandle) {
|
||||||
&mut self,
|
|
||||||
event: Event,
|
|
||||||
handle: EmulationHandle,
|
|
||||||
) -> Result<(), EmulationError> {
|
|
||||||
if let Some(virtual_input) = self.state.input_for_client.get(&handle) {
|
if let Some(virtual_input) = self.state.input_for_client.get(&handle) {
|
||||||
if self.last_flush_failed {
|
if self.last_flush_failed {
|
||||||
match self.queue.flush() {
|
if let Err(WaylandError::Io(e)) = self.queue.flush() {
|
||||||
Err(WaylandError::Io(e)) if e.kind() == io::ErrorKind::WouldBlock => {
|
if e.kind() == io::ErrorKind::WouldBlock {
|
||||||
/*
|
/*
|
||||||
* outgoing buffer is full - sending more events
|
* outgoing buffer is full - sending more events
|
||||||
* will overwhelm the output buffer and leave the
|
* will overwhelm the output buffer and leave the
|
||||||
* wayland connection in a broken state
|
* wayland connection in a broken state
|
||||||
*/
|
*/
|
||||||
log::warn!("can't keep up, discarding event: ({handle}) - {event:?}");
|
log::warn!("can't keep up, discarding event: ({handle}) - {event:?}");
|
||||||
return Ok(());
|
return;
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
virtual_input
|
virtual_input.consume_event(event).unwrap();
|
||||||
.consume_event(event)
|
|
||||||
.unwrap_or_else(|_| panic!("failed to convert event: {event:?}"));
|
|
||||||
match self.queue.flush() {
|
match self.queue.flush() {
|
||||||
Err(WaylandError::Io(e)) if e.kind() == io::ErrorKind::WouldBlock => {
|
Err(WaylandError::Io(e)) if e.kind() == io::ErrorKind::WouldBlock => {
|
||||||
self.last_flush_failed = true;
|
self.last_flush_failed = true;
|
||||||
log::warn!("can't keep up, discarding event: ({handle}) - {event:?}");
|
log::warn!("can't keep up, retrying ...");
|
||||||
|
}
|
||||||
|
Err(WaylandError::Io(e)) => {
|
||||||
|
log::error!("{e}")
|
||||||
|
}
|
||||||
|
Err(WaylandError::Protocol(e)) => {
|
||||||
|
panic!("wayland protocol violation: {e}")
|
||||||
|
}
|
||||||
|
Ok(()) => {
|
||||||
|
self.last_flush_failed = false;
|
||||||
}
|
}
|
||||||
Err(WaylandError::Protocol(e)) => panic!("wayland protocol violation: {e}"),
|
|
||||||
Ok(()) => self.last_flush_failed = false,
|
|
||||||
Err(e) => Err(e)?,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(&mut self, handle: EmulationHandle) {
|
async fn create(&mut self, handle: EmulationHandle) {
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ use input_event::{
|
|||||||
Event, KeyboardEvent, PointerEvent, BTN_BACK, BTN_FORWARD, BTN_LEFT, BTN_MIDDLE, BTN_RIGHT,
|
Event, KeyboardEvent, PointerEvent, BTN_BACK, BTN_FORWARD, BTN_LEFT, BTN_MIDDLE, BTN_RIGHT,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::error::EmulationError;
|
|
||||||
|
|
||||||
use super::{error::X11EmulationCreationError, EmulationHandle, InputEmulation};
|
use super::{error::X11EmulationCreationError, EmulationHandle, InputEmulation};
|
||||||
|
|
||||||
pub struct X11Emulation {
|
pub struct X11Emulation {
|
||||||
@@ -100,7 +98,7 @@ impl Drop for X11Emulation {
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl InputEmulation for X11Emulation {
|
impl InputEmulation for X11Emulation {
|
||||||
async fn consume(&mut self, event: Event, _: EmulationHandle) -> Result<(), EmulationError> {
|
async fn consume(&mut self, event: Event, _: EmulationHandle) {
|
||||||
match event {
|
match event {
|
||||||
Event::Pointer(pointer_event) => match pointer_event {
|
Event::Pointer(pointer_event) => match pointer_event {
|
||||||
PointerEvent::Motion {
|
PointerEvent::Motion {
|
||||||
@@ -141,8 +139,6 @@ impl InputEmulation for X11Emulation {
|
|||||||
unsafe {
|
unsafe {
|
||||||
xlib::XFlush(self.display);
|
xlib::XFlush(self.display);
|
||||||
}
|
}
|
||||||
// FIXME
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(&mut self, _: EmulationHandle) {
|
async fn create(&mut self, _: EmulationHandle) {
|
||||||
|
|||||||
@@ -4,24 +4,20 @@ use ashpd::{
|
|||||||
remote_desktop::{Axis, DeviceType, KeyState, RemoteDesktop},
|
remote_desktop::{Axis, DeviceType, KeyState, RemoteDesktop},
|
||||||
ResponseError, Session,
|
ResponseError, Session,
|
||||||
},
|
},
|
||||||
zbus::AsyncDrop,
|
|
||||||
WindowIdentifier,
|
WindowIdentifier,
|
||||||
};
|
};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
|
||||||
use futures::FutureExt;
|
|
||||||
use input_event::{
|
use input_event::{
|
||||||
Event::{Keyboard, Pointer},
|
Event::{Keyboard, Pointer},
|
||||||
KeyboardEvent, PointerEvent,
|
KeyboardEvent, PointerEvent,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::error::EmulationError;
|
|
||||||
|
|
||||||
use super::{error::XdpEmulationCreationError, EmulationHandle, InputEmulation};
|
use super::{error::XdpEmulationCreationError, EmulationHandle, InputEmulation};
|
||||||
|
|
||||||
pub struct DesktopPortalEmulation<'a> {
|
pub struct DesktopPortalEmulation<'a> {
|
||||||
proxy: RemoteDesktop<'a>,
|
proxy: RemoteDesktop<'a>,
|
||||||
session: Session<'a>,
|
session: Option<Session<'a>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> DesktopPortalEmulation<'a> {
|
impl<'a> DesktopPortalEmulation<'a> {
|
||||||
@@ -55,7 +51,7 @@ impl<'a> DesktopPortalEmulation<'a> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
log::debug!("started session");
|
log::debug!("started session");
|
||||||
let session = session;
|
let session = Some(session);
|
||||||
|
|
||||||
Ok(Self { proxy, session })
|
Ok(Self { proxy, session })
|
||||||
}
|
}
|
||||||
@@ -63,11 +59,7 @@ impl<'a> DesktopPortalEmulation<'a> {
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl<'a> InputEmulation for DesktopPortalEmulation<'a> {
|
impl<'a> InputEmulation for DesktopPortalEmulation<'a> {
|
||||||
async fn consume(
|
async fn consume(&mut self, event: input_event::Event, _client: EmulationHandle) {
|
||||||
&mut self,
|
|
||||||
event: input_event::Event,
|
|
||||||
_client: EmulationHandle,
|
|
||||||
) -> Result<(), EmulationError> {
|
|
||||||
match event {
|
match event {
|
||||||
Pointer(p) => match p {
|
Pointer(p) => match p {
|
||||||
PointerEvent::Motion {
|
PointerEvent::Motion {
|
||||||
@@ -75,9 +67,17 @@ impl<'a> InputEmulation for DesktopPortalEmulation<'a> {
|
|||||||
relative_x,
|
relative_x,
|
||||||
relative_y,
|
relative_y,
|
||||||
} => {
|
} => {
|
||||||
self.proxy
|
if let Err(e) = self
|
||||||
.notify_pointer_motion(&self.session, relative_x, relative_y)
|
.proxy
|
||||||
.await?;
|
.notify_pointer_motion(
|
||||||
|
self.session.as_ref().expect("no session"),
|
||||||
|
relative_x,
|
||||||
|
relative_y,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
log::warn!("{e}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
PointerEvent::Button {
|
PointerEvent::Button {
|
||||||
time: _,
|
time: _,
|
||||||
@@ -88,18 +88,34 @@ impl<'a> InputEmulation for DesktopPortalEmulation<'a> {
|
|||||||
0 => KeyState::Released,
|
0 => KeyState::Released,
|
||||||
_ => KeyState::Pressed,
|
_ => KeyState::Pressed,
|
||||||
};
|
};
|
||||||
self.proxy
|
if let Err(e) = self
|
||||||
.notify_pointer_button(&self.session, button as i32, state)
|
.proxy
|
||||||
.await?;
|
.notify_pointer_button(
|
||||||
|
self.session.as_ref().expect("no session"),
|
||||||
|
button as i32,
|
||||||
|
state,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
log::warn!("{e}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
PointerEvent::AxisDiscrete120 { axis, value } => {
|
PointerEvent::AxisDiscrete120 { axis, value } => {
|
||||||
let axis = match axis {
|
let axis = match axis {
|
||||||
0 => Axis::Vertical,
|
0 => Axis::Vertical,
|
||||||
_ => Axis::Horizontal,
|
_ => Axis::Horizontal,
|
||||||
};
|
};
|
||||||
self.proxy
|
if let Err(e) = self
|
||||||
.notify_pointer_axis_discrete(&self.session, axis, value)
|
.proxy
|
||||||
.await?;
|
.notify_pointer_axis_discrete(
|
||||||
|
self.session.as_ref().expect("no session"),
|
||||||
|
axis,
|
||||||
|
value,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
log::warn!("{e}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
PointerEvent::Axis {
|
PointerEvent::Axis {
|
||||||
time: _,
|
time: _,
|
||||||
@@ -114,9 +130,18 @@ impl<'a> InputEmulation for DesktopPortalEmulation<'a> {
|
|||||||
Axis::Vertical => (0., value),
|
Axis::Vertical => (0., value),
|
||||||
Axis::Horizontal => (value, 0.),
|
Axis::Horizontal => (value, 0.),
|
||||||
};
|
};
|
||||||
self.proxy
|
if let Err(e) = self
|
||||||
.notify_pointer_axis(&self.session, dx, dy, true)
|
.proxy
|
||||||
.await?;
|
.notify_pointer_axis(
|
||||||
|
self.session.as_ref().expect("no session"),
|
||||||
|
dx,
|
||||||
|
dy,
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
log::warn!("{e}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
PointerEvent::Frame {} => {}
|
PointerEvent::Frame {} => {}
|
||||||
},
|
},
|
||||||
@@ -131,9 +156,17 @@ impl<'a> InputEmulation for DesktopPortalEmulation<'a> {
|
|||||||
0 => KeyState::Released,
|
0 => KeyState::Released,
|
||||||
_ => KeyState::Pressed,
|
_ => KeyState::Pressed,
|
||||||
};
|
};
|
||||||
self.proxy
|
if let Err(e) = self
|
||||||
.notify_keyboard_keycode(&self.session, key as i32, state)
|
.proxy
|
||||||
.await?;
|
.notify_keyboard_keycode(
|
||||||
|
self.session.as_ref().expect("no session"),
|
||||||
|
key as i32,
|
||||||
|
state,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
log::warn!("{e}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
KeyboardEvent::Modifiers { .. } => {
|
KeyboardEvent::Modifiers { .. } => {
|
||||||
// ignore
|
// ignore
|
||||||
@@ -142,28 +175,22 @@ impl<'a> InputEmulation for DesktopPortalEmulation<'a> {
|
|||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(&mut self, _client: EmulationHandle) {}
|
async fn create(&mut self, _client: EmulationHandle) {}
|
||||||
async fn destroy(&mut self, _client: EmulationHandle) {}
|
async fn destroy(&mut self, _client: EmulationHandle) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> AsyncDrop for DesktopPortalEmulation<'a> {
|
impl<'a> Drop for DesktopPortalEmulation<'a> {
|
||||||
#[doc = r" Perform the async cleanup."]
|
fn drop(&mut self) {
|
||||||
#[must_use]
|
let session = self.session.take().expect("no session");
|
||||||
#[allow(clippy::type_complexity, clippy::type_repetition_in_bounds)]
|
tokio::runtime::Handle::try_current()
|
||||||
fn async_drop<'async_trait>(
|
.expect("no runtime")
|
||||||
self,
|
.block_on(async move {
|
||||||
) -> ::core::pin::Pin<
|
log::debug!("closing remote desktop session");
|
||||||
Box<dyn ::core::future::Future<Output = ()> + ::core::marker::Send + 'async_trait>,
|
if let Err(e) = session.close().await {
|
||||||
>
|
log::error!("failed to close remote desktop session: {e}");
|
||||||
where
|
}
|
||||||
Self: 'async_trait,
|
});
|
||||||
{
|
|
||||||
async move {
|
|
||||||
let _ = self.session.close().await;
|
|
||||||
}
|
|
||||||
.boxed()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,4 +11,4 @@ anyhow = "1.0.86"
|
|||||||
futures-core = "0.3.30"
|
futures-core = "0.3.30"
|
||||||
log = "0.4.22"
|
log = "0.4.22"
|
||||||
num_enum = "0.7.2"
|
num_enum = "0.7.2"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = "1.0.203"
|
||||||
|
|||||||
@@ -27,23 +27,22 @@ async fn input_emulation_test(config: Config) -> Result<()> {
|
|||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
let mut offset = (0, 0);
|
let mut offset = (0, 0);
|
||||||
loop {
|
loop {
|
||||||
tokio::time::sleep(Duration::from_millis(1)).await;
|
tokio::select! {
|
||||||
let elapsed = start.elapsed();
|
_ = emulation.dispatch() => {}
|
||||||
let elapsed_sec_f64 = elapsed.as_secs_f64();
|
_ = tokio::time::sleep(Duration::from_millis(1)) => {
|
||||||
let second_fraction = elapsed_sec_f64 - elapsed_sec_f64 as u64 as f64;
|
let elapsed = start.elapsed();
|
||||||
let radians = second_fraction * 2. * PI * FREQUENCY_HZ;
|
let elapsed_sec_f64 = elapsed.as_secs_f64();
|
||||||
let new_offset_f = (radians.cos() * RADIUS * 2., (radians * 2.).sin() * RADIUS);
|
let second_fraction = elapsed_sec_f64 - elapsed_sec_f64 as u64 as f64;
|
||||||
let new_offset = (new_offset_f.0 as i32, new_offset_f.1 as i32);
|
let radians = second_fraction * 2. * PI * FREQUENCY_HZ;
|
||||||
if new_offset != offset {
|
let new_offset_f = (radians.cos() * RADIUS * 2., (radians * 2.).sin() * RADIUS);
|
||||||
let relative_motion = (new_offset.0 - offset.0, new_offset.1 - offset.1);
|
let new_offset = (new_offset_f.0 as i32, new_offset_f.1 as i32);
|
||||||
offset = new_offset;
|
if new_offset != offset {
|
||||||
let (relative_x, relative_y) = (relative_motion.0 as f64, relative_motion.1 as f64);
|
let relative_motion = (new_offset.0 - offset.0, new_offset.1 - offset.1);
|
||||||
let event = Event::Pointer(PointerEvent::Motion {
|
offset = new_offset;
|
||||||
time: 0,
|
let (relative_x, relative_y) = (relative_motion.0 as f64, relative_motion.1 as f64);
|
||||||
relative_x,
|
emulation.consume(Event::Pointer(PointerEvent::Motion {time: 0, relative_x, relative_y }), 0).await;
|
||||||
relative_y,
|
}
|
||||||
});
|
}
|
||||||
emulation.consume(event, 0).await?;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,11 +7,7 @@ use tokio::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{client::ClientHandle, config::EmulationBackend, server::State};
|
use crate::{client::ClientHandle, config::EmulationBackend, server::State};
|
||||||
use input_emulation::{
|
use input_emulation::{self, error::EmulationCreationError, EmulationHandle, InputEmulation};
|
||||||
self,
|
|
||||||
error::{EmulationCreationError, EmulationError},
|
|
||||||
EmulationHandle, InputEmulation,
|
|
||||||
};
|
|
||||||
use input_event::{Event, KeyboardEvent};
|
use input_event::{Event, KeyboardEvent};
|
||||||
|
|
||||||
use super::{CaptureEvent, Server};
|
use super::{CaptureEvent, Server};
|
||||||
@@ -46,19 +42,22 @@ pub fn new(
|
|||||||
tokio::select! {
|
tokio::select! {
|
||||||
udp_event = udp_rx.recv() => {
|
udp_event = udp_rx.recv() => {
|
||||||
let udp_event = udp_event.ok_or(anyhow!("receiver closed"))??;
|
let udp_event = udp_event.ok_or(anyhow!("receiver closed"))??;
|
||||||
handle_udp_rx(&server, &capture_tx, &mut emulate, &sender_tx, &mut last_ignored, udp_event, &timer_tx).await?;
|
handle_udp_rx(&server, &capture_tx, &mut emulate, &sender_tx, &mut last_ignored, udp_event, &timer_tx).await;
|
||||||
}
|
}
|
||||||
emulate_event = rx.recv() => {
|
emulate_event = rx.recv() => {
|
||||||
match emulate_event {
|
match emulate_event {
|
||||||
Some(e) => match e {
|
Some(e) => match e {
|
||||||
EmulationEvent::Create(h) => emulate.create(h).await,
|
EmulationEvent::Create(h) => emulate.create(h).await,
|
||||||
EmulationEvent::Destroy(h) => emulate.destroy(h).await,
|
EmulationEvent::Destroy(h) => emulate.destroy(h).await,
|
||||||
EmulationEvent::ReleaseKeys(c) => release_keys(&server, &mut emulate, c).await?,
|
EmulationEvent::ReleaseKeys(c) => release_keys(&server, &mut emulate, c).await,
|
||||||
EmulationEvent::Terminate => break,
|
EmulationEvent::Terminate => break,
|
||||||
},
|
},
|
||||||
None => break,
|
None => break,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
res = emulate.dispatch() => {
|
||||||
|
res?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +69,7 @@ pub fn new(
|
|||||||
.map(|(h, _)| h)
|
.map(|(h, _)| h)
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
for client in clients {
|
for client in clients {
|
||||||
release_keys(&server, &mut emulate, client).await?;
|
release_keys(&server, &mut emulate, client).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
anyhow::Ok(())
|
anyhow::Ok(())
|
||||||
@@ -86,7 +85,7 @@ async fn handle_udp_rx(
|
|||||||
last_ignored: &mut Option<SocketAddr>,
|
last_ignored: &mut Option<SocketAddr>,
|
||||||
event: (Event, SocketAddr),
|
event: (Event, SocketAddr),
|
||||||
timer_tx: &Sender<()>,
|
timer_tx: &Sender<()>,
|
||||||
) -> Result<(), EmulationError> {
|
) {
|
||||||
let (event, addr) = event;
|
let (event, addr) = event;
|
||||||
|
|
||||||
// get handle for addr
|
// get handle for addr
|
||||||
@@ -97,7 +96,7 @@ async fn handle_udp_rx(
|
|||||||
log::warn!("ignoring events from client {addr}");
|
log::warn!("ignoring events from client {addr}");
|
||||||
last_ignored.replace(addr);
|
last_ignored.replace(addr);
|
||||||
}
|
}
|
||||||
return Ok(());
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -111,7 +110,7 @@ async fn handle_udp_rx(
|
|||||||
Some((_, s)) => s,
|
Some((_, s)) => s,
|
||||||
None => {
|
None => {
|
||||||
log::error!("unknown handle");
|
log::error!("unknown handle");
|
||||||
return Ok(());
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -127,7 +126,7 @@ async fn handle_udp_rx(
|
|||||||
let _ = sender_tx.send((Event::Pong(), addr)).await;
|
let _ = sender_tx.send((Event::Pong(), addr)).await;
|
||||||
}
|
}
|
||||||
(Event::Disconnect(), _) => {
|
(Event::Disconnect(), _) => {
|
||||||
release_keys(server, emulate, handle).await?;
|
release_keys(server, emulate, handle).await;
|
||||||
}
|
}
|
||||||
(event, addr) => {
|
(event, addr) => {
|
||||||
// tell clients that we are ready to receive events
|
// tell clients that we are ready to receive events
|
||||||
@@ -160,7 +159,7 @@ async fn handle_udp_rx(
|
|||||||
s
|
s
|
||||||
} else {
|
} else {
|
||||||
log::error!("unknown handle");
|
log::error!("unknown handle");
|
||||||
return Ok(());
|
return;
|
||||||
};
|
};
|
||||||
if state == 0 {
|
if state == 0 {
|
||||||
// ignore release event if key not pressed
|
// ignore release event if key not pressed
|
||||||
@@ -175,7 +174,7 @@ async fn handle_udp_rx(
|
|||||||
// workaround buggy rdp backend.
|
// workaround buggy rdp backend.
|
||||||
if !ignore_event {
|
if !ignore_event {
|
||||||
// consume event
|
// consume event
|
||||||
emulate.consume(event, handle).await?;
|
emulate.consume(event, handle).await;
|
||||||
log::trace!("{event} => emulate");
|
log::trace!("{event} => emulate");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -200,14 +199,13 @@ async fn handle_udp_rx(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn release_keys(
|
async fn release_keys(
|
||||||
server: &Server,
|
server: &Server,
|
||||||
emulate: &mut Box<dyn InputEmulation>,
|
emulate: &mut Box<dyn InputEmulation>,
|
||||||
client: ClientHandle,
|
client: ClientHandle,
|
||||||
) -> Result<(), EmulationError> {
|
) {
|
||||||
let keys = server
|
let keys = server
|
||||||
.client_manager
|
.client_manager
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
@@ -222,18 +220,19 @@ async fn release_keys(
|
|||||||
key,
|
key,
|
||||||
state: 0,
|
state: 0,
|
||||||
});
|
});
|
||||||
emulate.consume(event, client).await?;
|
emulate.consume(event, client).await;
|
||||||
if let Ok(key) = input_event::scancode::Linux::try_from(key) {
|
if let Ok(key) = input_event::scancode::Linux::try_from(key) {
|
||||||
log::warn!("releasing stuck key: {key:?}");
|
log::warn!("releasing stuck key: {key:?}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let event = Event::Keyboard(KeyboardEvent::Modifiers {
|
let modifiers_event = KeyboardEvent::Modifiers {
|
||||||
mods_depressed: 0,
|
mods_depressed: 0,
|
||||||
mods_latched: 0,
|
mods_latched: 0,
|
||||||
mods_locked: 0,
|
mods_locked: 0,
|
||||||
group: 0,
|
group: 0,
|
||||||
});
|
};
|
||||||
emulate.consume(event, client).await?;
|
emulate
|
||||||
Ok(())
|
.consume(Event::Keyboard(modifiers_event), client)
|
||||||
|
.await;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user