diff --git a/Cargo.lock b/Cargo.lock index f11db81d5..0655e5e4d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4881,7 +4881,7 @@ dependencies = [ [[package]] name = "rdev" version = "0.5.0-2" -source = "git+https://github.com/fufesou/rdev#ee3057bd97c91529e8b9daf2ca133a5c49f0c0eb" +source = "git+https://github.com/fufesou/rdev#bec664ee8743ade8d2fdd099b114c9eeacd9cfba" dependencies = [ "cocoa", "core-foundation", diff --git a/libs/enigo/src/lib.rs b/libs/enigo/src/lib.rs index 509bbf97c..397081c51 100644 --- a/libs/enigo/src/lib.rs +++ b/libs/enigo/src/lib.rs @@ -70,6 +70,8 @@ pub use win::ENIGO_INPUT_EXTRA_VALUE; mod macos; #[cfg(target_os = "macos")] pub use macos::Enigo; +#[cfg(target_os = "macos")] +pub use macos::ENIGO_INPUT_EXTRA_VALUE; #[cfg(target_os = "linux")] mod linux; diff --git a/libs/enigo/src/macos/macos_impl.rs b/libs/enigo/src/macos/macos_impl.rs index 992269085..b56beff12 100644 --- a/libs/enigo/src/macos/macos_impl.rs +++ b/libs/enigo/src/macos/macos_impl.rs @@ -37,6 +37,9 @@ const kUCKeyActionDisplay: u16 = 3; const kUCKeyTranslateDeadKeysBit: OptionBits = 1 << 31; const BUF_LEN: usize = 4; +/// The event source user data value of cgevent. +pub const ENIGO_INPUT_EXTRA_VALUE: i64 = 100; + #[allow(improper_ctypes)] #[allow(non_snake_case)] #[link(name = "ApplicationServices", kind = "framework")] @@ -131,6 +134,7 @@ impl Enigo { fn post(&self, event: CGEvent) { event.set_flags(self.flags); + event.set_integer_value_field(EventField::EVENT_SOURCE_USER_DATA, ENIGO_INPUT_EXTRA_VALUE); event.post(CGEventTapLocation::HID); } } diff --git a/libs/enigo/src/macos/mod.rs b/libs/enigo/src/macos/mod.rs index 286bd7483..f9aebb511 100644 --- a/libs/enigo/src/macos/mod.rs +++ b/libs/enigo/src/macos/mod.rs @@ -1,4 +1,4 @@ mod macos_impl; pub mod keycodes; -pub use self::macos_impl::Enigo; +pub use self::macos_impl::{Enigo, ENIGO_INPUT_EXTRA_VALUE}; diff --git a/libs/enigo/src/win/mod.rs b/libs/enigo/src/win/mod.rs index 62cdbd6e6..4ec95ee39 100644 --- a/libs/enigo/src/win/mod.rs +++ b/libs/enigo/src/win/mod.rs @@ -1,5 +1,4 @@ mod win_impl; pub mod keycodes; -pub use self::win_impl::Enigo; -pub use self::win_impl::ENIGO_INPUT_EXTRA_VALUE; +pub use self::win_impl::{Enigo, ENIGO_INPUT_EXTRA_VALUE}; diff --git a/src/keyboard.rs b/src/keyboard.rs index ca12cf4a1..d9b562ed3 100644 --- a/src/keyboard.rs +++ b/src/keyboard.rs @@ -583,6 +583,8 @@ pub fn event_type_to_event(event_type: EventType) -> Event { unicode: None, platform_code: 0, position_code: 0, + #[cfg(any(target_os = "windows", target_os = "macos"))] + extra_data: 0, } } diff --git a/src/server/connection.rs b/src/server/connection.rs index 2eebd54cf..517e7d4e3 100644 --- a/src/server/connection.rs +++ b/src/server/connection.rs @@ -676,10 +676,10 @@ impl Connection { #[cfg(not(any(target_os = "android", target_os = "ios")))] fn handle_input(receiver: std_mpsc::Receiver, tx: Sender) { let mut block_input_mode = false; - #[cfg(target_os = "windows")] + #[cfg(any(target_os = "windows", target_os = "macos"))] { - rdev::set_dw_mouse_extra_info(enigo::ENIGO_INPUT_EXTRA_VALUE); - rdev::set_dw_keyboard_extra_info(enigo::ENIGO_INPUT_EXTRA_VALUE); + rdev::set_mouse_extra_info(enigo::ENIGO_INPUT_EXTRA_VALUE); + rdev::set_keyboard_extra_info(enigo::ENIGO_INPUT_EXTRA_VALUE); } #[cfg(target_os = "macos")] reset_input_ondisconn(); diff --git a/src/server/input_service.rs b/src/server/input_service.rs index b721149e9..fd3a7cd24 100644 --- a/src/server/input_service.rs +++ b/src/server/input_service.rs @@ -380,6 +380,9 @@ pub fn try_stop_record_cursor_pos() { return; } RECORD_CURSOR_POS_RUNNING.store(false, Ordering::SeqCst); + + #[cfg(any(target_os = "windows", target_os = "macos"))] + let _r = rdev::exit_grab(); } // mac key input must be run in main thread, otherwise crash on >= osx 10.15 diff --git a/src/ui_session_interface.rs b/src/ui_session_interface.rs index dae85fe5f..6d12e7a1e 100644 --- a/src/ui_session_interface.rs +++ b/src/ui_session_interface.rs @@ -660,6 +660,8 @@ impl Session { platform_code, position_code: position_code as _, event_type, + #[cfg(any(target_os = "windows", target_os = "macos"))] + extra_data: 0, }; keyboard::client::process_event(&event, Some(lock_modes)); }