Merge pull request #2388 from fufesou/fix_wayland_ubuntu_22

Better uinput setup and update
This commit is contained in:
RustDesk 2022-11-30 10:46:27 +08:00 committed by GitHub
commit 11611daaba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 32 deletions

View File

@ -131,7 +131,7 @@ class PlatformFFI {
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo; AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
name = '${androidInfo.brand}-${androidInfo.model}'; name = '${androidInfo.brand}-${androidInfo.model}';
id = androidInfo.id.hashCode.toString(); id = androidInfo.id.hashCode.toString();
androidVersion = androidInfo.version.sdkInt ?? 0; androidVersion = androidInfo.version.sdkInt;
} else if (Platform.isIOS) { } else if (Platform.isIOS) {
IosDeviceInfo iosInfo = await deviceInfo.iosInfo; IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
name = iosInfo.utsname.machine ?? ''; name = iosInfo.utsname.machine ?? '';

View File

@ -379,6 +379,10 @@ pub async fn start_server(is_server: bool) {
#[cfg(windows)] #[cfg(windows)]
crate::platform::windows::bootstrap(); crate::platform::windows::bootstrap();
input_service::fix_key_down_timeout_loop(); input_service::fix_key_down_timeout_loop();
#[cfg(target_os = "linux")]
if crate::platform::current_is_wayland() {
allow_err!(input_service::setup_uinput(0, 1920, 0, 1080).await);
}
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
tokio::spawn(async { sync_and_watch_config_dir().await }); tokio::spawn(async { sync_and_watch_config_dir().await });
crate::RendezvousMediator::start_all().await; crate::RendezvousMediator::start_all().await;

View File

@ -223,44 +223,44 @@ lazy_static::lazy_static! {
// The clients are ipc connections that must live shorter than tokio runtime. // The clients are ipc connections that must live shorter than tokio runtime.
// Thus this funtion must not be called in a temporary runtime. // Thus this funtion must not be called in a temporary runtime.
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
pub async fn set_uinput() -> ResultType<()> { pub async fn setup_uinput(minx: i32, maxx: i32, miny: i32, maxy: i32) -> ResultType<()> {
// Keyboard and mouse both open /dev/uinput // Keyboard and mouse both open /dev/uinput
// TODO: Make sure there's no race // TODO: Make sure there's no race
set_uinput_resolution(minx, maxx, miny, maxy).await?;
if ENIGO.lock().unwrap().get_custom_keyboard().is_none() { let keyboard = super::uinput::client::UInputKeyboard::new().await?;
let keyboard = super::uinput::client::UInputKeyboard::new().await?; log::info!("UInput keyboard created");
log::info!("UInput keyboard created"); let mouse = super::uinput::client::UInputMouse::new().await?;
ENIGO log::info!("UInput mouse created");
.lock()
.unwrap()
.set_custom_keyboard(Box::new(keyboard));
}
let mouse_created = ENIGO.lock().unwrap().get_custom_mouse().is_some(); ENIGO
if mouse_created { .lock()
std::thread::spawn(|| { .unwrap()
if let Some(mouse) = ENIGO.lock().unwrap().get_custom_mouse() { .set_custom_keyboard(Box::new(keyboard));
if let Some(mouse) = mouse ENIGO.lock().unwrap().set_custom_mouse(Box::new(mouse));
.as_mut_any() Ok(())
.downcast_mut::<super::uinput::client::UInputMouse>() }
{
allow_err!(mouse.send_refresh()); #[cfg(target_os = "linux")]
} else { pub async fn update_mouse_resolution(minx: i32, maxx: i32, miny: i32, maxy: i32) -> ResultType<()> {
log::error!("failed downcast uinput mouse"); set_uinput_resolution(minx, maxx, miny, maxy).await?;
}
} if let Some(mouse) = ENIGO.lock().unwrap().get_custom_mouse() {
}); if let Some(mouse) = mouse
} else { .as_mut_any()
let mouse = super::uinput::client::UInputMouse::new().await?; .downcast_mut::<super::uinput::client::UInputMouse>()
log::info!("UInput mouse created"); {
ENIGO.lock().unwrap().set_custom_mouse(Box::new(mouse)); allow_err!(mouse.send_refresh());
} else {
log::error!("failed downcast uinput mouse");
}
} }
Ok(()) Ok(())
} }
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
pub async fn set_uinput_resolution(minx: i32, maxx: i32, miny: i32, maxy: i32) -> ResultType<()> { async fn set_uinput_resolution(minx: i32, maxx: i32, miny: i32, maxy: i32) -> ResultType<()> {
super::uinput::client::set_resolution(minx, maxx, miny, maxy).await super::uinput::client::set_resolution(minx, maxx, miny, maxy).await
} }

View File

@ -174,14 +174,13 @@ pub(super) async fn check_init() -> ResultType<()> {
if minx != maxx && miny != maxy { if minx != maxx && miny != maxy {
log::info!( log::info!(
"send uinput resolution: ({}, {}), ({}, {})", "update mouse resolution: ({}, {}), ({}, {})",
minx, minx,
maxx, maxx,
miny, miny,
maxy maxy
); );
allow_err!(input_service::set_uinput_resolution(minx, maxx, miny, maxy).await); allow_err!(input_service::update_mouse_resolution(minx, maxx, miny, maxy).await);
allow_err!(input_service::set_uinput().await);
} }
} }
Ok(()) Ok(())