Merge pull request #2785 from fufesou/fix/wayland_keyboard_flutter

fix wayland input
This commit is contained in:
RustDesk
2023-01-10 15:20:19 +08:00
committed by GitHub
10 changed files with 74 additions and 20 deletions

View File

@@ -51,7 +51,7 @@ lazy_static::lazy_static! {
pub fn global_init() -> bool {
#[cfg(target_os = "linux")]
{
if !scrap::is_x11() {
if !*IS_X11 {
crate::server::wayland::set_wayland_scrap_map_err();
}
}
@@ -660,13 +660,13 @@ pub fn make_privacy_mode_msg(state: back_notification::PrivacyModeState) -> Mess
#[cfg(not(target_os = "linux"))]
lazy_static::lazy_static! {
pub static ref IS_X11: Mutex<bool> = Mutex::new(false);
pub static ref IS_X11: bool = false;
}
#[cfg(target_os = "linux")]
lazy_static::lazy_static! {
pub static ref IS_X11: Mutex<bool> = Mutex::new("x11" == hbb_common::platform::linux::get_display_server());
pub static ref IS_X11: bool = "x11" == hbb_common::platform::linux::get_display_server();
}
pub fn make_fd_to_json(id: i32, path: String, entries: &Vec<FileEntry>) -> String {

View File

@@ -289,10 +289,11 @@ pub fn session_handle_flutter_key_event(
name: String,
keycode: i32,
scancode: i32,
lock_modes: i32,
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, lock_modes, down_or_up);
}
}
@@ -1093,8 +1094,13 @@ pub fn main_is_installed() -> SyncReturn<bool> {
SyncReturn(is_installed())
}
pub fn main_start_grab_keyboard() {
pub fn main_start_grab_keyboard() -> SyncReturn<bool> {
#[cfg(target_os = "linux")]
if !*crate::common::IS_X11 {
return SyncReturn(false);
}
crate::keyboard::client::start_grab_loop();
SyncReturn(true)
}
pub fn main_is_installed_lower_version() -> SyncReturn<bool> {

View File

@@ -99,11 +99,11 @@ pub mod client {
}
}
pub fn process_event(event: &Event) {
pub fn process_event(event: &Event, lock_modes: Option<i32>) {
if is_long_press(&event) {
return;
}
if let Some(key_event) = event_to_key_event(&event) {
if let Some(key_event) = event_to_key_event(&event, lock_modes) {
send_key_event(&key_event);
}
}
@@ -196,7 +196,7 @@ pub fn start_grab_loop() {
return Some(event);
}
if KEYBOARD_HOOKED.load(Ordering::SeqCst) {
client::process_event(&event);
client::process_event(&event, None);
if is_press {
return None;
} else {
@@ -222,7 +222,7 @@ pub fn start_grab_loop() {
if let Key::Unknown(keycode) = key {
log::error!("rdev get unknown key, keycode is : {:?}", keycode);
} else {
client::process_event(&event);
client::process_event(&event, None);
}
None
}
@@ -254,7 +254,7 @@ pub fn release_remote_keys() {
for key in to_release {
let event_type = EventType::KeyRelease(key);
let event = event_type_to_event(event_type);
client::process_event(&event);
client::process_event(&event, None);
}
}
@@ -267,7 +267,23 @@ pub fn get_keyboard_mode_enum() -> KeyboardMode {
}
#[cfg(not(any(target_os = "android", target_os = "ios")))]
pub fn add_numlock_capslock_status(key_event: &mut KeyEvent) {
fn add_numlock_capslock_with_lock_modes(key_event: &mut KeyEvent, lock_modes: i32) {
const CAPS_LOCK: i32 = 1;
const NUM_LOCK: i32 = 2;
// const SCROLL_LOCK: i32 = 3;
if lock_modes & (1 << CAPS_LOCK) != 0 {
key_event.modifiers.push(ControlKey::CapsLock.into());
}
if lock_modes & (1 << NUM_LOCK) != 0 {
key_event.modifiers.push(ControlKey::NumLock.into());
}
// if lock_modes & (1 << SCROLL_LOCK) != 0 {
// key_event.modifiers.push(ControlKey::ScrollLock.into());
// }
}
#[cfg(not(any(target_os = "android", target_os = "ios")))]
fn add_numlock_capslock_status(key_event: &mut KeyEvent) {
if get_key_state(enigo::Key::CapsLock) {
key_event.modifiers.push(ControlKey::CapsLock.into());
}
@@ -315,7 +331,7 @@ fn update_modifiers_state(event: &Event) {
};
}
pub fn event_to_key_event(event: &Event) -> Option<KeyEvent> {
pub fn event_to_key_event(event: &Event, lock_modes: Option<i32>) -> Option<KeyEvent> {
let mut key_event = KeyEvent::new();
update_modifiers_state(event);
@@ -346,7 +362,11 @@ pub fn event_to_key_event(event: &Event) -> Option<KeyEvent> {
}
};
#[cfg(not(any(target_os = "android", target_os = "ios")))]
add_numlock_capslock_status(&mut key_event);
if let Some(lock_modes) = lock_modes {
add_numlock_capslock_with_lock_modes(&mut key_event, lock_modes);
} else {
add_numlock_capslock_status(&mut key_event);
}
return Some(key_event);
}

View File

@@ -882,7 +882,7 @@ fn map_keyboard_mode(evt: &KeyEvent) {
// Wayland
#[cfg(target_os = "linux")]
if !*IS_X11.lock().unwrap() {
if !*IS_X11 {
let mut en = ENIGO.lock().unwrap();
let code = evt.chr() as u16;

View File

@@ -394,6 +394,7 @@ impl<T: InvokeUiSession> Session<T> {
name: &str,
keycode: i32,
scancode: i32,
lock_modes: i32,
down_or_up: bool,
) {
if scancode < 0 || keycode < 0 {
@@ -420,7 +421,7 @@ impl<T: InvokeUiSession> Session<T> {
scan_code: scancode as _,
event_type: event_type,
};
keyboard::client::process_event(&event);
keyboard::client::process_event(&event, Some(lock_modes));
}
// flutter only TODO new input