Skip to content

Commit

Permalink
macOS: Emit LoopDestroyed on CMD+Q (#2073)
Browse files Browse the repository at this point in the history
override applicationWillTerminate:

Co-authored-by: Mads Marquart <mads@marquart.dk>
  • Loading branch information
tinaun and madsmtm committed Jun 9, 2022
1 parent 2c01e9e commit c5eaa0a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ And please only add new entries to the top of this list, right below the `# Unre

# Unreleased

- On macOS, Fix emitting `Event::LoopDestroyed` on CMD+Q.
- On macOS, fixed an issue where having multiple windows would prevent run_return from ever returning.
- On Wayland, fix bug where the cursor wouldn't hide in GNOME.
- On macOS, Windows, and Wayland, add `set_cursor_hittest` to let the window ignore mouse events.
Expand Down
12 changes: 12 additions & 0 deletions src/platform_impl/macos/app_delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ pub static APP_DELEGATE_CLASS: Lazy<AppDelegateClass> = Lazy::new(|| unsafe {
sel!(applicationDidFinishLaunching:),
did_finish_launching as extern "C" fn(&Object, Sel, id),
);
decl.add_method(
sel!(applicationWillTerminate:),
will_terminate as extern "C" fn(&Object, Sel, id),
);

decl.add_ivar::<*mut c_void>(AUX_DELEGATE_STATE_NAME);

AppDelegateClass(decl.register())
Expand Down Expand Up @@ -75,3 +80,10 @@ extern "C" fn did_finish_launching(this: &Object, _: Sel, _: id) {
trace_scope!("applicationDidFinishLaunching:");
AppState::launched(this);
}

extern "C" fn will_terminate(_this: &Object, _: Sel, _: id) {
trace!("Triggered `applicationWillTerminate`");
// TODO: Notify every window that it will be destroyed, like done in iOS?
AppState::exit();
trace!("Completed `applicationWillTerminate`");
}

0 comments on commit c5eaa0a

Please sign in to comment.