refactor grab hot key
add compile condition
This commit is contained in:
parent
f2a5b77d7a
commit
2252d6345a
26
Cargo.lock
generated
26
Cargo.lock
generated
@ -1579,29 +1579,6 @@ dependencies = [
|
|||||||
"nix 0.23.1",
|
"nix 0.23.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "evdev-rs"
|
|
||||||
version = "0.6.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "46504075975d14f0463e5a41efa06820c94d4c04fecd01f70b95365d60de1caf"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags",
|
|
||||||
"evdev-sys",
|
|
||||||
"libc",
|
|
||||||
"log",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "evdev-sys"
|
|
||||||
version = "0.2.5"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "14ead42b547b15d47089c1243d907bcf0eb94e457046d3b315a26ac9c9e9ea6d"
|
|
||||||
dependencies = [
|
|
||||||
"cc",
|
|
||||||
"libc",
|
|
||||||
"pkg-config",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "event-listener"
|
name = "event-listener"
|
||||||
version = "2.5.3"
|
version = "2.5.3"
|
||||||
@ -4126,7 +4103,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#22c8a6474065f03ecbddef7f47de0539ff3f5c4f"
|
source = "git+https://github.com/asur4s/rdev#ea223720532f32652dab803db43f9ce437f2b019"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cocoa",
|
"cocoa",
|
||||||
"core-foundation 0.9.3",
|
"core-foundation 0.9.3",
|
||||||
@ -4134,7 +4111,6 @@ dependencies = [
|
|||||||
"core-graphics 0.22.3",
|
"core-graphics 0.22.3",
|
||||||
"enum-map",
|
"enum-map",
|
||||||
"epoll",
|
"epoll",
|
||||||
"evdev-rs",
|
|
||||||
"inotify",
|
"inotify",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"libc",
|
"libc",
|
||||||
|
@ -6,6 +6,7 @@ use crate::client::{
|
|||||||
load_config, send_mouse, start_video_audio_threads, FileManager, Key, LoginConfigHandler,
|
load_config, send_mouse, start_video_audio_threads, FileManager, Key, LoginConfigHandler,
|
||||||
QualityStatus, KEY_MAP, SERVER_KEYBOARD_ENABLED,
|
QualityStatus, KEY_MAP, SERVER_KEYBOARD_ENABLED,
|
||||||
};
|
};
|
||||||
|
use crate::common::IS_X11;
|
||||||
use crate::{client::Data, client::Interface};
|
use crate::{client::Data, client::Interface};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use hbb_common::config::{Config, LocalConfig, PeerConfig};
|
use hbb_common::config::{Config, LocalConfig, PeerConfig};
|
||||||
@ -909,14 +910,7 @@ impl<T: InvokeUiSession> Session<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
let ctrl =
|
let (alt, ctrl, shift, command) = get_all_hotkey_state(alt, ctrl, shift, command);
|
||||||
get_hotkey_state(RdevKey::ControlLeft) || get_hotkey_state(RdevKey::ControlRight);
|
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
|
||||||
let shift = get_hotkey_state(RdevKey::ShiftLeft) || get_hotkey_state(RdevKey::ShiftRight);
|
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
|
||||||
let command = get_hotkey_state(RdevKey::MetaLeft) || get_hotkey_state(RdevKey::MetaRight);
|
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
|
||||||
let alt = get_hotkey_state(RdevKey::Alt) || get_hotkey_state(RdevKey::AltGr);
|
|
||||||
|
|
||||||
self.legacy_modifiers(&mut key_event, alt, ctrl, shift, command);
|
self.legacy_modifiers(&mut key_event, alt, ctrl, shift, command);
|
||||||
if v == 1 {
|
if v == 1 {
|
||||||
@ -948,14 +942,7 @@ impl<T: InvokeUiSession> Session<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
let ctrl =
|
let (alt, ctrl, shift, command) = get_all_hotkey_state(alt, ctrl, shift, command);
|
||||||
get_hotkey_state(RdevKey::ControlLeft) || get_hotkey_state(RdevKey::ControlRight);
|
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
|
||||||
let shift = get_hotkey_state(RdevKey::ShiftLeft) || get_hotkey_state(RdevKey::ShiftRight);
|
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
|
||||||
let command = get_hotkey_state(RdevKey::MetaLeft) || get_hotkey_state(RdevKey::MetaRight);
|
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
|
||||||
let alt = get_hotkey_state(RdevKey::Alt) || get_hotkey_state(RdevKey::AltGr);
|
|
||||||
|
|
||||||
send_mouse(mask, x, y, alt, ctrl, shift, command, self);
|
send_mouse(mask, x, y, alt, ctrl, shift, command, self);
|
||||||
// on macos, ctrl + left button down = right button down, up won't emit, so we need to
|
// on macos, ctrl + left button down = right button down, up won't emit, so we need to
|
||||||
@ -1206,7 +1193,7 @@ impl<T: InvokeUiSession> Interface for Session<T> {
|
|||||||
crate::platform::windows::add_recent_document(&path);
|
crate::platform::windows::add_recent_document(&path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// rdev::grab and rdev::listen use the same api on macOS
|
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
self.start_keyboard_hook();
|
self.start_keyboard_hook();
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
@ -1253,10 +1240,6 @@ impl<T: InvokeUiSession> Interface for Session<T> {
|
|||||||
|
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
impl<T: InvokeUiSession> Session<T> {
|
impl<T: InvokeUiSession> Session<T> {
|
||||||
fn send_hotkey(&self, key: RdevKey, is_press: bool) {
|
|
||||||
log::info!("{:?} {:?}", key, is_press);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn handle_hot_key_event(&self, event: Event) {
|
fn handle_hot_key_event(&self, event: Event) {
|
||||||
// keyboard long press
|
// keyboard long press
|
||||||
match event.event_type {
|
match event.event_type {
|
||||||
@ -1279,11 +1262,9 @@ impl<T: InvokeUiSession> Session<T> {
|
|||||||
// keyboard short press
|
// keyboard short press
|
||||||
match event.event_type {
|
match event.event_type {
|
||||||
EventType::KeyPress(key) => {
|
EventType::KeyPress(key) => {
|
||||||
self.send_hotkey(key, true);
|
|
||||||
self.key_down_or_up(true, key, event);
|
self.key_down_or_up(true, key, event);
|
||||||
}
|
}
|
||||||
EventType::KeyRelease(key) => {
|
EventType::KeyRelease(key) => {
|
||||||
self.send_hotkey(key, false);
|
|
||||||
self.key_down_or_up(false, key, event);
|
self.key_down_or_up(false, key, event);
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
@ -1291,6 +1272,10 @@ impl<T: InvokeUiSession> Session<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn start_hotkey_grab(&self) {
|
fn start_hotkey_grab(&self) {
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
if !*IS_X11.lock().unwrap() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if self.is_port_forward() || self.is_file_transfer() {
|
if self.is_port_forward() || self.is_file_transfer() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1306,11 +1291,13 @@ impl<T: InvokeUiSession> Session<T> {
|
|||||||
return Some(event);
|
return Some(event);
|
||||||
};
|
};
|
||||||
match event.event_type {
|
match event.event_type {
|
||||||
EventType::KeyPress(key) | EventType::KeyRelease(key) => {
|
EventType::KeyPress(_key) | EventType::KeyRelease(_key) => {
|
||||||
#[cfg(any(target_os = "windows", target_os = "macos"))]
|
#[cfg(any(target_os = "windows", target_os = "macos"))]
|
||||||
if MUTEX_SPECIAL_KEYS.lock().unwrap().contains_key(&key) {
|
if MUTEX_SPECIAL_KEYS.lock().unwrap().contains_key(&_key) {
|
||||||
me.handle_hot_key_event(event);
|
me.handle_hot_key_event(event);
|
||||||
return None;
|
return None;
|
||||||
|
} else {
|
||||||
|
return Some(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
@ -1549,6 +1536,23 @@ fn get_hotkey_state(key: RdevKey) -> bool {
|
|||||||
*MUTEX_SPECIAL_KEYS.lock().unwrap().get(&key).unwrap()
|
*MUTEX_SPECIAL_KEYS.lock().unwrap().get(&key).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_all_hotkey_state(
|
||||||
|
alt: bool,
|
||||||
|
ctrl: bool,
|
||||||
|
shift: bool,
|
||||||
|
command: bool,
|
||||||
|
) -> (bool, bool, bool, bool) {
|
||||||
|
let ctrl =
|
||||||
|
get_hotkey_state(RdevKey::ControlLeft) || get_hotkey_state(RdevKey::ControlRight) || ctrl;
|
||||||
|
let shift =
|
||||||
|
get_hotkey_state(RdevKey::ShiftLeft) || get_hotkey_state(RdevKey::ShiftRight) || shift;
|
||||||
|
let command =
|
||||||
|
get_hotkey_state(RdevKey::MetaLeft) || get_hotkey_state(RdevKey::MetaRight) || command;
|
||||||
|
let alt = get_hotkey_state(RdevKey::Alt) || get_hotkey_state(RdevKey::AltGr) || alt;
|
||||||
|
|
||||||
|
(alt, ctrl, shift, command)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn global_get_keyboard_mode() -> String {
|
pub fn global_get_keyboard_mode() -> String {
|
||||||
return std::env::var("KEYBOARD_MODE")
|
return std::env::var("KEYBOARD_MODE")
|
||||||
.unwrap_or(String::from("map"))
|
.unwrap_or(String::from("map"))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user