Merge pull request #2498 from fufesou/uinput_remove_tmp_runtime

Fix wayland
This commit is contained in:
RustDesk 2022-12-09 18:02:05 +08:00 committed by GitHub
commit b504bc24cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 22 deletions

View File

@ -245,16 +245,18 @@ pub async fn setup_uinput(minx: i32, maxx: i32, miny: i32, maxy: i32) -> ResultT
pub async fn update_mouse_resolution(minx: i32, maxx: i32, miny: i32, maxy: i32) -> ResultType<()> { pub async fn update_mouse_resolution(minx: i32, maxx: i32, miny: i32, maxy: i32) -> ResultType<()> {
set_uinput_resolution(minx, maxx, miny, maxy).await?; set_uinput_resolution(minx, maxx, miny, maxy).await?;
if let Some(mouse) = ENIGO.lock().unwrap().get_custom_mouse() { std::thread::spawn(|| {
if let Some(mouse) = mouse if let Some(mouse) = ENIGO.lock().unwrap().get_custom_mouse() {
.as_mut_any() if let Some(mouse) = mouse
.downcast_mut::<super::uinput::client::UInputMouse>() .as_mut_any()
{ .downcast_mut::<super::uinput::client::UInputMouse>()
allow_err!(mouse.send_refresh()); {
} else { allow_err!(mouse.send_refresh());
log::error!("failed downcast uinput mouse"); } else {
log::error!("failed downcast uinput mouse");
}
} }
} });
Ok(()) Ok(())
} }

View File

@ -4,7 +4,7 @@ use evdev::{
uinput::{VirtualDevice, VirtualDeviceBuilder}, uinput::{VirtualDevice, VirtualDeviceBuilder},
AttributeSet, EventType, InputEvent, AttributeSet, EventType, InputEvent,
}; };
use hbb_common::{allow_err, bail, log, tokio, ResultType}; use hbb_common::{allow_err, bail, log, tokio::{self, runtime::Runtime}, ResultType};
static IPC_CONN_TIMEOUT: u64 = 1000; static IPC_CONN_TIMEOUT: u64 = 1000;
static IPC_REQUEST_TIMEOUT: u64 = 1000; static IPC_REQUEST_TIMEOUT: u64 = 1000;
@ -17,24 +17,24 @@ pub mod client {
pub struct UInputKeyboard { pub struct UInputKeyboard {
conn: Connection, conn: Connection,
rt: Runtime,
} }
impl UInputKeyboard { impl UInputKeyboard {
pub async fn new() -> ResultType<Self> { pub async fn new() -> ResultType<Self> {
let conn = ipc::connect(IPC_CONN_TIMEOUT, IPC_POSTFIX_KEYBOARD).await?; let conn = ipc::connect(IPC_CONN_TIMEOUT, IPC_POSTFIX_KEYBOARD).await?;
Ok(Self { conn }) let rt = Runtime::new()?;
Ok(Self { conn, rt })
} }
#[tokio::main(flavor = "current_thread")] fn send(&mut self, data: Data) -> ResultType<()> {
async fn send(&mut self, data: Data) -> ResultType<()> { self.rt.block_on(self.conn.send(&data))
self.conn.send(&data).await
} }
#[tokio::main(flavor = "current_thread")] fn send_get_key_state(&mut self, data: Data) -> ResultType<bool> {
async fn send_get_key_state(&mut self, data: Data) -> ResultType<bool> { self.rt.block_on(self.conn.send(&data))?;
self.conn.send(&data).await?;
match self.conn.next_timeout(IPC_REQUEST_TIMEOUT).await { match self.rt.block_on(self.conn.next_timeout(IPC_REQUEST_TIMEOUT)) {
Ok(Some(Data::KeyboardResponse(ipc::DataKeyboardResponse::GetKeyState(state)))) => { Ok(Some(Data::KeyboardResponse(ipc::DataKeyboardResponse::GetKeyState(state)))) => {
Ok(state) Ok(state)
} }
@ -101,17 +101,18 @@ pub mod client {
pub struct UInputMouse { pub struct UInputMouse {
conn: Connection, conn: Connection,
rt: Runtime,
} }
impl UInputMouse { impl UInputMouse {
pub async fn new() -> ResultType<Self> { pub async fn new() -> ResultType<Self> {
let conn = ipc::connect(IPC_CONN_TIMEOUT, IPC_POSTFIX_MOUSE).await?; let conn = ipc::connect(IPC_CONN_TIMEOUT, IPC_POSTFIX_MOUSE).await?;
Ok(Self { conn }) let rt = Runtime::new()?;
Ok(Self { conn, rt })
} }
#[tokio::main(flavor = "current_thread")] fn send(&mut self, data: Data) -> ResultType<()> {
async fn send(&mut self, data: Data) -> ResultType<()> { self.rt.block_on(self.conn.send(&data))
self.conn.send(&data).await
} }
pub fn send_refresh(&mut self) -> ResultType<()> { pub fn send_refresh(&mut self) -> ResultType<()> {
@ -586,6 +587,16 @@ pub mod service {
match data { match data {
Data::Mouse(data) => { Data::Mouse(data) => {
if let DataMouse::Refresh = data { if let DataMouse::Refresh = data {
let resolution = RESOLUTION.lock().unwrap();
let rng_x = resolution.0.clone();
let rng_y = resolution.1.clone();
log::info!(
"Refresh uinput mouce with rng_x: ({}, {}), rng_y: ({}, {})",
rng_x.0,
rng_x.1,
rng_y.0,
rng_y.1
);
mouse = match mouce::Mouse::new_uinput(rng_x, rng_y) { mouse = match mouce::Mouse::new_uinput(rng_x, rng_y) {
Ok(mouse) => mouse, Ok(mouse) => mouse,
Err(e) => { Err(e) => {