Fix simulate in wayland

This commit is contained in:
asur4s 2022-09-02 15:29:25 -04:00
parent 15b8a5592d
commit bec8daafb9
4 changed files with 93 additions and 78 deletions

View File

@ -49,7 +49,7 @@ packages:
name: async
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.8.2"
version: "2.9.0"
back_button_interceptor:
dependency: "direct main"
description:
@ -147,7 +147,7 @@ packages:
name: characters
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.2.0"
version: "1.2.1"
charcode:
dependency: transitive
description:
@ -168,7 +168,7 @@ packages:
name: clock
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.0"
version: "1.1.1"
code_builder:
dependency: transitive
description:
@ -324,7 +324,7 @@ packages:
name: fake_async
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.3.0"
version: "1.3.1"
ffi:
dependency: "direct main"
description:
@ -621,14 +621,14 @@ packages:
name: matcher
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.12.11"
version: "0.12.12"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.1.4"
version: "0.1.5"
menu_base:
dependency: transitive
description:
@ -642,7 +642,7 @@ packages:
name: meta
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.7.0"
version: "1.8.0"
mime:
dependency: transitive
description:
@ -719,7 +719,7 @@ packages:
name: path
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.8.1"
version: "1.8.2"
path_provider:
dependency: "direct main"
description:
@ -856,9 +856,11 @@ packages:
screen_retriever:
dependency: transitive
description:
name: screen_retriever
url: "https://pub.flutter-io.cn"
source: hosted
path: "."
ref: "406b9b0"
resolved-ref: "406b9b038b2c1d779f1e7bf609c8c248be247372"
url: "https://github.com/Kingtous/rustdesk_screen_retriever.git"
source: git
version: "0.1.2"
scroll_pos:
dependency: "direct main"
@ -969,7 +971,7 @@ packages:
name: source_span
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.8.2"
version: "1.9.0"
sqflite:
dependency: transitive
description:
@ -1011,7 +1013,7 @@ packages:
name: string_scanner
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.0"
version: "1.1.1"
synchronized:
dependency: transitive
description:
@ -1025,14 +1027,14 @@ packages:
name: term_glyph
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.2.0"
version: "1.2.1"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.4.9"
version: "0.4.12"
timing:
dependency: transitive
description:
@ -1242,11 +1244,11 @@ packages:
dependency: "direct main"
description:
path: "."
ref: "799ef079e87938c3f4340591b4330c2598f38bb9"
resolved-ref: "799ef079e87938c3f4340591b4330c2598f38bb9"
ref: "4627ba808ed08ff0c08706b01a7f9cc8b747accd"
resolved-ref: "4627ba808ed08ff0c08706b01a7f9cc8b747accd"
url: "https://github.com/Kingtous/rustdesk_window_manager"
source: git
version: "0.2.6"
version: "0.2.7"
xdg_directories:
dependency: transitive
description:

View File

@ -58,7 +58,7 @@ dependencies:
window_manager:
git:
url: https://github.com/Kingtous/rustdesk_window_manager
ref: 799ef079e87938c3f4340591b4330c2598f38bb9
ref: 4627ba808ed08ff0c08706b01a7f9cc8b747accd
desktop_multi_window:
git:
url: https://github.com/Kingtous/rustdesk_desktop_multi_window

View File

