mirror of
https://github.com/rust-windowing/winit.git
synced 2026-09-02 14:50:04 -04:00
Prevent winit from overriding LSUIElement in package manifests (#3920)
This commit is contained in:
@@ -44,3 +44,8 @@ changelog entry.
|
|||||||
|
|
||||||
- On macOS, add `WindowExtMacOS::set_borderless_game` and `WindowAttributesExtMacOS::with_borderless_game`
|
- On macOS, add `WindowExtMacOS::set_borderless_game` and `WindowAttributesExtMacOS::with_borderless_game`
|
||||||
to fully disable the menu bar and dock in Borderless Fullscreen as commonly done in games.
|
to fully disable the menu bar and dock in Borderless Fullscreen as commonly done in games.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- On MacOS, package manifest definitions of `LSUIElement` will no longer be overridden with the
|
||||||
|
default activation policy, unless explicitly provided during initialization.
|
||||||
|
|||||||
@@ -175,14 +175,12 @@ impl WindowExtMacOS for Window {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn set_borderless_game(&self, borderless_game: bool) {
|
fn set_borderless_game(&self, borderless_game: bool) {
|
||||||
let window = self.as_any().downcast_ref::<crate::platform_impl::Window>().unwrap();
|
self.window.maybe_wait_on_main(|w| w.set_borderless_game(borderless_game))
|
||||||
window.maybe_wait_on_main(|w| w.set_borderless_game(borderless_game))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn is_borderless_game(&self) -> bool {
|
fn is_borderless_game(&self) -> bool {
|
||||||
let window = self.as_any().downcast_ref::<crate::platform_impl::Window>().unwrap();
|
self.window.maybe_wait_on_main(|w| w.is_borderless_game())
|
||||||
window.maybe_wait_on_main(|w| w.is_borderless_game())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -313,9 +311,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
|
||||||
///
|
///
|
||||||
@@ -367,7 +368,7 @@ pub trait EventLoopBuilderExtMacOS {
|
|||||||
impl<T> EventLoopBuilderExtMacOS for EventLoopBuilder<T> {
|
impl<T> EventLoopBuilderExtMacOS for EventLoopBuilder<T> {
|
||||||
#[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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,12 @@ use crate::window::WindowId as RootWindowId;
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(super) struct AppState {
|
pub(super) struct AppState {
|
||||||
activation_policy: NSApplicationActivationPolicy,
|
// <<<<<<< HEAD:src/platform_impl/macos/app_state.rs
|
||||||
|
// activation_policy: NSApplicationActivationPolicy,
|
||||||
|
// =======
|
||||||
|
activation_policy: Option<NSApplicationActivationPolicy>,
|
||||||
|
// >>>>>>> 7e819bb2 (Prevent winit from overriding LSUIElement in package manifests
|
||||||
|
// (#3920)):src/platform_impl/apple/appkit/app_state.rs
|
||||||
default_menu: bool,
|
default_menu: bool,
|
||||||
activate_ignoring_other_apps: bool,
|
activate_ignoring_other_apps: bool,
|
||||||
run_loop: RunLoop,
|
run_loop: RunLoop,
|
||||||
@@ -74,7 +79,7 @@ declare_class!(
|
|||||||
impl ApplicationDelegate {
|
impl ApplicationDelegate {
|
||||||
pub(super) fn new(
|
pub(super) fn new(
|
||||||
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,
|
||||||
) -> Retained<Self> {
|
) -> Retained<Self> {
|
||||||
@@ -111,7 +116,11 @@ impl ApplicationDelegate {
|
|||||||
// 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.ivars().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 let Some(activation_policy) = self.ivars().activation_policy {
|
||||||
|
app.setActivationPolicy(activation_policy);
|
||||||
|
}
|
||||||
|
|
||||||
window_activation_hack(&app);
|
window_activation_hack(&app);
|
||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
|
|||||||
@@ -202,18 +202,14 @@ pub struct EventLoop<T: 'static> {
|
|||||||
|
|
||||||
#[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,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,9 +231,10 @@ impl<T> EventLoop<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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 delegate = ApplicationDelegate::new(
|
let delegate = ApplicationDelegate::new(
|
||||||
mtm,
|
mtm,
|
||||||
|
|||||||
Reference in New Issue
Block a user