Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add app activated event for macos #911

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -158,6 +164,7 @@ impl<T: Clone> Clone for Event<'static, T> {
LoopDestroyed => LoopDestroyed,
Suspended => Suspended,
Resumed => Resumed,
Activated => Activated,
Opened { urls } => Opened { urls: urls.clone() },
}
}
Expand All @@ -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 }),
}
}
Expand All @@ -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 }),
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/platform_impl/macos/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,24 @@ 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];
}
}
}

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 {
Expand Down
Loading