fix: wayland controlled side, cursor misalignment (#13537)

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou
2025-11-18 00:37:15 +08:00
committed by GitHub
parent a6571e71e4
commit b2dff336ce
22 changed files with 1241 additions and 187 deletions

View File

@@ -20,7 +20,10 @@ use scrap::wayland::pipewire::RDP_SESSION_INFO;
use std::{
convert::TryFrom,
ops::{Deref, DerefMut},
sync::atomic::{AtomicBool, Ordering},
sync::{
atomic::{AtomicBool, Ordering},
mpsc,
},
thread,
time::{self, Duration, Instant},
};
@@ -1834,6 +1837,51 @@ pub fn wayland_use_rdp_input() -> bool {
!crate::platform::is_x11() && !crate::is_server()
}
#[cfg(target_os = "linux")]
pub struct TemporaryMouseMoveHandle {
thread_handle: Option<std::thread::JoinHandle<()>>,
tx: Option<mpsc::Sender<(i32, i32)>>,
}
#[cfg(target_os = "linux")]
impl TemporaryMouseMoveHandle {
pub fn new() -> Self {
let (tx, rx) = mpsc::channel::<(i32, i32)>();
let thread_handle = std::thread::spawn(move || {
log::debug!("TemporaryMouseMoveHandle thread started");
for (x, y) in rx {
ENIGO.lock().unwrap().mouse_move_to(x, y);
}
log::debug!("TemporaryMouseMoveHandle thread exiting");
});
TemporaryMouseMoveHandle {
thread_handle: Some(thread_handle),
tx: Some(tx),
}
}
pub fn move_mouse_to(&self, x: i32, y: i32) {
if let Some(tx) = &self.tx {
let _ = tx.send((x, y));
}
}
}
#[cfg(target_os = "linux")]
impl Drop for TemporaryMouseMoveHandle {
fn drop(&mut self) {
log::debug!("Dropping TemporaryMouseMoveHandle");
// Close the channel to signal the thread to exit.
self.tx.take();
// Wait for the thread to finish.
if let Some(thread_handle) = self.thread_handle.take() {
if let Err(e) = thread_handle.join() {
log::error!("Error joining TemporaryMouseMoveHandle thread: {:?}", e);
}
}
}
}
lazy_static::lazy_static! {
static ref MODIFIER_MAP: HashMap<i32, Key> = [
(ControlKey::Alt, Key::Alt),