@ -1,4 +1,9 @@
use crate::ResultType;
use std::sync::Mutex;
lazy_static::lazy_static! {
pub static ref IS_X11: Mutex<bool> = Mutex::new("x11" == get_display_server());
}
pub fn get_display_server() -> String {
let session = get_value_of_seat0(0);

View File

@ -2,6 +2,7 @@ use super::*;
#[cfg(target_os = "macos")]
use dispatch::Queue;
use enigo::{Enigo, Key, KeyboardControllable, MouseButton, MouseControllable};
use hbb_common::platform::linux::IS_X11;
use hbb_common::{config::COMPRESS_LEVEL, protobuf::EnumOrUnknown};
use rdev::{simulate, EventType, Key as RdevKey};
use std::{
@ -673,13 +674,13 @@ fn tfc_key_down_or_up(key: Key, down: bool, up: bool) {
if let Key::Layout(chr) = key {
log::info!("tfc_key_down_or_up :{:?}", chr);
if down {
if let Err(_) = TFC_CONTEXT.lock().unwrap().unicode_char_down(chr){
if let Err(_) = TFC_CONTEXT.lock().unwrap().unicode_char_down(chr) {
log::error!("Failed to press char {:?}", chr);
};
}
if up {
if let Err(_) = TFC_CONTEXT.lock().unwrap().unicode_char_down(chr){
log::error!("Failed to press char {:?}",chr);
if let Err(_) = TFC_CONTEXT.lock().unwrap().unicode_char_down(chr) {
log::error!("Failed to press char {:?}", chr);
};
}
return;
@ -753,12 +754,12 @@ fn tfc_key_down_or_up(key: Key, down: bool, up: bool) {
log::info!("tfc_key_down_or_up: {:?}", key);
if down {
if let Err(_) = TFC_CONTEXT.lock().unwrap().key_down(key){
if let Err(_) = TFC_CONTEXT.lock().unwrap().key_down(key) {
log::error!("Failed to press char {:?}", key);
};
}
if up {
if let Err(_) = TFC_CONTEXT.lock().unwrap().key_up(key){
if let Err(_) = TFC_CONTEXT.lock().unwrap().key_up(key) {
log::error!("Failed to press char {:?}", key);
};
}
@ -771,16 +772,18 @@ fn legacy_keyboard_mode(evt: &KeyEvent) {
crate::platform::windows::try_change_desktop();
let mut en = ENIGO.lock().unwrap();
if click_capslock {
#[cfg(target_os = "linux")]
tfc_key_down_or_up(Key::CapsLock, true, true);
#[cfg(not(target_os = "linux"))]
en.key_click(Key::CapsLock);
if *IS_X11.lock().unwrap() {
tfc_key_down_or_up(Key::CapsLock, true, true);
} else {
en.key_click(Key::CapsLock);
}
}
if click_numlock {
#[cfg(target_os = "linux")]
tfc_key_down_or_up(Key::NumLock, true, true);
#[cfg(not(target_os = "linux"))]
en.key_click(Key::NumLock);
if *IS_X11.lock().unwrap() {
tfc_key_down_or_up(Key::NumLock, true, true);
} else {
en.key_click(Key::NumLock);
}
}
// disable numlock if press home etc when numlock is on,
// because we will get numpad value (7,8,9 etc) if not
@ -834,10 +837,11 @@ fn legacy_keyboard_mode(evt: &KeyEvent) {
}
} else {
if !get_modifier_state(key.clone(), &mut en) {
#[cfg(target_os = "linux")]
tfc_key_down_or_up(key.clone(), true, false);
#[cfg(not(target_os = "linux"))]
en.key_down(key.clone()).ok();
if *IS_X11.lock().unwrap() {
tfc_key_down_or_up(key.clone(), true, false);
} else {
en.key_down(key.clone()).ok();
}
modifier_sleep();
to_release.push(key);
}
@ -848,12 +852,12 @@ fn legacy_keyboard_mode(evt: &KeyEvent) {
}
#[cfg(not(target_os = "macos"))]
if has_cap != en.get_key_state(Key::CapsLock) {
#[cfg(target_os = "linux")]
tfc_key_down_or_up(Key::CapsLock, true, true);
#[cfg(not(target_os = "linux"))]
en.key_down(Key::CapsLock).ok();
#[cfg(not(target_os = "linux"))]
en.key_up(Key::CapsLock);
if *IS_X11.lock().unwrap() {
tfc_key_down_or_up(Key::CapsLock, true, true);
} else {
en.key_down(Key::CapsLock).ok();
en.key_up(Key::CapsLock);
}
}
#[cfg(windows)]
if crate::common::valid_for_numlock(evt) {
@ -874,19 +878,21 @@ fn legacy_keyboard_mode(evt: &KeyEvent) {
}
}
if evt.down {
#[cfg(target_os = "linux")]
tfc_key_down_or_up(key.clone(), true, false);
#[cfg(not(target_os = "linux"))]
allow_err!(en.key_down(key.clone()));
if *IS_X11.lock().unwrap() {
tfc_key_down_or_up(key.clone(), true, false);
} else {
allow_err!(en.key_down(key.clone()));
}
KEYS_DOWN
.lock()
.unwrap()
.insert(ck.value() as _, Instant::now());
} else {
#[cfg(target_os = "linux")]
tfc_key_down_or_up(key.clone(), false, true);
#[cfg(not(target_os = "linux"))]
en.key_up(key.clone());
if *IS_X11.lock().unwrap() {
tfc_key_down_or_up(key.clone(), false, true);
} else {
en.key_up(key.clone());
}
KEYS_DOWN.lock().unwrap().remove(&(ck.value() as _));
}
} else if ck.value() == ControlKey::CtrlAltDel.value() {
@ -900,35 +906,36 @@ fn legacy_keyboard_mode(evt: &KeyEvent) {
}
Some(key_event::Union::Chr(chr)) => {
if evt.down {
#[cfg(target_os = "linux")]
tfc_key_down_or_up(get_layout(chr), true, false);
#[cfg(target_os = "linux")]
if *IS_X11.lock().unwrap() {
tfc_key_down_or_up(get_layout(chr), true, false);
} else {
if en.key_down(get_layout(chr)).is_ok() {
KEYS_DOWN
.lock()
.unwrap()
.insert(chr as u64 + KEY_CHAR_START, Instant::now());
} else {
if let Ok(chr) = char::try_from(chr) {
let mut x = chr.to_string();
if get_modifier_state(Key::Shift, &mut en)
|| get_modifier_state(Key::CapsLock, &mut en)
{
x = x.to_uppercase();
}
en.key_sequence(&x);
}
}
}
KEYS_DOWN
.lock()
.unwrap()
.insert(chr as u64 + KEY_CHAR_START, Instant::now());
#[cfg(not(target_os = "linux"))]
if en.key_down(get_layout(chr)).is_ok() {
KEYS_DOWN
.lock()
.unwrap()
.insert(chr as u64 + KEY_CHAR_START, Instant::now());
} else {
if let Ok(chr) = char::try_from(chr) {
let mut x = chr.to_string();
if get_modifier_state(Key::Shift, &mut en)
|| get_modifier_state(Key::CapsLock, &mut en)
{
x = x.to_uppercase();
}
en.key_sequence(&x);
}
}
} else {
#[cfg(target_os = "linux")]
tfc_key_down_or_up(get_layout(chr), false, true);
#[cfg(not(target_os = "linux"))]
en.key_up(get_layout(chr));
if *IS_X11.lock().unwrap() {
tfc_key_down_or_up(get_layout(chr), false, true);
} else {
en.key_up(get_layout(chr));
}
KEYS_DOWN
.lock()
.unwrap()
@ -947,10 +954,11 @@ fn legacy_keyboard_mode(evt: &KeyEvent) {
}
#[cfg(not(target_os = "macos"))]
for key in to_release {
#[cfg(target_os = "linux")]
tfc_key_down_or_up(key.clone(), false, true);
#[cfg(not(target_os = "linux"))]
en.key_up(key.clone());
if *IS_X11.lock().unwrap() {
tfc_key_down_or_up(key.clone(), false, true);
} else {
en.key_up(key.clone());
}
}
#[cfg(windows)]
if disable_numlock {