fix refresh uinput mouse resulition

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2022-12-09 17:45:07 +08:00
parent 03fc91e557
commit fc85dca911

View File

@ -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) => {