Prevent winit from overriding LSUIElement in package manifests (#3920)
This commit is contained in:
parent
dfea49f488
commit
7e819bb2ce
4 changed files with 21 additions and 15 deletions
|
|
@ -154,3 +154,5 @@ changelog entry.
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- On Orbital, `MonitorHandle::name()` now returns `None` instead of a dummy name.
|
- On Orbital, `MonitorHandle::name()` now returns `None` instead of a dummy name.
|
||||||
|
- On MacOS, package manifest definitions of `LSUIElement` will no longer be overridden with the
|
||||||
|
default activation policy, unless explicitly provided during initialization.
|
||||||
|
|
|
||||||
|
|
@ -384,9 +384,12 @@ impl WindowAttributesExtMacOS for WindowAttributes {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait EventLoopBuilderExtMacOS {
|
pub trait EventLoopBuilderExtMacOS {
|
||||||
/// Sets the activation policy for the application.
|
/// Sets the activation policy for the application. If used, this will override
|
||||||
|
/// any relevant settings provided in the package manifest.
|
||||||
|
/// For instance, `with_activation_policy(ActivationPolicy::Regular)` will prevent
|
||||||
|
/// the application from running as an "agent", even if LSUIElement is set to true.
|
||||||
///
|
///
|
||||||
/// It is set to [`ActivationPolicy::Regular`] by default.
|
/// If unused, the Winit will honor the package manifest.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
|
|
@ -438,7 +441,7 @@ pub trait EventLoopBuilderExtMacOS {
|
||||||
impl EventLoopBuilderExtMacOS for EventLoopBuilder {
|
impl EventLoopBuilderExtMacOS for EventLoopBuilder {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn with_activation_policy(&mut self, activation_policy: ActivationPolicy) -> &mut Self {
|
fn with_activation_policy(&mut self, activation_policy: ActivationPolicy) -> &mut Self {
|
||||||
self.platform_specific.activation_policy = activation_policy;
|
self.platform_specific.activation_policy = Some(activation_policy);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ use crate::window::WindowId as RootWindowId;
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(super) struct AppState {
|
pub(super) struct AppState {
|
||||||
mtm: MainThreadMarker,
|
mtm: MainThreadMarker,
|
||||||
activation_policy: NSApplicationActivationPolicy,
|
activation_policy: Option<NSApplicationActivationPolicy>,
|
||||||
default_menu: bool,
|
default_menu: bool,
|
||||||
activate_ignoring_other_apps: bool,
|
activate_ignoring_other_apps: bool,
|
||||||
run_loop: RunLoop,
|
run_loop: RunLoop,
|
||||||
|
|
@ -65,7 +65,7 @@ static GLOBAL: StaticMainThreadBound<OnceCell<Rc<AppState>>> =
|
||||||
impl AppState {
|
impl AppState {
|
||||||
pub(super) fn setup_global(
|
pub(super) fn setup_global(
|
||||||
mtm: MainThreadMarker,
|
mtm: MainThreadMarker,
|
||||||
activation_policy: NSApplicationActivationPolicy,
|
activation_policy: Option<NSApplicationActivationPolicy>,
|
||||||
default_menu: bool,
|
default_menu: bool,
|
||||||
activate_ignoring_other_apps: bool,
|
activate_ignoring_other_apps: bool,
|
||||||
) -> Rc<Self> {
|
) -> Rc<Self> {
|
||||||
|
|
@ -113,7 +113,11 @@ impl AppState {
|
||||||
// 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
|
||||||
// menu bar is initially unresponsive on macOS 10.15.
|
// menu bar is initially unresponsive on macOS 10.15.
|
||||||
app.setActivationPolicy(self.activation_policy);
|
// If no activation policy is explicitly provided, do not set it at all
|
||||||
|
// to allow the package manifest to define behavior via LSUIElement.
|
||||||
|
if self.activation_policy.is_some() {
|
||||||
|
app.setActivationPolicy(self.activation_policy.unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
app.activateIgnoringOtherApps(self.activate_ignoring_other_apps);
|
app.activateIgnoringOtherApps(self.activate_ignoring_other_apps);
|
||||||
|
|
|
||||||
|
|
@ -190,18 +190,14 @@ pub struct EventLoop {
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||||
pub(crate) struct PlatformSpecificEventLoopAttributes {
|
pub(crate) struct PlatformSpecificEventLoopAttributes {
|
||||||
pub(crate) activation_policy: ActivationPolicy,
|
pub(crate) activation_policy: Option<ActivationPolicy>,
|
||||||
pub(crate) default_menu: bool,
|
pub(crate) default_menu: bool,
|
||||||
pub(crate) activate_ignoring_other_apps: bool,
|
pub(crate) activate_ignoring_other_apps: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for PlatformSpecificEventLoopAttributes {
|
impl Default for PlatformSpecificEventLoopAttributes {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self { activation_policy: None, default_menu: true, activate_ignoring_other_apps: true }
|
||||||
activation_policy: Default::default(), // Regular
|
|
||||||
default_menu: true,
|
|
||||||
activate_ignoring_other_apps: true,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -223,9 +219,10 @@ impl EventLoop {
|
||||||
}
|
}
|
||||||
|
|
||||||
let activation_policy = match attributes.activation_policy {
|
let activation_policy = match attributes.activation_policy {
|
||||||
ActivationPolicy::Regular => NSApplicationActivationPolicy::Regular,
|
None => None,
|
||||||
ActivationPolicy::Accessory => NSApplicationActivationPolicy::Accessory,
|
Some(ActivationPolicy::Regular) => Some(NSApplicationActivationPolicy::Regular),
|
||||||
ActivationPolicy::Prohibited => NSApplicationActivationPolicy::Prohibited,
|
Some(ActivationPolicy::Accessory) => Some(NSApplicationActivationPolicy::Accessory),
|
||||||
|
Some(ActivationPolicy::Prohibited) => Some(NSApplicationActivationPolicy::Prohibited),
|
||||||
};
|
};
|
||||||
|
|
||||||
let app_state = AppState::setup_global(
|
let app_state = AppState::setup_global(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue