Skip to content

Commit 1081291

Browse files
committed
MacOS: Only activate after the application has finished launching
This fixes the main menu not responding until you refocus, at least from what I can tell - though we might have to do something similar to linebender/druid#994 to fix it fully?
1 parent 7502c27 commit 1081291

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Unreleased
22

3+
- On macOS, wait with activating the application until the application has initialized.
34
- On macOS, fix creating new windows when the application has a main menu.
45
- On Windows, fix fractional deltas for mouse wheel device events.
56
- On macOS, fix segmentation fault after dropping the main window.

src/platform_impl/macos/app_state.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ use std::{
1313
};
1414

1515
use cocoa::{
16-
appkit::{NSApp, NSWindow},
16+
appkit::{NSApp, NSApplication, NSWindow},
1717
base::{id, nil},
1818
foundation::{NSAutoreleasePool, NSSize},
1919
};
20+
use objc::runtime::YES;
2021

2122
use crate::{
2223
dpi::LogicalSize,
@@ -272,6 +273,11 @@ impl AppState {
272273
}
273274

274275
pub fn launched() {
276+
unsafe {
277+
let ns_app = NSApp();
278+
// TODO: Consider allowing the user to specify they don't want their application activated
279+
ns_app.activateIgnoringOtherApps_(YES);
280+
};
275281
HANDLER.set_ready();
276282
HANDLER.waker().start();
277283
HANDLER.set_in_callback(true);

src/platform_impl/macos/window.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ impl UnownedWindow {
361361

362362
let pool = unsafe { NSAutoreleasePool::new(nil) };
363363

364-
let ns_app = create_app(pl_attribs.activation_policy).ok_or_else(|| {
364+
create_app(pl_attribs.activation_policy).ok_or_else(|| {
365365
unsafe { pool.drain() };
366366
os_error!(OsError::CreationError("Couldn't create `NSApplication`"))
367367
})?;
@@ -387,7 +387,6 @@ impl UnownedWindow {
387387
ns_window.setBackgroundColor_(NSColor::clearColor(nil));
388388
}
389389

390-
ns_app.activateIgnoringOtherApps_(YES);
391390
win_attribs.min_inner_size.map(|dim| {
392391
let logical_dim = dim.to_logical(scale_factor);
393392
set_min_inner_size(*ns_window, logical_dim)

0 commit comments

Comments
 (0)