From 68f0f99de34c39737b214ae47374ec617edf1f4a Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Tue, 21 Jan 2025 23:20:21 +0100 Subject: [PATCH] fix(macos): Remove internal `From` implementation Removes `impl From for NSApplicationActivationPolicy`. This is needed to avoid publicly exposing a dependency on cocoa, which will allow using `objc2` in the future. --- .changes/remove-from-activation-policy.md | 5 +++++ src/platform/macos.rs | 25 ++++++++--------------- 2 files changed, 14 insertions(+), 16 deletions(-) create mode 100644 .changes/remove-from-activation-policy.md diff --git a/.changes/remove-from-activation-policy.md b/.changes/remove-from-activation-policy.md new file mode 100644 index 000000000..9d9b90e19 --- /dev/null +++ b/.changes/remove-from-activation-policy.md @@ -0,0 +1,5 @@ +--- +tao: minor +--- + +macOS: Remove `From` implementation for `cocoa::appkit::NSApplicationActivationPolicy`. diff --git a/src/platform/macos.rs b/src/platform/macos.rs index 932e8127f..4ffec9f94 100644 --- a/src/platform/macos.rs +++ b/src/platform/macos.rs @@ -14,11 +14,6 @@ use crate::{ window::{Window, WindowBuilder}, }; -use cocoa::appkit::{ - NSApplicationActivationPolicy, NSApplicationActivationPolicyAccessory, - NSApplicationActivationPolicyProhibited, NSApplicationActivationPolicyRegular, -}; - /// Additional methods on `Window` that are specific to MacOS. pub trait WindowExtMacOS { /// Returns a pointer to the cocoa `NSWindow` that is used by this window. @@ -189,16 +184,6 @@ impl Default for ActivationPolicy { } } -impl From for NSApplicationActivationPolicy { - fn from(act_pol: ActivationPolicy) -> Self { - match act_pol { - ActivationPolicy::Regular => NSApplicationActivationPolicyRegular, - ActivationPolicy::Accessory => NSApplicationActivationPolicyAccessory, - ActivationPolicy::Prohibited => NSApplicationActivationPolicyProhibited, - } - } -} - /// Additional methods on `WindowBuilder` that are specific to MacOS. /// /// **Note:** Properties dealing with the titlebar will be overwritten by the `with_decorations` method @@ -421,9 +406,17 @@ impl EventLoopWindowTargetExtMacOS for EventLoopWindowTarget { } fn set_activation_policy_at_runtime(&self, activation_policy: ActivationPolicy) { + use cocoa::appkit; + let cls = objc::runtime::Class::get("NSApplication").unwrap(); let app: cocoa::base::id = unsafe { msg_send![cls, sharedApplication] }; - let ns_activation_policy: NSApplicationActivationPolicy = activation_policy.into(); + + let ns_activation_policy = match activation_policy { + ActivationPolicy::Regular => appkit::NSApplicationActivationPolicyRegular, + ActivationPolicy::Accessory => appkit::NSApplicationActivationPolicyAccessory, + ActivationPolicy::Prohibited => appkit::NSApplicationActivationPolicyProhibited, + }; + unsafe { msg_send![app, setActivationPolicy: ns_activation_policy] } }