Merge pull request #2498 from fufesou/uinput_remove_tmp_runtime
Fix wayland
This commit is contained in:
commit
b504bc24cc
@ -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<()> {
|
||||
set_uinput_resolution(minx, maxx, miny, maxy).await?;
|
||||
|
||||
if let Some(mouse) = ENIGO.lock().unwrap().get_custom_mouse() {
|
||||
if let Some(mouse) = mouse
|
||||
.as_mut_any()
|
||||
.downcast_mut::<super::uinput::client::UInputMouse>()
|
||||
{
|
||||
allow_err!(mouse.send_refresh());
|
||||
} else {
|
||||
log::error!("failed downcast uinput mouse");
|
||||
std::thread::spawn(|| {
|
||||
if let Some(mouse) = ENIGO.lock().unwrap().get_custom_mouse() {
|
||||
if let Some(mouse) = mouse
|
||||
.as_mut_any()
|
||||
.downcast_mut::<super::uinput::client::UInputMouse>()
|
||||
{
|
||||
allow_err!(mouse.send_refresh());
|
||||
} else {
|
||||
log::error!("failed downcast uinput mouse");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ use evdev::{
|
||||
uinput::{VirtualDevice, VirtualDeviceBuilder},
|
||||
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_REQUEST_TIMEOUT: u64 = 1000;
|
||||
@ -17,24 +17,24 @@ pub mod client {
|
||||
|
||||
pub struct UInputKeyboard {
|
||||
conn: Connection,
|
||||
rt: Runtime,
|
||||
}
|
||||
|
||||
impl UInputKeyboard {
|
||||
pub async fn new() -> ResultType<Self> {
|
||||
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")]
|
||||
async fn send(&mut self, data: Data) -> ResultType<()> {
|
||||
self.conn.send(&data).await
|
||||
fn send(&mut self, data: Data) -> ResultType<()> {
|
||||
self.rt.block_on(self.conn.send(&data))
|
||||
}
|
||||
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn send_get_key_state(&mut self, data: Data) -> ResultType<bool> {
|
||||
self.conn.send(&data).await?;
|
||||
fn send_get_key_state(&mut self, data: Data) -> ResultType<bool> {
|
||||
self.rt.block_on(self.conn.send(&data))?;
|
||||
|
||||
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(state)
|
||||
}
|
||||
@ -101,17 +101,18 @@ pub mod client {
|
||||
|
||||
pub struct UInputMouse {
|
||||
conn: Connection,
|
||||
rt: Runtime,
|
||||
}
|
||||
|
||||
impl UInputMouse {
|
||||
pub async fn new() -> ResultType<Self> {
|
||||
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")]
|
||||
async fn send(&mut self, data: Data) -> ResultType<()> {
|
||||
self.conn.send(&data).await
|
||||
fn send(&mut self, data: Data) -> ResultType<()> {
|
||||
self.rt.block_on(self.conn.send(&data))
|
||||
}
|
||||
|
||||
pub fn send_refresh(&mut self) -> ResultType<()> {
|
||||
@ -586,6 +587,16 @@ pub mod service {
|
||||
match data {
|
||||
Data::Mouse(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) {
|
||||
Ok(mouse) => mouse,
|
||||
Err(e) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user