mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-01-22 18:13:00 +08:00
remove unused logic
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
d916c54029
commit
aa5debe986
126
src/keyboard.rs
126
src/keyboard.rs
@ -12,7 +12,7 @@ use std::{
|
|||||||
collections::{HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
sync::{
|
sync::{
|
||||||
atomic::{AtomicBool, Ordering},
|
atomic::{AtomicBool, Ordering},
|
||||||
mpsc, Arc, Mutex,
|
Arc, Mutex,
|
||||||
},
|
},
|
||||||
thread,
|
thread,
|
||||||
time::SystemTime,
|
time::SystemTime,
|
||||||
@ -21,10 +21,6 @@ use std::{
|
|||||||
static mut IS_ALT_GR: bool = false;
|
static mut IS_ALT_GR: bool = false;
|
||||||
static KEYBOARD_HOOKED: AtomicBool = AtomicBool::new(false);
|
static KEYBOARD_HOOKED: AtomicBool = AtomicBool::new(false);
|
||||||
|
|
||||||
lazy_static::lazy_static! {
|
|
||||||
static ref GRAB_SENDER: Arc<Mutex<Option<mpsc::Sender<GrabState>>>> = Default::default();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "flutter")]
|
#[cfg(feature = "flutter")]
|
||||||
lazy_static::lazy_static! {
|
lazy_static::lazy_static! {
|
||||||
static ref CUR_SESSION: Arc<Mutex<Option<Session<FlutterHandler>>>> = Default::default();
|
static ref CUR_SESSION: Arc<Mutex<Option<Session<FlutterHandler>>>> = Default::default();
|
||||||
@ -67,20 +63,32 @@ pub mod client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn start_grab_loop() {
|
pub fn start_grab_loop() {
|
||||||
let (sender, receiver) = mpsc::channel::<GrabState>();
|
thread::spawn(grab_loop);
|
||||||
|
|
||||||
grab_loop(receiver);
|
|
||||||
*GRAB_SENDER.lock().unwrap() = Some(sender);
|
|
||||||
|
|
||||||
change_grab_status(GrabState::Ready);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn change_grab_status(state: GrabState) {
|
pub fn change_grab_status(state: GrabState) {
|
||||||
if GrabState::Wait == state {
|
match state {
|
||||||
release_remote_keys();
|
GrabState::Ready => {}
|
||||||
}
|
GrabState::Run => {
|
||||||
if let Some(sender) = &*GRAB_SENDER.lock().unwrap() {
|
#[cfg(any(target_os = "windows", target_os = "macos"))]
|
||||||
sender.send(state).ok();
|
KEYBOARD_HOOKED.swap(true, Ordering::SeqCst);
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
rdev::enable_grab().ok();
|
||||||
|
}
|
||||||
|
GrabState::Wait => {
|
||||||
|
release_remote_keys();
|
||||||
|
|
||||||
|
#[cfg(any(target_os = "windows", target_os = "macos"))]
|
||||||
|
KEYBOARD_HOOKED.swap(false, Ordering::SeqCst);
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
rdev::disable_grab().ok();
|
||||||
|
}
|
||||||
|
GrabState::Exit => {
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
rdev::exit_grab_listen().ok();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,67 +179,41 @@ pub mod client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn grab_loop(recv: mpsc::Receiver<GrabState>) {
|
pub fn grab_loop() {
|
||||||
thread::spawn(move || loop {
|
#[cfg(any(target_os = "windows", target_os = "macos"))]
|
||||||
if let Some(state) = recv.recv().ok() {
|
std::thread::spawn(move || {
|
||||||
match state {
|
let func = move |event: Event| match event.event_type {
|
||||||
GrabState::Ready => {
|
EventType::KeyPress(key) | EventType::KeyRelease(key) => {
|
||||||
#[cfg(any(target_os = "windows", target_os = "macos"))]
|
// fix #2211:CAPS LOCK don't work
|
||||||
std::thread::spawn(move || {
|
if key == Key::CapsLock || key == Key::NumLock {
|
||||||
let func = move |event: Event| match event.event_type {
|
return Some(event);
|
||||||
EventType::KeyPress(key) | EventType::KeyRelease(key) => {
|
|
||||||
// fix #2211:CAPS LOCK don't work
|
|
||||||
if key == Key::CapsLock || key == Key::NumLock {
|
|
||||||
return Some(event);
|
|
||||||
}
|
|
||||||
if KEYBOARD_HOOKED.load(Ordering::SeqCst) {
|
|
||||||
client::process_event(event);
|
|
||||||
return None;
|
|
||||||
} else {
|
|
||||||
return Some(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => Some(event),
|
|
||||||
};
|
|
||||||
if let Err(error) = rdev::grab(func) {
|
|
||||||
log::error!("rdev Error: {:?}", error)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
|
||||||
rdev::start_grab_listen(move |event: Event| match event.event_type {
|
|
||||||
EventType::KeyPress(key) | EventType::KeyRelease(key) => {
|
|
||||||
if let Key::Unknown(keycode) = key {
|
|
||||||
log::error!("rdev get unknown key, keycode is : {:?}", keycode);
|
|
||||||
} else {
|
|
||||||
client::process_event(event);
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
|
||||||
_ => Some(event),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
GrabState::Run => {
|
if KEYBOARD_HOOKED.load(Ordering::SeqCst) {
|
||||||
#[cfg(any(target_os = "windows", target_os = "macos"))]
|
client::process_event(event);
|
||||||
KEYBOARD_HOOKED.swap(true, Ordering::SeqCst);
|
return None;
|
||||||
|
} else {
|
||||||
#[cfg(target_os = "linux")]
|
return Some(event);
|
||||||
rdev::enable_grab().ok();
|
|
||||||
}
|
|
||||||
GrabState::Wait => {
|
|
||||||
#[cfg(any(target_os = "windows", target_os = "macos"))]
|
|
||||||
KEYBOARD_HOOKED.swap(false, Ordering::SeqCst);
|
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
|
||||||
rdev::disable_grab().ok();
|
|
||||||
}
|
|
||||||
GrabState::Exit => {
|
|
||||||
#[cfg(target_os = "linux")]
|
|
||||||
rdev::exit_grab_listen().ok();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_ => Some(event),
|
||||||
|
};
|
||||||
|
if let Err(error) = rdev::grab(func) {
|
||||||
|
log::error!("rdev Error: {:?}", error)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
rdev::start_grab_listen(move |event: Event| match event.event_type {
|
||||||
|
EventType::KeyPress(key) | EventType::KeyRelease(key) => {
|
||||||
|
if let Key::Unknown(keycode) = key {
|
||||||
|
log::error!("rdev get unknown key, keycode is : {:?}", keycode);
|
||||||
|
} else {
|
||||||
|
client::process_event(event);
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
_ => Some(event),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_long_press(event: &Event) -> bool {
|
pub fn is_long_press(event: &Event) -> bool {
|
||||||
|
Loading…
Reference in New Issue
Block a user