From edcfd2a801920410b2b8dd650ba5202db0e6698b Mon Sep 17 00:00:00 2001 From: fufesou Date: Tue, 13 Jun 2023 10:59:37 +0800 Subject: [PATCH] keyboard do not work, when more than one connection, cursor jump to the other connection Signed-off-by: fufesou --- src/client.rs | 12 ++++-------- src/flutter_ffi.rs | 9 ++++++++- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/client.rs b/src/client.rs index c56eee294..df4358787 100644 --- a/src/client.rs +++ b/src/client.rs @@ -53,11 +53,7 @@ use scrap::{ ImageFormat, ImageRgb, }; -use crate::common::{ - self, - input::{MOUSE_TYPE_TRACKPAD, MOUSE_TYPE_WHEEL}, - is_keyboard_mode_supported, -}; +use crate::common::{self, is_keyboard_mode_supported}; #[cfg(not(any(target_os = "android", target_os = "ios")))] use crate::common::{check_clipboard, ClipboardContext, CLIPBOARD_INTERVAL}; @@ -1912,10 +1908,10 @@ pub async fn handle_test_delay(t: TestDelay, peer: &mut Stream) { #[cfg(all(target_os = "macos"))] fn check_scroll_on_mac(mask: i32, x: i32, y: i32) -> bool { // flutter version we set mask type bit to 4 when track pad scrolling. - if mask & 7 == MOUSE_TYPE_TRACKPAD { + if mask & 7 == crate::common::input::MOUSE_TYPE_TRACKPAD { return true; } - if mask & 3 != MOUSE_TYPE_WHEEL { + if mask & 3 != crate::common::input::MOUSE_TYPE_WHEEL { return false; } let btn = mask >> 3; @@ -1979,7 +1975,7 @@ pub fn send_mouse( #[cfg(all(target_os = "macos", not(feature = "flutter")))] if check_scroll_on_mac(mask, x, y) { let factor = 3; - mouse_event.mask = MOUSE_TYPE_TRACKPAD; + mouse_event.mask = crate::common::input::MOUSE_TYPE_TRACKPAD; mouse_event.x *= factor; mouse_event.y *= factor; } diff --git a/src/flutter_ffi.rs b/src/flutter_ffi.rs index 33227a721..8cf0893ba 100644 --- a/src/flutter_ffi.rs +++ b/src/flutter_ffi.rs @@ -348,7 +348,13 @@ pub fn session_handle_flutter_key_event( } } -pub fn session_enter_or_leave(_session_id: SessionID, _enter: bool) { +// SyncReturn<()> is used to make sure enter() and leave() are executed in the sequence this function is called. +// +// If the cursor jumps between remote page of two connections, leave view and enter view will be called. +// session_enter_or_leave() will be called then. +// As rust is multi-thread, it is possible that enter() is called before leave(). +// This will cause the keyboard input to take no effect. +pub fn session_enter_or_leave(_session_id: SessionID, _enter: bool) -> SyncReturn<()> { #[cfg(not(any(target_os = "android", target_os = "ios")))] if let Some(session) = SESSIONS.read().unwrap().get(&_session_id) { if _enter { @@ -357,6 +363,7 @@ pub fn session_enter_or_leave(_session_id: SessionID, _enter: bool) { session.leave(); } } + SyncReturn(()) } pub fn session_input_key(