From 5424881d40a6de5e94ac3d50ccd2a978fce91e05 Mon Sep 17 00:00:00 2001 From: fufesou Date: Wed, 9 Nov 2022 16:35:08 +0800 Subject: [PATCH] better mouse control Signed-off-by: fufesou --- src/server/input_service.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/server/input_service.rs b/src/server/input_service.rs index c8b099b6d..170d672c9 100644 --- a/src/server/input_service.rs +++ b/src/server/input_service.rs @@ -379,7 +379,7 @@ fn is_mouse_active_by_conn(conn: i32) -> bool { return true; } - let last_input = *LATEST_INPUT_CURSOR.lock().unwrap(); + let mut last_input = LATEST_INPUT_CURSOR.lock().unwrap(); // last conn input may be protected if last_input.conn != conn { return false; @@ -388,8 +388,13 @@ fn is_mouse_active_by_conn(conn: i32) -> bool { // check if input is in valid range match crate::get_cursor_pos() { Some((x, y)) => { - (last_input.x - x).abs() < MOUSE_ACTIVE_DISTANCE - && (last_input.y - y).abs() < MOUSE_ACTIVE_DISTANCE + let is_same_input = (last_input.x - x).abs() < MOUSE_ACTIVE_DISTANCE + && (last_input.y - y).abs() < MOUSE_ACTIVE_DISTANCE; + if !is_same_input { + last_input.x = -MOUSE_ACTIVE_DISTANCE * 2; + last_input.y = -MOUSE_ACTIVE_DISTANCE * 2; + } + is_same_input } None => true, }