fix conflict

This commit is contained in:
Chieh Wang
2022-12-08 18:51:20 +08:00
committed by Asura
Unverified
parent 95775678ca
commit 49bcf8f794
6 changed files with 114 additions and 84 deletions

View File

@@ -285,7 +285,7 @@ pub fn session_handle_flutter_key_event(
down_or_up: bool,
) {
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
// session.handle_flutter_key_event(&name, keycode, scancode, down_or_up);
session.handle_flutter_key_event(&name, keycode, scancode, down_or_up);
}
}

View File

@@ -1,7 +1,10 @@
#[cfg(not(any(target_os = "android", target_os = "ios")))]
use crate::client::get_key_state;
use crate::common::GrabState;
#[cfg(feature = "flutter")]
use crate::flutter::FlutterHandler;
#[cfg(not(feature = "flutter"))]
use crate::ui::remote::SciterHandler;
use crate::ui_session_interface::Session;
use hbb_common::{log, message_proto::*};
use rdev::{Event, EventType, Key};
@@ -16,10 +19,18 @@ use std::time::SystemTime;
static mut IS_ALT_GR: bool = false;
pub static KEYBOARD_HOOKED: AtomicBool = AtomicBool::new(false);
lazy_static::lazy_static! {
pub static ref GRAB_SENDER: Arc<Mutex<Option<mpsc::Sender<GrabState>>>> = Default::default();
}
#[cfg(feature = "flutter")]
lazy_static::lazy_static! {
pub static ref CUR_SESSION: Arc<Mutex<Option<Session<FlutterHandler>>>> = Default::default();
pub static ref GRAB_SENDER: Arc<Mutex<Option<mpsc::Sender<GrabState>>>> = Default::default();
}
#[cfg(not(feature = "flutter"))]
lazy_static::lazy_static! {
pub static ref CUR_SESSION: Arc<Mutex<Option<Session<SciterHandler>>>> = Default::default();
}
lazy_static::lazy_static! {
@@ -50,19 +61,12 @@ pub mod client {
}
}
pub fn save_keyboard_mode(value: String) {
release_remote_keys();
if let Some(handler) = CUR_SESSION.lock().unwrap().as_mut() {
handler.save_keyboard_mode(value);
}
}
pub fn start_grab_loop() {
let (sender, receiver) = mpsc::channel::<GrabState>();
unsafe {
grab_loop(receiver);
*GRAB_SENDER.lock().unwrap() = Some(sender);
}
grab_loop(receiver);
*GRAB_SENDER.lock().unwrap() = Some(sender);
change_grab_status(GrabState::Ready);
}
@@ -70,11 +74,8 @@ pub mod client {
if GrabState::Wait == state {
release_remote_keys();
}
unsafe {
if let Some(sender) = &*GRAB_SENDER.lock().unwrap() {
log::info!("grab state: {:?}", state);
sender.send(state);
}
if let Some(sender) = &*GRAB_SENDER.lock().unwrap() {
sender.send(state).ok();
}
}
@@ -83,7 +84,6 @@ pub mod client {
return;
}
let key_event = event_to_key_event(&event);
log::info!("key event: {:?}", key_event);
send_key_event(&key_event);
}
@@ -103,9 +103,10 @@ pub mod client {
let command = *modifiers_lock.get(&Key::MetaLeft).unwrap()
|| *modifiers_lock.get(&Key::MetaRight).unwrap()
|| command;
let alt =
*modifiers_lock.get(&Key::Alt).unwrap() || *modifiers_lock.get(&Key::AltGr).unwrap() || alt;
let alt = *modifiers_lock.get(&Key::Alt).unwrap()
|| *modifiers_lock.get(&Key::AltGr).unwrap()
|| alt;
(alt, ctrl, shift, command)
}
@@ -229,7 +230,7 @@ pub fn grab_loop(recv: mpsc::Receiver<GrabState>) {
}
pub fn is_long_press(event: &Event) -> bool {
let mut keys = MODIFIERS_STATE.lock().unwrap();
let keys = MODIFIERS_STATE.lock().unwrap();
match event.event_type {
EventType::KeyPress(k) => {
if let Some(&state) = keys.get(&k) {
@@ -251,12 +252,11 @@ pub fn release_remote_keys() {
for key in keys {
let event_type = EventType::KeyRelease(key);
let event = event_type_to_event(event_type);
log::info!("release key: {:?}", key);
client::process_event(event);
}
}
pub fn get_keyboard_mode_enum() -> KeyboardMode {
pub fn get_keyboard_mode_enum() -> KeyboardMode {
match client::get_keyboard_mode().as_str() {
"map" => KeyboardMode::Map,
"translate" => KeyboardMode::Translate,
@@ -264,6 +264,7 @@ pub fn get_keyboard_mode_enum() -> KeyboardMode {
}
}
#[cfg(not(any(target_os = "android", target_os = "ios")))]
pub fn add_numlock_capslock_state(key_event: &mut KeyEvent) {
if get_key_state(enigo::Key::CapsLock) {
key_event.modifiers.push(ControlKey::CapsLock.into());
@@ -273,6 +274,7 @@ pub fn add_numlock_capslock_state(key_event: &mut KeyEvent) {
}
}
#[cfg(not(any(target_os = "android", target_os = "ios")))]
pub fn convert_numpad_keys(key: Key) -> Key {
if get_key_state(enigo::Key::NumLock) {
return key;
@@ -337,6 +339,7 @@ pub fn event_to_key_event(event: &Event) -> KeyEvent {
translate_keyboard_mode(event, &mut key_event);
}
_ => {
#[cfg(not(any(target_os = "android", target_os = "ios")))]
legacy_keyboard_mode(event, &mut key_event);
}
};
@@ -356,10 +359,8 @@ pub fn event_type_to_event(event_type: EventType) -> Event {
}
}
#[cfg(feature = "flutter")]
pub fn send_key_event(key_event: &KeyEvent) {
if let Some(handler) = CUR_SESSION.lock().unwrap().as_ref() {
log::info!("Sending key even {:?}", key_event);
handler.send_key_event(key_event);
}
}
@@ -373,6 +374,7 @@ pub fn get_peer_platform() -> String {
}
}
#[cfg(not(any(target_os = "android", target_os = "ios")))]
pub fn legacy_keyboard_mode(event: &Event, key_event: &mut KeyEvent) {
// legacy mode(0): Generate characters locally, look for keycode on other side.
let (mut key, down_or_up) = match event.event_type {
@@ -616,4 +618,4 @@ pub fn map_keyboard_mode(event: &Event, key_event: &mut KeyEvent) {
key_event.set_chr(keycode);
}
pub fn translate_keyboard_mode(event: &Event, key_event: &mut KeyEvent) {}
pub fn translate_keyboard_mode(_event: &Event, _key_event: &mut KeyEvent) {}

View File

@@ -764,11 +764,6 @@ fn rdev_key_down_or_up(key: RdevKey, down_or_up: bool) {
std::thread::sleep(Duration::from_millis(20));
}
fn rdev_key_click(key: RdevKey) {
rdev_key_down_or_up(key, true);
rdev_key_down_or_up(key, false);
}
fn sync_status(evt: &KeyEvent) {
let mut en = ENIGO.lock().unwrap();

View File

@@ -4,8 +4,7 @@ use crate::client::{
load_config, send_mouse, start_video_audio_threads, FileManager, Key, LoginConfigHandler,
QualityStatus, KEY_MAP,
};
#[cfg(target_os = "linux")]
use crate::common::IS_X11;
use crate::common::GrabState;
use crate::{client::Data, client::Interface};
use async_trait::async_trait;
use hbb_common::config::{Config, LocalConfig, PeerConfig};
@@ -17,7 +16,8 @@ use std::collections::HashMap;
use std::ops::{Deref, DerefMut};
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use std::sync::{Arc, Mutex, RwLock};
use crate::keyboard;
use rdev::{Event, EventType::*};
pub static IS_IN: AtomicBool = AtomicBool::new(false);
#[derive(Clone, Default)]
@@ -292,7 +292,7 @@ impl<T: InvokeUiSession> Session<T> {
return "".to_owned();
}
pub fn send_key_event(&self, mut evt: &KeyEvent) {
pub fn send_key_event(&self, evt: &KeyEvent) {
// mode: legacy(0), map(1), translate(2), auto(3)
let mut msg_out = Message::new();
msg_out.set_key_event(evt.clone());
@@ -362,6 +362,40 @@ impl<T: InvokeUiSession> Session<T> {
self.send(Data::Message(msg_out));
}
pub fn handle_flutter_key_event(
&self,
name: &str,
keycode: i32,
scancode: i32,
down_or_up: bool,
) {
if scancode < 0 || keycode < 0 {
return;
}
let keycode: u32 = keycode as u32;
let scancode: u32 = scancode as u32;
#[cfg(not(target_os = "windows"))]
let key = rdev::key_from_scancode(scancode) as rdev::Key;
// Windows requires special handling
#[cfg(target_os = "windows")]
let key = rdev::get_win_key(keycode, scancode);
let event_type = if down_or_up {
KeyPress(key)
} else {
KeyRelease(key)
};
let event = Event {
time: std::time::SystemTime::now(),
name: Option::Some(name.to_owned()),
code: keycode as _,
scan_code: scancode as _,
event_type: event_type,
};
keyboard::client::process_event(event);
}
// flutter only TODO new input
fn _input_key(
&self,
@@ -423,7 +457,6 @@ impl<T: InvokeUiSession> Session<T> {
}
}
// todo! chieh
// #[cfg(not(any(target_os = "android", target_os = "ios")))]
let (alt, ctrl, shift, command) =
keyboard::client::get_modifiers_state(alt, ctrl, shift, command);