Skip to content

Commit 1cdf43c

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 ba704c4 commit 1cdf43c

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

CHANGELOG.md

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

3+
- On macOS, wait with activating the application until the application has initialized.
4+
- On macOS, fix creating new windows when the application has a main menu.
35
- On Windows, fix fractional deltas for mouse wheel device events.
46
- On macOS, fix segmentation fault after dropping the main window.
57
- On Android, `InputEvent::KeyEvent` is partially implemented providing the key scancode.

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
@@ -360,7 +360,7 @@ impl UnownedWindow {
360360

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

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

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

0 commit comments

Comments
 (0)