simple refact

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2023-04-08 17:56:04 +08:00
parent 4a8d61ac09
commit 072da85f09

View File

@ -1372,16 +1372,18 @@ fn simulate_win2win_hotkey(code: u32, down: bool) {
} }
#[cfg(not(any(target_os = "windows", target_os = "linux")))] #[cfg(not(any(target_os = "windows", target_os = "linux")))]
fn skip_led_sync(_evt: &KeyEvent) -> bool { fn skip_led_sync_control_key(_evt: &KeyEvent) -> bool {
false false
} }
// LockModesHandler should not be created when single meta is pressing and releasing.
// Because the drop function may insert "CapsLock Click" and "NumLock Click", which breaks single meta click.
// https://github.com/rustdesk/rustdesk/issues/3928#issuecomment-1496936687
// https://github.com/rustdesk/rustdesk/issues/3928#issuecomment-1500415822
// https://github.com/rustdesk/rustdesk/issues/3928#issuecomment-1500773473
#[cfg(any(target_os = "windows", target_os = "linux"))] #[cfg(any(target_os = "windows", target_os = "linux"))]
fn skip_led_sync(evt: &KeyEvent) -> bool { fn skip_led_sync_control_key(key: &ControlKey) -> bool {
match (&evt.union, evt.mode.enum_value_or(KeyboardMode::Legacy)) { [
(Some(key_event::Union::ControlKey(ck)), _) => {
let key = ck.enum_value_or(ControlKey::Unknown);
return [
ControlKey::Control, ControlKey::Control,
ControlKey::Meta, ControlKey::Meta,
ControlKey::Shift, ControlKey::Shift,
@ -1389,11 +1391,17 @@ fn skip_led_sync(evt: &KeyEvent) -> bool {
ControlKey::Tab, ControlKey::Tab,
ControlKey::Return, ControlKey::Return,
] ]
.contains(&key); .contains(key)
} }
(Some(key_event::Union::Chr(code)), KeyboardMode::Map | KeyboardMode::Translate) => {
let key = crate::keycode_to_rdev_key(*code); #[cfg(not(any(target_os = "windows", target_os = "linux")))]
return [ fn skip_led_sync_rdev_key(_evt: &KeyEvent) -> bool {
false
}
#[cfg(any(target_os = "windows", target_os = "linux"))]
fn skip_led_sync_rdev_key(key: &RdevKey) -> bool {
[
RdevKey::ControlLeft, RdevKey::ControlLeft,
RdevKey::ControlRight, RdevKey::ControlRight,
RdevKey::MetaLeft, RdevKey::MetaLeft,
@ -1405,11 +1413,7 @@ fn skip_led_sync(evt: &KeyEvent) -> bool {
RdevKey::Tab, RdevKey::Tab,
RdevKey::Return, RdevKey::Return,
] ]
.contains(&key); .contains(key)
}
_ => {}
}
false
} }
pub fn handle_key_(evt: &KeyEvent) { pub fn handle_key_(evt: &KeyEvent) {
@ -1417,22 +1421,24 @@ pub fn handle_key_(evt: &KeyEvent) {
return; return;
} }
let _lock_mode_handler = match &evt.union { let mut _lock_mode_handler = None;
Some(key_event::Union::Unicode(..)) | Some(key_event::Union::Seq(..)) => { match (&evt.union, evt.mode.enum_value_or(KeyboardMode::Legacy)) {
Some(LockModesHandler::new(&evt)) (Some(key_event::Union::Unicode(..)) | Some(key_event::Union::Seq(..)), _) => {
_lock_mode_handler = Some(LockModesHandler::new(&evt));
} }
_ => { (Some(key_event::Union::ControlKey(ck)), _) => {
// LockModesHandler should not be created when single meta is pressing and releasing. let key = ck.enum_value_or(ControlKey::Unknown);
// Because the drop function may insert "CapsLock Click" and "NumLock Click", which breaks single meta click. if !skip_led_sync_control_key(&key) {
// https://github.com/rustdesk/rustdesk/issues/3928#issuecomment-1496936687 _lock_mode_handler = Some(LockModesHandler::new(&evt));
// https://github.com/rustdesk/rustdesk/issues/3928#issuecomment-1500415822
// https://github.com/rustdesk/rustdesk/issues/3928#issuecomment-1500773473
if evt.down && !skip_led_sync(evt) {
Some(LockModesHandler::new(evt))
} else {
None
} }
} }
(Some(key_event::Union::Chr(code)), KeyboardMode::Map | KeyboardMode::Translate) => {
let key = crate::keycode_to_rdev_key(*code);
if !skip_led_sync_rdev_key(&key) {
_lock_mode_handler = Some(LockModesHandler::new(evt));
}
}
_ => {}
}; };
match evt.mode.unwrap() { match evt.mode.unwrap() {