Skip to content

Commit

Permalink
MacOS: Only activate after the application has finished launching
Browse files Browse the repository at this point in the history
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?
  • Loading branch information
madsmtm committed Apr 6, 2021
1 parent 7502c27 commit 1081291
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Unreleased

- On macOS, wait with activating the application until the application has initialized.
- On macOS, fix creating new windows when the application has a main menu.
- On Windows, fix fractional deltas for mouse wheel device events.
- On macOS, fix segmentation fault after dropping the main window.
Expand Down
8 changes: 7 additions & 1 deletion src/platform_impl/macos/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ use std::{
};

use cocoa::{
appkit::{NSApp, NSWindow},
appkit::{NSApp, NSApplication, NSWindow},
base::{id, nil},
foundation::{NSAutoreleasePool, NSSize},
};
use objc::runtime::YES;

use crate::{
dpi::LogicalSize,
Expand Down Expand Up @@ -272,6 +273,11 @@ impl AppState {
}

pub fn launched() {
unsafe {
let ns_app = NSApp();
// TODO: Consider allowing the user to specify they don't want their application activated
ns_app.activateIgnoringOtherApps_(YES);
};
HANDLER.set_ready();
HANDLER.waker().start();
HANDLER.set_in_callback(true);
Expand Down
3 changes: 1 addition & 2 deletions src/platform_impl/macos/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ impl UnownedWindow {

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

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

ns_app.activateIgnoringOtherApps_(YES);
win_attribs.min_inner_size.map(|dim| {
let logical_dim = dim.to_logical(scale_factor);
set_min_inner_size(*ns_window, logical_dim)
Expand Down

0 comments on commit 1081291

Please sign in to comment.