From c5eaa0ab699be019c76b9b24a0d4f9b9aa72f11b Mon Sep 17 00:00:00 2001 From: tinaun Date: Thu, 9 Jun 2022 10:08:52 -0400 Subject: [PATCH] macOS: Emit LoopDestroyed on CMD+Q (#2073) override applicationWillTerminate: Co-authored-by: Mads Marquart --- CHANGELOG.md | 1 + src/platform_impl/macos/app_delegate.rs | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c3e8794..235a8ab1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/src/platform_impl/macos/app_delegate.rs b/src/platform_impl/macos/app_delegate.rs index 5ff8be2f..0ba31ecd 100644 --- a/src/platform_impl/macos/app_delegate.rs +++ b/src/platform_impl/macos/app_delegate.rs @@ -34,6 +34,11 @@ pub static APP_DELEGATE_CLASS: Lazy = 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()) @@ -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`"); +}