Merge pull request #3735 from chiehw/tr-linux-client

translate mode: support x11 in client
This commit is contained in:
RustDesk 2023-03-22 23:06:06 +08:00 committed by GitHub
commit 60314577ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 43 deletions

2
Cargo.lock generated
View File

@ -4721,7 +4721,7 @@ dependencies = [
[[package]] [[package]]
name = "rdev" name = "rdev"
version = "0.5.0-2" version = "0.5.0-2"
source = "git+https://github.com/fufesou/rdev#25a99ce71ab42843ad253dd51e6a35e83e87a8a4" source = "git+https://github.com/fufesou/rdev#eaa35ff9af22891b4aae3a0a5e83472c16177cd8"
dependencies = [ dependencies = [
"cocoa", "cocoa",
"core-foundation 0.9.3", "core-foundation 0.9.3",

View File

@ -1688,11 +1688,6 @@ class _KeyboardMenu extends StatelessWidget {
if (pi.is_wayland && mode.key != _kKeyMapMode) { if (pi.is_wayland && mode.key != _kKeyMapMode) {
continue; continue;
} }
if (mode.key == _kKeyTranslateMode) {
if (Platform.isLinux) {
continue;
}
}
var text = translate(mode.menu); var text = translate(mode.menu);
if (mode.key == _kKeyTranslateMode) { if (mode.key == _kKeyTranslateMode) {
text = '$text beta'; text = '$text beta';

View File

@ -227,8 +227,8 @@ pub fn start_grab_loop() {
} }
let mut _keyboard_mode = KeyboardMode::Map; let mut _keyboard_mode = KeyboardMode::Map;
let _scan_code = event.scan_code; let _scan_code = event.position_code;
let _code = event.code; let _code = event.platform_code;
let res = if KEYBOARD_HOOKED.load(Ordering::SeqCst) { let res = if KEYBOARD_HOOKED.load(Ordering::SeqCst) {
_keyboard_mode = client::process_event(&event, None); _keyboard_mode = client::process_event(&event, None);
if is_press { if is_press {
@ -460,8 +460,8 @@ pub fn event_type_to_event(event_type: EventType) -> Event {
event_type, event_type,
time: SystemTime::now(), time: SystemTime::now(),
unicode: None, unicode: None,
code: 0, platform_code: 0,
scan_code: 0, position_code: 0,
} }
} }
@ -546,7 +546,7 @@ pub fn legacy_keyboard_mode(event: &Event, mut key_event: KeyEvent) -> Vec<KeyEv
// when pressing AltGr, an extra VK_LCONTROL with a special // when pressing AltGr, an extra VK_LCONTROL with a special
// scancode with bit 9 set is sent, let's ignore this. // scancode with bit 9 set is sent, let's ignore this.
#[cfg(windows)] #[cfg(windows)]
if (event.scan_code >> 8) == 0xE0 { if (event.position_code >> 8) == 0xE0 {
unsafe { unsafe {
IS_ALT_GR = true; IS_ALT_GR = true;
} }
@ -741,37 +741,37 @@ pub fn map_keyboard_mode(peer: &str, event: &Event, mut key_event: KeyEvent) ->
OS_LOWER_WINDOWS => { OS_LOWER_WINDOWS => {
// https://github.com/rustdesk/rustdesk/issues/1371 // https://github.com/rustdesk/rustdesk/issues/1371
// Filter scancodes that are greater than 255 and the hight word is not 0xE0. // Filter scancodes that are greater than 255 and the hight word is not 0xE0.
if event.scan_code > 255 && (event.scan_code >> 8) != 0xE0 { if event.position_code > 255 && (event.position_code >> 8) != 0xE0 {
return None; return None;
} }
event.scan_code event.position_code
} }
OS_LOWER_MACOS => { OS_LOWER_MACOS => {
if hbb_common::config::LocalConfig::get_kb_layout_type() == "ISO" { if hbb_common::config::LocalConfig::get_kb_layout_type() == "ISO" {
rdev::win_scancode_to_macos_iso_code(event.scan_code)? rdev::win_scancode_to_macos_iso_code(event.position_code)?
} else { } else {
rdev::win_scancode_to_macos_code(event.scan_code)? rdev::win_scancode_to_macos_code(event.position_code)?
} }
} }
_ => rdev::win_scancode_to_linux_code(event.scan_code)?, _ => rdev::win_scancode_to_linux_code(event.position_code)?,
}; };
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
let keycode = match peer { let keycode = match peer {
OS_LOWER_WINDOWS => rdev::macos_code_to_win_scancode(event.code as _)?, OS_LOWER_WINDOWS => rdev::macos_code_to_win_scancode(event.platform_code as _)?,
OS_LOWER_MACOS => event.code as _, OS_LOWER_MACOS => event.platform_code as _,
_ => rdev::macos_code_to_linux_code(event.code as _)?, _ => rdev::macos_code_to_linux_code(event.platform_code as _)?,
}; };
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
let keycode = match peer { let keycode = match peer {
OS_LOWER_WINDOWS => rdev::linux_code_to_win_scancode(event.code as _)?, OS_LOWER_WINDOWS => rdev::linux_code_to_win_scancode(event.position_code as _)?,
OS_LOWER_MACOS => { OS_LOWER_MACOS => {
if hbb_common::config::LocalConfig::get_kb_layout_type() == "ISO" { if hbb_common::config::LocalConfig::get_kb_layout_type() == "ISO" {
rdev::linux_code_to_macos_iso_code(event.code as _)? rdev::linux_code_to_macos_iso_code(event.position_code as _)?
} else { } else {
rdev::linux_code_to_macos_code(event.code as _)? rdev::linux_code_to_macos_code(event.position_code as _)?
} }
} }
_ => event.code as _, _ => event.position_code as _,
}; };
#[cfg(any(target_os = "android", target_os = "ios"))] #[cfg(any(target_os = "android", target_os = "ios"))]
let keycode = 0; let keycode = 0;
@ -795,7 +795,7 @@ fn try_fill_unicode(event: &Event, key_event: &KeyEvent, events: &mut Vec<KeyEve
{ {
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
if is_hot_key_modifiers_down() && unsafe { !IS_0X021D_DOWN } { if is_hot_key_modifiers_down() && unsafe { !IS_0X021D_DOWN } {
if let Some(chr) = get_char_by_vk(event.code as u32) { if let Some(chr) = get_char_by_vk(event.platform_code as u32) {
let mut evt = key_event.clone(); let mut evt = key_event.clone();
evt.set_seq(chr.to_string()); evt.set_seq(chr.to_string());
events.push(evt); events.push(evt);
@ -823,7 +823,7 @@ fn is_hot_key_modifiers_down() -> bool {
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
pub fn translate_key_code(peer: &str, event: &Event, key_event: KeyEvent) -> Option<KeyEvent> { pub fn translate_key_code(peer: &str, event: &Event, key_event: KeyEvent) -> Option<KeyEvent> {
let mut key_event = map_keyboard_mode(peer, event, key_event)?; let mut key_event = map_keyboard_mode(peer, event, key_event)?;
key_event.set_chr((key_event.chr() & 0x0000FFFF) | ((event.code as u32) << 16)); key_event.set_chr((key_event.chr() & 0x0000FFFF) | ((event.platform_code as u32) << 16));
Some(key_event) Some(key_event)
} }
@ -833,6 +833,28 @@ pub fn translate_key_code(peer: &str, event: &Event, key_event: KeyEvent) -> Opt
map_keyboard_mode(peer, event, key_event) map_keyboard_mode(peer, event, key_event)
} }
#[inline]
#[cfg(any(target_os = "linux", target_os = "windows"))]
fn is_altgr(event: &Event) -> bool {
#[cfg(target_os = "linux")]
if event.platform_code == 0xFE03 {
true
} else {
false
}
#[cfg(target_os = "windows")]
if unsafe { IS_0X021D_DOWN } && event.position_code == 0xE038 {
true
} else {
false
}
}
fn is_press(event: &Event) -> bool {
matches!(event.event_type, EventType::KeyPress(_))
}
pub fn translate_keyboard_mode(peer: &str, event: &Event, key_event: KeyEvent) -> Vec<KeyEvent> { pub fn translate_keyboard_mode(peer: &str, event: &Event, key_event: KeyEvent) -> Vec<KeyEvent> {
let mut events: Vec<KeyEvent> = Vec::new(); let mut events: Vec<KeyEvent> = Vec::new();
if let Some(unicode_info) = &event.unicode { if let Some(unicode_info) = &event.unicode {
@ -851,25 +873,22 @@ pub fn translate_keyboard_mode(peer: &str, event: &Event, key_event: KeyEvent) -
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
// ignore right option key // ignore right option key
if event.code as u32 == rdev::kVK_RightOption { if event.platform_code as u32 == rdev::kVK_RightOption {
return events;
}
#[cfg(any(target_os = "linux", target_os = "windows"))]
if is_altgr(event) {
return events; return events;
} }
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
unsafe { if event.position_code == 0x021D {
if event.scan_code == 0x021D {
return events; return events;
} }
if IS_0X021D_DOWN { #[cfg(any(target_os = "linux", target_os = "windows"))]
if event.scan_code == 0xE038 { if is_press(event) {
return events;
}
}
}
#[cfg(target_os = "windows")]
if matches!(event.event_type, EventType::KeyPress(_)) {
try_fill_unicode(event, &key_event, &mut events); try_fill_unicode(event, &key_event, &mut events);
} }
@ -880,9 +899,6 @@ pub fn translate_keyboard_mode(peer: &str, event: &Event, key_event: KeyEvent) -
} }
} }
#[cfg(target_os = "linux")]
try_fill_unicode(event, &key_event, &mut events);
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
if !unsafe { IS_LEFT_OPTION_DOWN } { if !unsafe { IS_LEFT_OPTION_DOWN } {
try_fill_unicode(event, &key_event, &mut events); try_fill_unicode(event, &key_event, &mut events);

View File

@ -562,8 +562,8 @@ impl<T: InvokeUiSession> Session<T> {
let event = Event { let event = Event {
time: SystemTime::now(), time: SystemTime::now(),
unicode: None, unicode: None,
code: keycode as _, platform_code: keycode as _,
scan_code: scancode as _, position_code: scancode as _,
event_type: event_type, event_type: event_type,
}; };
keyboard::client::process_event(&event, Some(lock_modes)); keyboard::client::process_event(&event, Some(lock_modes));