Require setting the activation policy on the event loop (#1922)
* Require setting the activation policy on the event loop * Run cargo fmt * Update changelog * Fixes and tweaks from review * Correct comment in app_state.rs Co-authored-by: Mads Marquart <mads@marquart.dk>
This commit is contained in:
parent
0986fae066
commit
cdeb1c3828
9 changed files with 110 additions and 56 deletions
|
|
@ -19,17 +19,23 @@ use cocoa::{
|
|||
};
|
||||
use objc::runtime::YES;
|
||||
|
||||
use objc::runtime::Object;
|
||||
|
||||
use crate::{
|
||||
dpi::LogicalSize,
|
||||
event::{Event, StartCause, WindowEvent},
|
||||
event_loop::{ControlFlow, EventLoopWindowTarget as RootWindowTarget},
|
||||
platform_impl::platform::{
|
||||
event::{EventProxy, EventWrapper},
|
||||
event_loop::{post_dummy_event, PanicInfo},
|
||||
menu,
|
||||
observer::{CFRunLoopGetMain, CFRunLoopWakeUp, EventLoopWaker},
|
||||
util::{IdRef, Never},
|
||||
window::get_window_id,
|
||||
platform::macos::ActivationPolicy,
|
||||
platform_impl::{
|
||||
get_aux_state_mut,
|
||||
platform::{
|
||||
event::{EventProxy, EventWrapper},
|
||||
event_loop::{post_dummy_event, PanicInfo},
|
||||
menu,
|
||||
observer::{CFRunLoopGetMain, CFRunLoopWakeUp, EventLoopWaker},
|
||||
util::{IdRef, Never},
|
||||
window::get_window_id,
|
||||
},
|
||||
},
|
||||
window::WindowId,
|
||||
};
|
||||
|
|
@ -273,7 +279,8 @@ impl AppState {
|
|||
HANDLER.callback.lock().unwrap().take();
|
||||
}
|
||||
|
||||
pub fn launched() {
|
||||
pub fn launched(app_delegate: &Object) {
|
||||
apply_activation_policy(app_delegate);
|
||||
unsafe {
|
||||
let ns_app = NSApp();
|
||||
window_activation_hack(ns_app);
|
||||
|
|
@ -457,3 +464,18 @@ unsafe fn window_activation_hack(ns_app: id) {
|
|||
}
|
||||
}
|
||||
}
|
||||
fn apply_activation_policy(app_delegate: &Object) {
|
||||
unsafe {
|
||||
use cocoa::appkit::NSApplicationActivationPolicy::*;
|
||||
let ns_app = NSApp();
|
||||
// We need to delay setting the activation policy and activating the app
|
||||
// until `applicationDidFinishLaunching` has been called. Otherwise the
|
||||
// menu bar won't be interactable.
|
||||
let act_pol = get_aux_state_mut(app_delegate).activation_policy;
|
||||
ns_app.setActivationPolicy_(match act_pol {
|
||||
ActivationPolicy::Regular => NSApplicationActivationPolicyRegular,
|
||||
ActivationPolicy::Accessory => NSApplicationActivationPolicyAccessory,
|
||||
ActivationPolicy::Prohibited => NSApplicationActivationPolicyProhibited,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue