mirror of
https://github.com/weyne85/rustdesk.git
synced 2025-10-29 17:00:05 +00:00
Fix wayland input after Lock and Wake
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
@@ -118,6 +118,13 @@ pub enum MouseButton {
|
||||
/// Representing an interface and a set of mouse functions every
|
||||
/// operating system implementation _should_ implement.
|
||||
pub trait MouseControllable {
|
||||
// https://stackoverflow.com/a/33687996
|
||||
/// Offer the ability to confer concrete type.
|
||||
fn as_any(&self) -> &dyn std::any::Any;
|
||||
|
||||
/// Offer the ability to confer concrete type.
|
||||
fn as_mut_any(&mut self) -> &mut dyn std::any::Any;
|
||||
|
||||
/// Lets the mouse cursor move to the specified x and y coordinates.
|
||||
///
|
||||
/// The topleft corner of your monitor screen is x=0 y=0. Move
|
||||
@@ -425,6 +432,13 @@ pub enum Key {
|
||||
/// Representing an interface and a set of keyboard functions every
|
||||
/// operating system implementation _should_ implement.
|
||||
pub trait KeyboardControllable {
|
||||
// https://stackoverflow.com/a/33687996
|
||||
/// Offer the ability to confer concrete type.
|
||||
fn as_any(&self) -> &dyn std::any::Any;
|
||||
|
||||
/// Offer the ability to confer concrete type.
|
||||
fn as_mut_any(&mut self) -> &mut dyn std::any::Any;
|
||||
|
||||
/// Types the string parsed with DSL.
|
||||
///
|
||||
/// Typing {+SHIFT}hello{-SHIFT} becomes HELLO.
|
||||
|
||||
@@ -3,14 +3,17 @@ use crate::{Key, KeyboardControllable, MouseButton, MouseControllable};
|
||||
use std::io::Read;
|
||||
use tfc::{traits::*, Context as TFC_Context, Key as TFC_Key};
|
||||
|
||||
pub type CustomKeyboard = Box<dyn KeyboardControllable + Send>;
|
||||
pub type CustomMouce = Box<dyn MouseControllable + Send>;
|
||||
|
||||
/// The main struct for handling the event emitting
|
||||
// #[derive(Default)]
|
||||
pub struct Enigo {
|
||||
xdo: EnigoXdo,
|
||||
is_x11: bool,
|
||||
tfc: Option<TFC_Context>,
|
||||
uinput_keyboard: Option<Box<dyn KeyboardControllable + Send>>,
|
||||
uinput_mouse: Option<Box<dyn MouseControllable + Send>>,
|
||||
custom_keyboard: Option<CustomKeyboard>,
|
||||
cutsom_mouse: Option<CustomMouce>,
|
||||
}
|
||||
|
||||
impl Enigo {
|
||||
@@ -22,16 +25,21 @@ impl Enigo {
|
||||
pub fn set_delay(&mut self, delay: u64) {
|
||||
self.xdo.set_delay(delay)
|
||||
}
|
||||
/// Set uinput keyboard.
|
||||
pub fn set_uinput_keyboard(
|
||||
&mut self,
|
||||
uinput_keyboard: Option<Box<dyn KeyboardControllable + Send>>,
|
||||
) {
|
||||
self.uinput_keyboard = uinput_keyboard
|
||||
/// Set custom keyboard.
|
||||
pub fn set_custom_keyboard(&mut self, custom_keyboard: CustomKeyboard) {
|
||||
self.custom_keyboard = Some(custom_keyboard)
|
||||
}
|
||||
/// Set uinput mouse.
|
||||
pub fn set_uinput_mouse(&mut self, uinput_mouse: Option<Box<dyn MouseControllable + Send>>) {
|
||||
self.uinput_mouse = uinput_mouse
|
||||
/// Set custom mouse.
|
||||
pub fn set_custom_mouse(&mut self, custom_mouse: CustomMouce) {
|
||||
self.cutsom_mouse = Some(custom_mouse)
|
||||
}
|
||||
/// Get custom keyboard.
|
||||
pub fn get_custom_keyboard(&mut self) -> &mut Option<CustomKeyboard> {
|
||||
&mut self.custom_keyboard
|
||||
}
|
||||
/// Get custom mouse.
|
||||
pub fn get_custom_mouse(&mut self) -> &mut Option<CustomMouce> {
|
||||
&mut self.cutsom_mouse
|
||||
}
|
||||
|
||||
fn tfc_key_down_or_up(&mut self, key: Key, down: bool, up: bool) -> bool {
|
||||
@@ -84,19 +92,27 @@ impl Default for Enigo {
|
||||
} else {
|
||||
None
|
||||
},
|
||||
uinput_keyboard: None,
|
||||
uinput_mouse: None,
|
||||
custom_keyboard: None,
|
||||
cutsom_mouse: None,
|
||||
xdo: EnigoXdo::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl MouseControllable for Enigo {
|
||||
fn as_any(&self) -> &dyn std::any::Any {
|
||||
self
|
||||
}
|
||||
|
||||
fn as_mut_any(&mut self) -> &mut dyn std::any::Any {
|
||||
self
|
||||
}
|
||||
|
||||
fn mouse_move_to(&mut self, x: i32, y: i32) {
|
||||
if self.is_x11 {
|
||||
self.xdo.mouse_move_to(x, y);
|
||||
} else {
|
||||
if let Some(mouse) = &mut self.uinput_mouse {
|
||||
if let Some(mouse) = &mut self.cutsom_mouse {
|
||||
mouse.mouse_move_to(x, y)
|
||||
}
|
||||
}
|
||||
@@ -105,7 +121,7 @@ impl MouseControllable for Enigo {
|
||||
if self.is_x11 {
|
||||
self.xdo.mouse_move_relative(x, y);
|
||||
} else {
|
||||
if let Some(mouse) = &mut self.uinput_mouse {
|
||||
if let Some(mouse) = &mut self.cutsom_mouse {
|
||||
mouse.mouse_move_relative(x, y)
|
||||
}
|
||||
}
|
||||
@@ -114,7 +130,7 @@ impl MouseControllable for Enigo {
|
||||
if self.is_x11 {
|
||||
self.xdo.mouse_down(button)
|
||||
} else {
|
||||
if let Some(mouse) = &mut self.uinput_mouse {
|
||||
if let Some(mouse) = &mut self.cutsom_mouse {
|
||||
mouse.mouse_down(button)
|
||||
} else {
|
||||
Ok(())
|
||||
@@ -125,7 +141,7 @@ impl MouseControllable for Enigo {
|
||||
if self.is_x11 {
|
||||
self.xdo.mouse_up(button)
|
||||
} else {
|
||||
if let Some(mouse) = &mut self.uinput_mouse {
|
||||
if let Some(mouse) = &mut self.cutsom_mouse {
|
||||
mouse.mouse_up(button)
|
||||
}
|
||||
}
|
||||
@@ -134,7 +150,7 @@ impl MouseControllable for Enigo {
|
||||
if self.is_x11 {
|
||||
self.xdo.mouse_click(button)
|
||||
} else {
|
||||
if let Some(mouse) = &mut self.uinput_mouse {
|
||||
if let Some(mouse) = &mut self.cutsom_mouse {
|
||||
mouse.mouse_click(button)
|
||||
}
|
||||
}
|
||||
@@ -143,7 +159,7 @@ impl MouseControllable for Enigo {
|
||||
if self.is_x11 {
|
||||
self.xdo.mouse_scroll_x(length)
|
||||
} else {
|
||||
if let Some(mouse) = &mut self.uinput_mouse {
|
||||
if let Some(mouse) = &mut self.cutsom_mouse {
|
||||
mouse.mouse_scroll_x(length)
|
||||
}
|
||||
}
|
||||
@@ -152,7 +168,7 @@ impl MouseControllable for Enigo {
|
||||
if self.is_x11 {
|
||||
self.xdo.mouse_scroll_y(length)
|
||||
} else {
|
||||
if let Some(mouse) = &mut self.uinput_mouse {
|
||||
if let Some(mouse) = &mut self.cutsom_mouse {
|
||||
mouse.mouse_scroll_y(length)
|
||||
}
|
||||
}
|
||||
@@ -180,11 +196,19 @@ fn get_led_state(key: Key) -> bool {
|
||||
}
|
||||
|
||||
impl KeyboardControllable for Enigo {
|
||||
fn as_any(&self) -> &dyn std::any::Any {
|
||||
self
|
||||
}
|
||||
|
||||
fn as_mut_any(&mut self) -> &mut dyn std::any::Any {
|
||||
self
|
||||
}
|
||||
|
||||
fn get_key_state(&mut self, key: Key) -> bool {
|
||||
if self.is_x11 {
|
||||
self.xdo.get_key_state(key)
|
||||
} else {
|
||||
if let Some(keyboard) = &mut self.uinput_keyboard {
|
||||
if let Some(keyboard) = &mut self.custom_keyboard {
|
||||
keyboard.get_key_state(key)
|
||||
} else {
|
||||
get_led_state(key)
|
||||
@@ -196,7 +220,7 @@ impl KeyboardControllable for Enigo {
|
||||
if self.is_x11 {
|
||||
self.xdo.key_sequence(sequence)
|
||||
} else {
|
||||
if let Some(keyboard) = &mut self.uinput_keyboard {
|
||||
if let Some(keyboard) = &mut self.custom_keyboard {
|
||||
keyboard.key_sequence(sequence)
|
||||
}
|
||||
}
|
||||
@@ -211,7 +235,7 @@ impl KeyboardControllable for Enigo {
|
||||
Ok(())
|
||||
}
|
||||
} else {
|
||||
if let Some(keyboard) = &mut self.uinput_keyboard {
|
||||
if let Some(keyboard) = &mut self.custom_keyboard {
|
||||
keyboard.key_down(key)
|
||||
} else {
|
||||
Ok(())
|
||||
@@ -225,7 +249,7 @@ impl KeyboardControllable for Enigo {
|
||||
self.xdo.key_up(key)
|
||||
}
|
||||
} else {
|
||||
if let Some(keyboard) = &mut self.uinput_keyboard {
|
||||
if let Some(keyboard) = &mut self.custom_keyboard {
|
||||
keyboard.key_up(key)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,6 +102,14 @@ impl Drop for EnigoXdo {
|
||||
}
|
||||
}
|
||||
impl MouseControllable for EnigoXdo {
|
||||
fn as_any(&self) -> &dyn std::any::Any {
|
||||
self
|
||||
}
|
||||
|
||||
fn as_mut_any(&mut self) -> &mut dyn std::any::Any {
|
||||
self
|
||||
}
|
||||
|
||||
fn mouse_move_to(&mut self, x: i32, y: i32) {
|
||||
if self.xdo.is_null() {
|
||||
return;
|
||||
@@ -277,6 +285,14 @@ fn keysequence<'a>(key: Key) -> Cow<'a, str> {
|
||||
})
|
||||
}
|
||||
impl KeyboardControllable for EnigoXdo {
|
||||
fn as_any(&self) -> &dyn std::any::Any {
|
||||
self
|
||||
}
|
||||
|
||||
fn as_mut_any(&mut self) -> &mut dyn std::any::Any {
|
||||
self
|
||||
}
|
||||
|
||||
fn get_key_state(&mut self, key: Key) -> bool {
|
||||
if self.xdo.is_null() {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user