Merge pull request #3119 from fufesou/feat/keyboard_translate_mode3

Feat/keyboard translate mode
This commit is contained in:
RustDesk 2023-02-08 20:06:03 +08:00 committed by GitHub
commit d26da28218
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 18 deletions

2
Cargo.lock generated
View File

@ -4405,7 +4405,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#4d8231f05e14c5a04cd7d2c1288e87ad52d39e4c" source = "git+https://github.com/fufesou/rdev#cedc4e62744566775026af4b434ef799804c1130"
dependencies = [ dependencies = [
"cocoa", "cocoa",
"core-foundation 0.9.3", "core-foundation 0.9.3",

View File

@ -1,6 +1,9 @@
use std::{collections::HashMap, ffi::{CStr, CString}, os::raw::c_char, thread}; use std::{collections::HashMap, ffi::{CStr, CString}, os::raw::c_char};
use std::str::FromStr; use std::str::FromStr;
#[cfg(any(target_os = "linux", target_os = "macos"))]
use std::thread;
use flutter_rust_bridge::{StreamSink, SyncReturn, ZeroCopyBuffer}; use flutter_rust_bridge::{StreamSink, SyncReturn, ZeroCopyBuffer};
use serde_json::json; use serde_json::json;
@ -928,7 +931,7 @@ pub fn main_start_dbus_server() {
{ {
use crate::dbus::start_dbus_server; use crate::dbus::start_dbus_server;
// spawn new thread to start dbus server // spawn new thread to start dbus server
std::thread::spawn(|| { thread::spawn(|| {
let _ = start_dbus_server(); let _ = start_dbus_server();
}); });
} }
@ -1275,7 +1278,7 @@ pub fn main_is_login_wayland() -> SyncReturn<bool> {
pub fn main_start_pa() { pub fn main_start_pa() {
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
std::thread::spawn(crate::ipc::start_pa); thread::spawn(crate::ipc::start_pa);
} }
pub fn main_hide_docker() -> SyncReturn<bool> { pub fn main_hide_docker() -> SyncReturn<bool> {
@ -1302,9 +1305,9 @@ pub fn main_start_ipc_url_server() {
/// ///
/// * macOS only /// * macOS only
#[allow(unused_variables)] #[allow(unused_variables)]
pub fn send_url_scheme(url: String) { pub fn send_url_scheme(_url: String) {
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
thread::spawn(move || crate::ui::macos::handle_url_scheme(url)); thread::spawn(move || crate::ui::macos::handle_url_scheme(_url));
} }
#[cfg(target_os = "android")] #[cfg(target_os = "android")]
@ -1324,7 +1327,7 @@ pub mod server_side {
_class: JClass, _class: JClass,
) { ) {
log::debug!("startServer from java"); log::debug!("startServer from java");
std::thread::spawn(move || start_server(true)); thread::spawn(move || start_server(true));
} }
#[no_mangle] #[no_mangle]

View File

@ -193,8 +193,8 @@ pub mod client {
#[cfg(windows)] #[cfg(windows)]
pub fn update_grab_get_key_name() { pub fn update_grab_get_key_name() {
match get_keyboard_mode_enum() { match get_keyboard_mode_enum() {
KeyboardMode::Map => rdev::set_get_key_name(false), KeyboardMode::Map => rdev::set_get_key_unicode(false),
KeyboardMode::Translate => rdev::set_get_key_name(true), KeyboardMode::Translate => rdev::set_get_key_unicode(true),
_ => {} _ => {}
}; };
} }
@ -256,6 +256,7 @@ pub fn start_grab_loop() {
if let Err(error) = rdev::grab(func) { if let Err(error) = rdev::grab(func) {
log::error!("rdev Error: {:?}", error) log::error!("rdev Error: {:?}", error)
} }
rdev::set_event_popup(false);
}); });
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
@ -757,14 +758,12 @@ pub fn map_keyboard_mode(event: &Event, mut key_event: KeyEvent) -> Option<KeyEv
fn try_fill_unicode(event: &Event, key_event: &KeyEvent, events: &mut Vec<KeyEvent>) { fn try_fill_unicode(event: &Event, key_event: &KeyEvent, events: &mut Vec<KeyEvent>) {
match &event.unicode { match &event.unicode {
Some(unicode_info) => { Some(unicode_info) => {
if !unicode_info.is_dead {
for code in &unicode_info.unicode { for code in &unicode_info.unicode {
let mut evt = key_event.clone(); let mut evt = key_event.clone();
evt.set_unicode(*code as _); evt.set_unicode(*code as _);
events.push(evt); events.push(evt);
} }
} }
}
None => {} None => {}
} }
} }
@ -816,6 +815,12 @@ pub fn translate_virtual_keycode(event: &Event, mut key_event: KeyEvent) -> Opti
pub fn translate_keyboard_mode(event: &Event, key_event: KeyEvent) -> Vec<KeyEvent> { pub fn translate_keyboard_mode(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 unicode_info.is_dead {
return events;
}
}
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
unsafe { unsafe {
if event.scan_code == 0x021D { if event.scan_code == 0x021D {

View File

@ -368,8 +368,8 @@ impl<T: InvokeUiSession> Session<T> {
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
{ {
match &self.lc.read().unwrap().keyboard_mode as _ { match &self.lc.read().unwrap().keyboard_mode as _ {
"legacy" => rdev::set_get_key_name(true), "legacy" => rdev::set_get_key_unicode(true),
"translate" => rdev::set_get_key_name(true), "translate" => rdev::set_get_key_unicode(true),
_ => {} _ => {}
} }
} }
@ -381,7 +381,7 @@ impl<T: InvokeUiSession> Session<T> {
pub fn leave(&self) { pub fn leave(&self) {
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
{ {
rdev::set_get_key_name(false); rdev::set_get_key_unicode(false);
} }
IS_IN.store(false, Ordering::SeqCst); IS_IN.store(false, Ordering::SeqCst);
keyboard::client::change_grab_status(GrabState::Wait); keyboard::client::change_grab_status(GrabState::Wait);