Merge pull request #3719 from chiehw/win-linux

translate mode: support linux in server
This commit is contained in:
RustDesk
2023-03-20 15:55:24 +08:00
committed by GitHub
10 changed files with 167 additions and 14 deletions

View File

@@ -1,5 +1,5 @@
use super::xdo::EnigoXdo;
use crate::{Key, KeyboardControllable, MouseButton, MouseControllable};
use crate::{Key, KeyboardControllable, MouseButton, MouseControllable, ResultType};
use std::io::Read;
use tfc::{traits::*, Context as TFC_Context, Key as TFC_Key};
@@ -42,6 +42,37 @@ impl Enigo {
&mut self.custom_mouse
}
/// Clear remapped keycodes
pub fn tfc_clear_remapped(&mut self) {
if let Some(tfc) = &mut self.tfc {
tfc.recover_remapped_keycodes();
}
}
fn tfc_key_click(&mut self, key: Key) -> ResultType {
if let Some(tfc) = &mut self.tfc {
let res = match key {
Key::Layout(chr) => tfc.unicode_char(chr),
key => {
let tfc_key: TFC_Key = match convert_to_tfc_key(key) {
Some(key) => key,
None => {
return Err(format!("Failed to convert {:?} to TFC_Key", key).into());
}
};
tfc.key_click(tfc_key)
}
};
if res.is_err() {
Err(format!("Failed to click {:?} by tfc", key).into())
} else {
Ok(())
}
} else {
Err("Not Found TFC".into())
}
}
fn tfc_key_down_or_up(&mut self, key: Key, down: bool, up: bool) -> bool {
match &mut self.tfc {
None => false,
@@ -223,6 +254,7 @@ impl KeyboardControllable for Enigo {
}
}
/// Warning: Get 6^ in French.
fn key_sequence(&mut self, sequence: &str) {
if self.is_x11 {
self.xdo.key_sequence(sequence)
@@ -262,8 +294,10 @@ impl KeyboardControllable for Enigo {
}
}
fn key_click(&mut self, key: Key) {
self.key_down(key).ok();
self.key_up(key);
if self.tfc_key_click(key).is_err() {
self.key_down(key).ok();
self.key_up(key);
}
}
}
@@ -335,3 +369,10 @@ fn convert_to_tfc_key(key: Key) -> Option<TFC_Key> {
};
Some(key)
}
#[test]
fn test_key_seq() {
// Get 6^ in French.
let mut en = Enigo::new();
en.key_sequence("^^");
}

View File

@@ -7,6 +7,8 @@ pub mod macos;
use crate::{config::Config, log};
use std::process::exit;
static mut GLOBAL_CALLBACK: Option<Box<dyn Fn()>> = None;
extern "C" fn breakdown_signal_handler(sig: i32) {
let mut stack = vec![];
backtrace::trace(|frame| {
@@ -41,11 +43,20 @@ extern "C" fn breakdown_signal_handler(sig: i32) {
)
.ok();
}
unsafe {
if let Some(callback) = &GLOBAL_CALLBACK {
callback()
}
}
exit(0);
}
pub fn register_breakdown_handler() {
pub fn register_breakdown_handler<T>(callback: T)
where
T: Fn() + 'static,
{
unsafe {
GLOBAL_CALLBACK = Some(Box::new(callback));
libc::signal(libc::SIGSEGV, breakdown_signal_handler as _);
}
}