mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2025-01-26 03:36:32 +11:00
On macOS, add EventLoopBuilderExtMacOS::with_activate_ignoring_other_apps
(#2551)
* On macOS, add `EventLoopBuilderExtMacOS::with_activate_ignoring_other_apps` * Update src/platform/macos.rs Co-authored-by: Mads Marquart <mads@marquart.dk> * remove todo Co-authored-by: Mads Marquart <mads@marquart.dk>
This commit is contained in:
parent
ce6c6e8c95
commit
418cc44e93
5 changed files with 34 additions and 5 deletions
|
@ -8,6 +8,7 @@ And please only add new entries to the top of this list, right below the `# Unre
|
||||||
|
|
||||||
# Unreleased
|
# Unreleased
|
||||||
|
|
||||||
|
- On MacOS, add `EventLoopBuilderExtMacOS::with_activate_ignoring_other_apps`.
|
||||||
- On Windows, fix icons specified on `WindowBuilder` not taking effect for windows created after the first one.
|
- On Windows, fix icons specified on `WindowBuilder` not taking effect for windows created after the first one.
|
||||||
- On Windows and macOS, add `Window::title` to query the current window title.
|
- On Windows and macOS, add `Window::title` to query the current window title.
|
||||||
- On Windows, fix focusing menubar when pressing `Alt`.
|
- On Windows, fix focusing menubar when pressing `Alt`.
|
||||||
|
|
|
@ -218,6 +218,12 @@ pub trait EventLoopBuilderExtMacOS {
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
fn with_default_menu(&mut self, enable: bool) -> &mut Self;
|
fn with_default_menu(&mut self, enable: bool) -> &mut Self;
|
||||||
|
|
||||||
|
/// Used to prevent the application from automatically activating when launched if
|
||||||
|
/// another application is already active.
|
||||||
|
///
|
||||||
|
/// The default behavior is to ignore other applications and activate when launched.
|
||||||
|
fn with_activate_ignoring_other_apps(&mut self, ignore: bool) -> &mut Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> EventLoopBuilderExtMacOS for EventLoopBuilder<T> {
|
impl<T> EventLoopBuilderExtMacOS for EventLoopBuilder<T> {
|
||||||
|
@ -232,6 +238,12 @@ impl<T> EventLoopBuilderExtMacOS for EventLoopBuilder<T> {
|
||||||
self.platform_specific.default_menu = enable;
|
self.platform_specific.default_menu = enable;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn with_activate_ignoring_other_apps(&mut self, ignore: bool) -> &mut Self {
|
||||||
|
self.platform_specific.activate_ignoring_other_apps = ignore;
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Additional methods on [`MonitorHandle`] that are specific to MacOS.
|
/// Additional methods on [`MonitorHandle`] that are specific to MacOS.
|
||||||
|
|
|
@ -11,6 +11,7 @@ declare_class!(
|
||||||
pub(super) struct ApplicationDelegate {
|
pub(super) struct ApplicationDelegate {
|
||||||
activation_policy: NSApplicationActivationPolicy,
|
activation_policy: NSApplicationActivationPolicy,
|
||||||
default_menu: bool,
|
default_menu: bool,
|
||||||
|
activate_ignoring_other_apps: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl ClassType for ApplicationDelegate {
|
unsafe impl ClassType for ApplicationDelegate {
|
||||||
|
@ -36,7 +37,11 @@ declare_class!(
|
||||||
#[sel(applicationDidFinishLaunching:)]
|
#[sel(applicationDidFinishLaunching:)]
|
||||||
fn did_finish_launching(&self, _sender: *const Object) {
|
fn did_finish_launching(&self, _sender: *const Object) {
|
||||||
trace_scope!("applicationDidFinishLaunching:");
|
trace_scope!("applicationDidFinishLaunching:");
|
||||||
AppState::launched(*self.activation_policy, *self.default_menu);
|
AppState::launched(
|
||||||
|
*self.activation_policy,
|
||||||
|
*self.default_menu,
|
||||||
|
*self.activate_ignoring_other_apps,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[sel(applicationWillTerminate:)]
|
#[sel(applicationWillTerminate:)]
|
||||||
|
@ -52,12 +57,14 @@ impl ApplicationDelegate {
|
||||||
pub(super) fn new(
|
pub(super) fn new(
|
||||||
activation_policy: NSApplicationActivationPolicy,
|
activation_policy: NSApplicationActivationPolicy,
|
||||||
default_menu: bool,
|
default_menu: bool,
|
||||||
|
activate_ignoring_other_apps: bool,
|
||||||
) -> Id<Self, Shared> {
|
) -> Id<Self, Shared> {
|
||||||
unsafe {
|
unsafe {
|
||||||
msg_send_id![
|
msg_send_id![
|
||||||
msg_send_id![Self::class(), alloc],
|
msg_send_id![Self::class(), alloc],
|
||||||
initWithActivationPolicy: activation_policy,
|
initWithActivationPolicy: activation_policy,
|
||||||
defaultMenu: default_menu,
|
defaultMenu: default_menu,
|
||||||
|
activateIgnoringOtherApps: activate_ignoring_other_apps,
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -272,7 +272,11 @@ impl AppState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn launched(activation_policy: NSApplicationActivationPolicy, create_default_menu: bool) {
|
pub fn launched(
|
||||||
|
activation_policy: NSApplicationActivationPolicy,
|
||||||
|
create_default_menu: bool,
|
||||||
|
activate_ignoring_other_apps: bool,
|
||||||
|
) {
|
||||||
let app = NSApp();
|
let app = NSApp();
|
||||||
// We need to delay setting the activation policy and activating the app
|
// We need to delay setting the activation policy and activating the app
|
||||||
// until `applicationDidFinishLaunching` has been called. Otherwise the
|
// until `applicationDidFinishLaunching` has been called. Otherwise the
|
||||||
|
@ -280,8 +284,7 @@ impl AppState {
|
||||||
app.setActivationPolicy(activation_policy);
|
app.setActivationPolicy(activation_policy);
|
||||||
|
|
||||||
window_activation_hack(&app);
|
window_activation_hack(&app);
|
||||||
// TODO: Consider allowing the user to specify they don't want their application activated
|
app.activateIgnoringOtherApps(activate_ignoring_other_apps);
|
||||||
app.activateIgnoringOtherApps(true);
|
|
||||||
|
|
||||||
HANDLER.set_ready();
|
HANDLER.set_ready();
|
||||||
HANDLER.waker().start();
|
HANDLER.waker().start();
|
||||||
|
|
|
@ -124,6 +124,7 @@ pub struct EventLoop<T: 'static> {
|
||||||
pub(crate) struct PlatformSpecificEventLoopAttributes {
|
pub(crate) struct PlatformSpecificEventLoopAttributes {
|
||||||
pub(crate) activation_policy: ActivationPolicy,
|
pub(crate) activation_policy: ActivationPolicy,
|
||||||
pub(crate) default_menu: bool,
|
pub(crate) default_menu: bool,
|
||||||
|
pub(crate) activate_ignoring_other_apps: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for PlatformSpecificEventLoopAttributes {
|
impl Default for PlatformSpecificEventLoopAttributes {
|
||||||
|
@ -131,6 +132,7 @@ impl Default for PlatformSpecificEventLoopAttributes {
|
||||||
Self {
|
Self {
|
||||||
activation_policy: Default::default(), // Regular
|
activation_policy: Default::default(), // Regular
|
||||||
default_menu: true,
|
default_menu: true,
|
||||||
|
activate_ignoring_other_apps: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -154,7 +156,11 @@ impl<T> EventLoop<T> {
|
||||||
ActivationPolicy::Accessory => NSApplicationActivationPolicyAccessory,
|
ActivationPolicy::Accessory => NSApplicationActivationPolicyAccessory,
|
||||||
ActivationPolicy::Prohibited => NSApplicationActivationPolicyProhibited,
|
ActivationPolicy::Prohibited => NSApplicationActivationPolicyProhibited,
|
||||||
};
|
};
|
||||||
let delegate = ApplicationDelegate::new(activation_policy, attributes.default_menu);
|
let delegate = ApplicationDelegate::new(
|
||||||
|
activation_policy,
|
||||||
|
attributes.default_menu,
|
||||||
|
attributes.activate_ignoring_other_apps,
|
||||||
|
);
|
||||||
|
|
||||||
autoreleasepool(|_| {
|
autoreleasepool(|_| {
|
||||||
app.setDelegate(&delegate);
|
app.setDelegate(&delegate);
|
||||||
|
|
Loading…
Add table
Reference in a new issue