From f3c1ace18f0017ad5d0f2f8e054cba6752e6e036 Mon Sep 17 00:00:00 2001 From: thewh1teagle <61390950+thewh1teagle@users.noreply.github.com> Date: Mon, 29 Apr 2024 01:52:01 +0300 Subject: [PATCH] feat: add app activated event for macos --- src/event.rs | 9 +++++++++ src/platform_impl/macos/app.rs | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/event.rs b/src/event.rs index fb3b1727b..127890dea 100644 --- a/src/event.rs +++ b/src/event.rs @@ -84,6 +84,12 @@ pub enum Event<'a, T: 'static> { /// Emitted when the application has been resumed. Resumed, + /// Emitted when the application has been activated. + /// ## Platform-specific + /// + /// - Only available on **macOS**. + Activated, + /// Emitted when all of the event loop's input events have been processed and redraw processing /// is about to begin. /// @@ -158,6 +164,7 @@ impl Clone for Event<'static, T> { LoopDestroyed => LoopDestroyed, Suspended => Suspended, Resumed => Resumed, + Activated => Activated, Opened { urls } => Opened { urls: urls.clone() }, } } @@ -177,6 +184,7 @@ impl<'a, T> Event<'a, T> { LoopDestroyed => Ok(LoopDestroyed), Suspended => Ok(Suspended), Resumed => Ok(Resumed), + Activated => Ok(Activated), Opened { urls } => Ok(Opened { urls }), } } @@ -198,6 +206,7 @@ impl<'a, T> Event<'a, T> { LoopDestroyed => Some(LoopDestroyed), Suspended => Some(Suspended), Resumed => Some(Resumed), + Activated => Some(Activated), Opened { urls } => Some(Opened { urls }), } } diff --git a/src/platform_impl/macos/app.rs b/src/platform_impl/macos/app.rs index 7a14813da..bea20a024 100644 --- a/src/platform_impl/macos/app.rs +++ b/src/platform_impl/macos/app.rs @@ -53,6 +53,7 @@ extern "C" fn send_event(this: &Object, _sel: Sel, event: id) { let key_window: id = msg_send![this, keyWindow]; let _: () = msg_send![key_window, sendEvent: event]; } else { + maybe_dispatch_app_event(event); maybe_dispatch_device_event(event); let superclass = util::superclass(this); let _: () = msg_send![super(this, superclass), sendEvent: event]; @@ -60,6 +61,16 @@ extern "C" fn send_event(this: &Object, _sel: Sel, event: id) { } } +unsafe fn maybe_dispatch_app_event(event: id) { + let event_type = event.eventType(); + if event_type == appkit::NSEventType::NSAppKitDefined { + let event_subtype = event.subtype(); + if let appkit::NSEventSubtype::NSApplicationActivatedEventType = event_subtype { + AppState::queue_event(EventWrapper::StaticEvent(Event::Activated)); + } + } +} + unsafe fn maybe_dispatch_device_event(event: id) { let event_type = event.eventType(); match event_type {