Fix character generation, altgr only takes effect locally
This commit is contained in:
parent
8f04c1a780
commit
92c4ee1560
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -3795,7 +3795,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "rdev"
|
name = "rdev"
|
||||||
version = "0.5.0-2"
|
version = "0.5.0-2"
|
||||||
source = "git+https://github.com/asur4s/rdev#c3a896bcb4a10d171dee1aa685c90abadf8946d2"
|
source = "git+https://github.com/asur4s/rdev#d009906ba983f26c7b6f6f1a5e3c76bf43164294"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cocoa",
|
"cocoa",
|
||||||
"core-foundation 0.9.3",
|
"core-foundation 0.9.3",
|
||||||
|
@ -43,7 +43,7 @@ use hbb_common::{
|
|||||||
Stream,
|
Stream,
|
||||||
};
|
};
|
||||||
use hbb_common::{config::TransferSerde, fs::TransferJobMeta};
|
use hbb_common::{config::TransferSerde, fs::TransferJobMeta};
|
||||||
use rdev::{Event, EventType::*, Key as RdevKey};
|
use rdev::{Event, EventType::*, Key as RdevKey, Keyboard as RdevKeyboard, KeyboardState};
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
use crate::clipboard_file::*;
|
use crate::clipboard_file::*;
|
||||||
@ -58,6 +58,7 @@ lazy_static::lazy_static! {
|
|||||||
static ref ENIGO: Arc<Mutex<Enigo>> = Arc::new(Mutex::new(Enigo::new()));
|
static ref ENIGO: Arc<Mutex<Enigo>> = Arc::new(Mutex::new(Enigo::new()));
|
||||||
static ref VIDEO: Arc<Mutex<Option<Video>>> = Default::default();
|
static ref VIDEO: Arc<Mutex<Option<Video>>> = Default::default();
|
||||||
static ref TO_RELEASE: Arc<Mutex<HashSet<RdevKey>>> = Arc::new(Mutex::new(HashSet::<RdevKey>::new()));
|
static ref TO_RELEASE: Arc<Mutex<HashSet<RdevKey>>> = Arc::new(Mutex::new(HashSet::<RdevKey>::new()));
|
||||||
|
static ref KEYBOARD: Arc<Mutex<RdevKeyboard>> = Arc::new(Mutex::new(RdevKeyboard::new().unwrap()));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_key_state(key: enigo::Key) -> bool {
|
fn get_key_state(key: enigo::Key) -> bool {
|
||||||
@ -333,9 +334,6 @@ impl Handler {
|
|||||||
_ => return,
|
_ => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
let _key = rdev::get_win_key(evt.code.into(), evt.scan_code);
|
|
||||||
|
|
||||||
me.key_down_or_up(down, _key, evt);
|
me.key_down_or_up(down, _key, evt);
|
||||||
};
|
};
|
||||||
if let Err(error) = rdev::listen(func) {
|
if let Err(error) = rdev::listen(func) {
|
||||||
@ -785,7 +783,7 @@ impl Handler {
|
|||||||
|
|
||||||
fn leave(&mut self) {
|
fn leave(&mut self) {
|
||||||
for key in TO_RELEASE.lock().unwrap().iter() {
|
for key in TO_RELEASE.lock().unwrap().iter() {
|
||||||
self.map_keyboard_mode(false, *key)
|
self.map_keyboard_mode(false, *key, None)
|
||||||
}
|
}
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
crate::platform::windows::stop_system_key_propagate(false);
|
crate::platform::windows::stop_system_key_propagate(false);
|
||||||
@ -1036,8 +1034,15 @@ impl Handler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn map_keyboard_mode(&mut self, down_or_up: bool, key: RdevKey) {
|
fn map_keyboard_mode(&mut self, down_or_up: bool, key: RdevKey, evt: Option<Event>) {
|
||||||
// map mode(1): Send keycode according to the peer platform.
|
// map mode(1): Send keycode according to the peer platform.
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
let key = if let Some(e) = evt {
|
||||||
|
rdev::get_win_key(e.code.into(), e.scan_code)
|
||||||
|
} else {
|
||||||
|
key
|
||||||
|
};
|
||||||
|
|
||||||
let peer = self.peer_platform();
|
let peer = self.peer_platform();
|
||||||
|
|
||||||
let mut key_event = KeyEvent::new();
|
let mut key_event = KeyEvent::new();
|
||||||
@ -1067,8 +1072,20 @@ impl Handler {
|
|||||||
|
|
||||||
fn translate_keyboard_mode(&mut self, down_or_up: bool, key: RdevKey, evt: Event) {
|
fn translate_keyboard_mode(&mut self, down_or_up: bool, key: RdevKey, evt: Event) {
|
||||||
// translate mode(2): locally generated characters are send to the peer.
|
// translate mode(2): locally generated characters are send to the peer.
|
||||||
let string = evt.name.unwrap_or_default();
|
|
||||||
|
|
||||||
|
// get char
|
||||||
|
let string = match KEYBOARD.lock() {
|
||||||
|
Ok(mut keyboard) => {
|
||||||
|
let string = keyboard.add(&evt.event_type).unwrap_or_default();
|
||||||
|
if keyboard.last_is_dead && string == "" {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
string
|
||||||
|
}
|
||||||
|
Err(_) => "".to_owned(),
|
||||||
|
};
|
||||||
|
|
||||||
|
// maybe two string
|
||||||
let chars = if string == "" {
|
let chars = if string == "" {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
@ -1096,7 +1113,13 @@ impl Handler {
|
|||||||
} else {
|
} else {
|
||||||
TO_RELEASE.lock().unwrap().remove(&key);
|
TO_RELEASE.lock().unwrap().remove(&key);
|
||||||
}
|
}
|
||||||
self.map_keyboard_mode(down_or_up, key);
|
// algr without action
|
||||||
|
// Control left
|
||||||
|
if key == RdevKey::AltGr || evt.scan_code == 541 {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dbg!(key);
|
||||||
|
self.map_keyboard_mode(down_or_up, key, None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1369,7 +1392,7 @@ impl Handler {
|
|||||||
} else {
|
} else {
|
||||||
TO_RELEASE.lock().unwrap().remove(&key);
|
TO_RELEASE.lock().unwrap().remove(&key);
|
||||||
}
|
}
|
||||||
self.map_keyboard_mode(down_or_up, key);
|
self.map_keyboard_mode(down_or_up, key, Some(evt));
|
||||||
}
|
}
|
||||||
KeyboardMode::Legacy => self.legacy_keyboard_mode(down_or_up, key, evt),
|
KeyboardMode::Legacy => self.legacy_keyboard_mode(down_or_up, key, evt),
|
||||||
KeyboardMode::Translate => {
|
KeyboardMode::Translate => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user