Skip to content

Commit 4f6ae08

Browse files
authored
fix: macos, key input lags, when service running (rustdesk#11786)
Signed-off-by: fufesou <linlong1266@gmail.com>
1 parent 90ad55d commit 4f6ae08

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/server/input_service.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ static RECORD_CURSOR_POS_RUNNING: AtomicBool = AtomicBool::new(false);
457457
// We need to do some special handling for macOS when using the legacy mode.
458458
#[cfg(target_os = "macos")]
459459
static LAST_KEY_LEGACY_MODE: AtomicBool = AtomicBool::new(true);
460-
// We use enigo to
460+
// We use enigo to
461461
// 1. Simulate mouse events
462462
// 2. Simulate the legacy mode key events
463463
// 3. Simulate the functioin key events, like LockScreen
@@ -667,7 +667,17 @@ fn is_pressed(key: &Key, en: &mut Enigo) -> bool {
667667
#[inline]
668668
#[cfg(target_os = "macos")]
669669
fn key_sleep() {
670-
std::thread::sleep(Duration::from_millis(20));
670+
// https://www.reddit.com/r/rustdesk/comments/1kn1w5x/typing_lags_when_connecting_to_macos_clients/
671+
//
672+
// There's a strange bug when running by `launchctl load -w /Library/LaunchAgents/abc.plist`
673+
// `std::thread::sleep(Duration::from_millis(20));` may sleep 90ms or more.
674+
// Though `/Applications/RustDesk.app/Contents/MacOS/rustdesk --server` in terminal is ok.
675+
let now = Instant::now();
676+
// This workaround results `21~24ms` sleep time in my tests.
677+
// But it works well in my tests.
678+
while now.elapsed() < Duration::from_millis(12) {
679+
std::thread::sleep(Duration::from_millis(1));
680+
}
671681
}
672682

673683
#[inline]

0 commit comments

Comments
 (0)