Merge pull request #2064 from fufesou/fix_cursor

fix mouse cannot be controled, when show remote cursor is on
This commit is contained in:
RustDesk 2022-11-11 15:05:52 +08:00 committed by GitHub
commit 3626a26523
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,6 +13,8 @@ use std::{
time::Instant, time::Instant,
}; };
const INVALID_CURSOR_POS: i32 = i32::MIN;
#[derive(Default)] #[derive(Default)]
struct StateCursor { struct StateCursor {
hcursor: u64, hcursor: u64,
@ -28,14 +30,33 @@ impl super::service::Reset for StateCursor {
} }
} }
#[derive(Default)]
struct StatePos { struct StatePos {
cursor_pos: (i32, i32), cursor_pos: (i32, i32),
} }
impl Default for StatePos {
fn default() -> Self {
Self {
cursor_pos: (INVALID_CURSOR_POS, INVALID_CURSOR_POS),
}
}
}
impl super::service::Reset for StatePos { impl super::service::Reset for StatePos {
fn reset(&mut self) { fn reset(&mut self) {
self.cursor_pos = (0, 0); self.cursor_pos = (INVALID_CURSOR_POS, INVALID_CURSOR_POS);
}
}
impl StatePos {
#[inline]
fn is_valid(&self) -> bool {
self.cursor_pos.0 != INVALID_CURSOR_POS
}
#[inline]
fn is_moved(&self, x: i32, y: i32) -> bool {
self.is_valid() && (self.cursor_pos.0 != x || self.cursor_pos.1 != y)
} }
} }
@ -114,8 +135,7 @@ fn update_last_cursor_pos(x: i32, y: i32) {
fn run_pos(sp: GenericService, state: &mut StatePos) -> ResultType<()> { fn run_pos(sp: GenericService, state: &mut StatePos) -> ResultType<()> {
if let Some((x, y)) = crate::get_cursor_pos() { if let Some((x, y)) = crate::get_cursor_pos() {
update_last_cursor_pos(x, y); update_last_cursor_pos(x, y);
if state.cursor_pos.0 != x || state.cursor_pos.1 != y { if state.is_moved(x, y) {
state.cursor_pos = (x, y);
let mut msg_out = Message::new(); let mut msg_out = Message::new();
msg_out.set_cursor_position(CursorPosition { msg_out.set_cursor_position(CursorPosition {
x, x,
@ -133,6 +153,7 @@ fn run_pos(sp: GenericService, state: &mut StatePos) -> ResultType<()> {
}; };
sp.send_without(msg_out, exclude); sp.send_without(msg_out, exclude);
} }
state.cursor_pos = (x, y);
} }
sp.snapshot(|sps| { sp.snapshot(|sps| {