Skip to content

Commit

Permalink
fix: Function "LockScreen" on macOS since "ignore_flags" in enigo is …
Browse files Browse the repository at this point in the history
…introduced. (rustdesk#9757)

1. LockScreen after connection is established.
2. LockScreen after "Map mode" or "Translate mode" keys are sent.

Signed-off-by: fufesou <[email protected]>
  • Loading branch information
fufesou authored Oct 27, 2024
1 parent 40e8f0d commit c565849
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/server/input_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,13 +456,22 @@ static RECORD_CURSOR_POS_RUNNING: AtomicBool = AtomicBool::new(false);
// https://github.com/rustdesk/rustdesk/issues/9729
// We need to do some special handling for macOS when using the legacy mode.
#[cfg(target_os = "macos")]
static LAST_KEY_LEGACY_MODE: AtomicBool = AtomicBool::new(false);
// We use enigo to simulate mouse events. Only the legacy mode uses the key flags.
static LAST_KEY_LEGACY_MODE: AtomicBool = AtomicBool::new(true);
// We use enigo to
// 1. Simulate mouse events
// 2. Simulate the legacy mode key events
// 3. Simulate the functioin key events, like LockScreen
#[inline]
#[cfg(target_os = "macos")]
fn enigo_ignore_flags() -> bool {
!LAST_KEY_LEGACY_MODE.load(Ordering::SeqCst)
}
#[inline]
#[cfg(target_os = "macos")]
fn set_last_legacy_mode(v: bool) {
LAST_KEY_LEGACY_MODE.store(v, Ordering::SeqCst);
ENIGO.lock().unwrap().set_ignore_flags(!v);
}

pub fn try_start_record_cursor_pos() -> Option<thread::JoinHandle<()>> {
if RECORD_CURSOR_POS_RUNNING.load(Ordering::SeqCst) {
Expand Down Expand Up @@ -1698,17 +1707,19 @@ pub fn handle_key_(evt: &KeyEvent) {
match evt.mode.enum_value() {
Ok(KeyboardMode::Map) => {
#[cfg(target_os = "macos")]
LAST_KEY_LEGACY_MODE.store(false, Ordering::SeqCst);
set_last_legacy_mode(false);
map_keyboard_mode(evt);
}
Ok(KeyboardMode::Translate) => {
#[cfg(target_os = "macos")]
LAST_KEY_LEGACY_MODE.store(false, Ordering::SeqCst);
set_last_legacy_mode(false);
translate_keyboard_mode(evt);
}
_ => {
// All key down events are started from here,
// so we can reset the flag of last legacy mode here.
#[cfg(target_os = "macos")]
LAST_KEY_LEGACY_MODE.store(true, Ordering::SeqCst);
set_last_legacy_mode(true);
legacy_keyboard_mode(evt);
}
}
Expand Down

0 comments on commit c565849

Please sign in to comment.