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;
name = '${androidInfo.brand}-${androidInfo.model}';
id = androidInfo.id.hashCode.toString();
androidVersion = androidInfo.version.sdkInt ?? 0;
androidVersion = androidInfo.version.sdkInt;
} else if (Platform.isIOS) {
IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
name = iosInfo.utsname.machine ?? '';

View File

@ -379,6 +379,10 @@ pub async fn start_server(is_server: bool) {
#[cfg(windows)]
crate::platform::windows::bootstrap();
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")]
tokio::spawn(async { sync_and_watch_config_dir().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.
// Thus this funtion must not be called in a temporary runtime.
#[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
// 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?;
log::info!("UInput keyboard created");
ENIGO
.lock()
.unwrap()
.set_custom_keyboard(Box::new(keyboard));
}
let keyboard = super::uinput::client::UInputKeyboard::new().await?;
log::info!("UInput keyboard created");
let mouse = super::uinput::client::UInputMouse::new().await?;
log::info!("UInput mouse created");
let mouse_created = ENIGO.lock().unwrap().get_custom_mouse().is_some();
if mouse_created {
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");
}
}
});
} else {
let mouse = super::uinput::client::UInputMouse::new().await?;
log::info!("UInput mouse created");
ENIGO.lock().unwrap().set_custom_mouse(Box::new(mouse));
ENIGO
.lock()
.unwrap()
.set_custom_keyboard(Box::new(keyboard));
ENIGO.lock().unwrap().set_custom_mouse(Box::new(mouse));
Ok(())
}
#[cfg(target_os = "linux")]
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");
}
}
Ok(())
}
#[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
}

View File

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