From 05311d1966f673a44ac12794108261b372e978d5 Mon Sep 17 00:00:00 2001 From: Kaur Kuut Date: Sun, 31 May 2020 21:15:03 +0300 Subject: [PATCH] Fix macOS main menu not working before refocus. (#994) --- CHANGELOG.md | 2 ++ druid-shell/src/platform/mac/application.rs | 9 +++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f536e5590..05f4422238 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -116,6 +116,7 @@ This means that druid no longer requires cairo on macOS and uses Core Graphics i - Wheel events now properly update hot state. ([#951] by [@xStrom]) - X11: Support mouse scrolling. ([#961] by [@jneem]) - `Painter` now properly repaints on data change in `Container`. ([#991] by [@cmyr]) +- macOS: The application menu is now immediately interactable after launch. ([#994] by [@xStrom]) ### Visual @@ -248,6 +249,7 @@ This means that druid no longer requires cairo on macOS and uses Core Graphics i [#990]: https://github.com/xi-editor/druid/pull/990 [#991]: https://github.com/xi-editor/druid/pull/991 [#993]: https://github.com/xi-editor/druid/pull/993 +[#994]: https://github.com/xi-editor/druid/pull/994 [#996]: https://github.com/xi-editor/druid/pull/996 [#1001]: https://github.com/xi-editor/druid/pull/1001 diff --git a/druid-shell/src/platform/mac/application.rs b/druid-shell/src/platform/mac/application.rs index 79fd923343..77b80f87c2 100644 --- a/druid-shell/src/platform/mac/application.rs +++ b/druid-shell/src/platform/mac/application.rs @@ -53,10 +53,7 @@ impl Application { util::assert_main_thread(); unsafe { let _pool = NSAutoreleasePool::new(nil); - let ns_app = NSApp(); - ns_app.setActivationPolicy_(NSApplicationActivationPolicyRegular); - let state = Rc::new(RefCell::new(State { quitting: false })); Ok(Application { ns_app, state }) @@ -174,7 +171,11 @@ lazy_static! { extern "C" fn application_did_finish_launching(_this: &mut Object, _: Sel, _notification: id) { unsafe { - let () = msg_send![NSApp(), activateIgnoringOtherApps: YES]; + let ns_app = NSApp(); + // We need to delay setting the activation policy and activating the app + // until we have the main menu all set up. Otherwise the menu won't be interactable. + ns_app.setActivationPolicy_(NSApplicationActivationPolicyRegular); + let () = msg_send![ns_app, activateIgnoringOtherApps: YES]; } }