mirror of
https://github.com/weyne85/rustdesk.git
synced 2025-10-29 17:00:05 +00:00
fix, RwLock, remove nested read calls
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
@@ -56,22 +56,6 @@ pub mod client {
|
||||
static ref IS_GRAB_STARTED: Arc<Mutex<bool>> = Arc::new(Mutex::new(false));
|
||||
}
|
||||
|
||||
pub fn get_keyboard_mode() -> String {
|
||||
#[cfg(not(any(feature = "flutter", feature = "cli")))]
|
||||
if let Some(session) = CUR_SESSION.lock().unwrap().as_ref() {
|
||||
return session.get_keyboard_mode();
|
||||
}
|
||||
#[cfg(feature = "flutter")]
|
||||
if let Some(session) = SESSIONS
|
||||
.read()
|
||||
.unwrap()
|
||||
.get(&*CUR_SESSION_ID.read().unwrap())
|
||||
{
|
||||
return session.get_keyboard_mode();
|
||||
}
|
||||
"legacy".to_string()
|
||||
}
|
||||
|
||||
pub fn start_grab_loop() {
|
||||
let mut lock = IS_GRAB_STARTED.lock().unwrap();
|
||||
if *lock {
|
||||
@@ -82,12 +66,12 @@ pub mod client {
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
pub fn change_grab_status(state: GrabState) {
|
||||
pub fn change_grab_status(state: GrabState, keyboard_mode: &str) {
|
||||
match state {
|
||||
GrabState::Ready => {}
|
||||
GrabState::Run => {
|
||||
#[cfg(windows)]
|
||||
update_grab_get_key_name();
|
||||
update_grab_get_key_name(keyboard_mode);
|
||||
#[cfg(any(target_os = "windows", target_os = "macos"))]
|
||||
KEYBOARD_HOOKED.swap(true, Ordering::SeqCst);
|
||||
|
||||
@@ -95,7 +79,10 @@ pub mod client {
|
||||
rdev::enable_grab();
|
||||
}
|
||||
GrabState::Wait => {
|
||||
release_remote_keys();
|
||||
#[cfg(windows)]
|
||||
rdev::set_get_key_unicode(false);
|
||||
|
||||
release_remote_keys(keyboard_mode);
|
||||
|
||||
#[cfg(any(target_os = "windows", target_os = "macos"))]
|
||||
KEYBOARD_HOOKED.swap(false, Ordering::SeqCst);
|
||||
@@ -110,17 +97,16 @@ pub mod client {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn process_event(event: &Event, lock_modes: Option<i32>) -> KeyboardMode {
|
||||
let keyboard_mode = get_keyboard_mode_enum();
|
||||
pub fn process_event(keyboard_mode: &str, event: &Event, lock_modes: Option<i32>) {
|
||||
let keyboard_mode = get_keyboard_mode_enum(keyboard_mode);
|
||||
|
||||
if is_long_press(&event) {
|
||||
return keyboard_mode;
|
||||
return;
|
||||
}
|
||||
|
||||
for key_event in event_to_key_events(&event, keyboard_mode, lock_modes) {
|
||||
send_key_event(&key_event);
|
||||
}
|
||||
keyboard_mode
|
||||
}
|
||||
|
||||
pub fn get_modifiers_state(
|
||||
@@ -215,10 +201,11 @@ pub mod client {
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
pub fn update_grab_get_key_name() {
|
||||
match get_keyboard_mode_enum() {
|
||||
KeyboardMode::Map => rdev::set_get_key_unicode(false),
|
||||
KeyboardMode::Translate => rdev::set_get_key_unicode(true),
|
||||
pub fn update_grab_get_key_name(keyboard_mode: &str) {
|
||||
match keyboard_mode {
|
||||
"map" => rdev::set_get_key_unicode(false),
|
||||
"translate" => rdev::set_get_key_unicode(true),
|
||||
"legacy" => rdev::set_get_key_unicode(true),
|
||||
_ => {}
|
||||
};
|
||||
}
|
||||
@@ -229,6 +216,22 @@ static mut IS_0X021D_DOWN: bool = false;
|
||||
#[cfg(target_os = "macos")]
|
||||
static mut IS_LEFT_OPTION_DOWN: bool = false;
|
||||
|
||||
fn get_keyboard_mode() -> String {
|
||||
#[cfg(not(any(feature = "flutter", feature = "cli")))]
|
||||
if let Some(session) = CUR_SESSION.lock().unwrap().as_ref() {
|
||||
return session.get_keyboard_mode();
|
||||
}
|
||||
#[cfg(feature = "flutter")]
|
||||
if let Some(session) = SESSIONS
|
||||
.read()
|
||||
.unwrap()
|
||||
.get(&*CUR_SESSION_ID.read().unwrap())
|
||||
{
|
||||
return session.get_keyboard_mode();
|
||||
}
|
||||
"legacy".to_string()
|
||||
}
|
||||
|
||||
pub fn start_grab_loop() {
|
||||
std::env::set_var("KEYBOARD_ONLY", "y");
|
||||
#[cfg(any(target_os = "windows", target_os = "macos"))]
|
||||
@@ -239,11 +242,10 @@ pub fn start_grab_loop() {
|
||||
return Some(event);
|
||||
}
|
||||
|
||||
let mut _keyboard_mode = KeyboardMode::Map;
|
||||
let _scan_code = event.position_code;
|
||||
let _code = event.platform_code as KeyCode;
|
||||
let res = if KEYBOARD_HOOKED.load(Ordering::SeqCst) {
|
||||
_keyboard_mode = client::process_event(&event, None);
|
||||
client::process_event(&get_keyboard_mode(), &event, None);
|
||||
if is_press {
|
||||
None
|
||||
} else {
|
||||
@@ -304,7 +306,7 @@ pub fn start_grab_loop() {
|
||||
if let Key::Unknown(keycode) = key {
|
||||
log::error!("rdev get unknown key, keycode is : {:?}", keycode);
|
||||
} else {
|
||||
client::process_event(&event, None);
|
||||
client::process_event(&get_keyboard_mode(), &event, None);
|
||||
}
|
||||
None
|
||||
}
|
||||
@@ -330,7 +332,7 @@ pub fn is_long_press(event: &Event) -> bool {
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
pub fn release_remote_keys() {
|
||||
pub fn release_remote_keys(keyboard_mode: &str) {
|
||||
// todo!: client quit suddenly, how to release keys?
|
||||
let to_release = TO_RELEASE.lock().unwrap().clone();
|
||||
TO_RELEASE.lock().unwrap().clear();
|
||||
@@ -339,23 +341,16 @@ pub fn release_remote_keys() {
|
||||
let event = event_type_to_event(event_type);
|
||||
// to-do: BUG
|
||||
// Release events should be sent to the corresponding sessions, instead of current session.
|
||||
client::process_event(&event, None);
|
||||
client::process_event(keyboard_mode, &event, None);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_keyboard_mode_enum() -> KeyboardMode {
|
||||
match client::get_keyboard_mode().as_str() {
|
||||
pub fn get_keyboard_mode_enum(keyboard_mode: &str) -> KeyboardMode {
|
||||
match keyboard_mode {
|
||||
"map" => KeyboardMode::Map,
|
||||
"translate" => KeyboardMode::Translate,
|
||||
"legacy" => KeyboardMode::Legacy,
|
||||
_ => {
|
||||
// Set "map" as default mode if version >= 1.2.0.
|
||||
if crate::is_peer_version_ge("1.2.0") {
|
||||
KeyboardMode::Map
|
||||
} else {
|
||||
KeyboardMode::Legacy
|
||||
}
|
||||
}
|
||||
_ => KeyboardMode::Map,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user