Skip to content

Commit

Permalink
fix(macos): Remove internal From implementation
Browse files Browse the repository at this point in the history
Removes `impl From<ActivationPolicy> for NSApplicationActivationPolicy`.

This is needed to avoid publicly exposing a dependency on cocoa, which
will allow using `objc2` in the future.
  • Loading branch information
madsmtm committed Jan 21, 2025
1 parent 543e117 commit 68f0f99
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changes/remove-from-activation-policy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
tao: minor
---

macOS: Remove `From<ActivationPolicy>` implementation for `cocoa::appkit::NSApplicationActivationPolicy`.
25 changes: 9 additions & 16 deletions src/platform/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -189,16 +184,6 @@ impl Default for ActivationPolicy {
}
}

impl From<ActivationPolicy> 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
Expand Down Expand Up @@ -421,9 +406,17 @@ impl<T> EventLoopWindowTargetExtMacOS for EventLoopWindowTarget<T> {
}

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] }
}

Expand Down

0 comments on commit 68f0f99

Please sign in to comment.