Skip to content

Commit

Permalink
Fix a few unsound message sends
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Jul 31, 2023
1 parent cc744a2 commit cd0a306
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cocoa/examples/nsvisualeffectview_blur.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fn main() {
blurred_view.setState_(NSVisualEffectState::FollowsWindowActiveState);
blurred_view.setAutoresizingMask_(NSViewWidthSizable | NSViewHeightSizable);

let _: () = msg_send![ns_view, addSubview: blurred_view positioned: NSWindowOrderingMode::NSWindowBelow relativeTo: 0];
let _: () = msg_send![ns_view, addSubview: blurred_view positioned: NSWindowOrderingMode::NSWindowBelow relativeTo: nil];

app.run();
}
Expand Down
36 changes: 21 additions & 15 deletions cocoa/src/appkit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use foundation::{
NSInteger, NSPoint, NSRange, NSRect, NSRectEdge, NSSize, NSTimeInterval, NSUInteger,
};
use libc;
use objc2::encode::{Encode, Encoding};

pub use core_graphics::base::CGFloat;
pub use core_graphics::geometry::CGPoint;
Expand Down Expand Up @@ -426,29 +427,29 @@ impl_Encode!(NSBezelStyle, u64);

// https://developer.apple.com/documentation/appkit/nsvisualeffectview/blendingmode
#[allow(dead_code)]
#[repr(u64)]
#[repr(isize)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum NSVisualEffectBlendingMode {
BehindWindow = 0,
WithinWindow = 1,
}

impl_Encode!(NSVisualEffectBlendingMode, u64);
impl_Encode!(NSVisualEffectBlendingMode, isize);

// https://developer.apple.com/documentation/appkit/nsvisualeffectview/state
#[allow(dead_code)]
#[repr(u64)]
#[repr(isize)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum NSVisualEffectState {
FollowsWindowActiveState = 0,
Active = 1,
Inactive = 2,
}

impl_Encode!(NSVisualEffectState, u64);
impl_Encode!(NSVisualEffectState, isize);

/// <https://developer.apple.com/documentation/appkit/nsvisualeffectview/material>
#[repr(u64)]
#[repr(isize)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum NSVisualEffectMaterial {
/// A default material for the view's effectiveAppearance.
Expand Down Expand Up @@ -484,7 +485,7 @@ pub enum NSVisualEffectMaterial {
UnderPageBackground = 22,
}

impl_Encode!(NSVisualEffectMaterial, u64);
impl_Encode!(NSVisualEffectMaterial, isize);

// macOS 10.10+ - https://developer.apple.com/documentation/appkit/nsvisualeffectview
#[allow(non_snake_case)]
Expand Down Expand Up @@ -587,7 +588,7 @@ pub trait NSApplication: Sized {

unsafe fn mainMenu(self) -> id;
unsafe fn setActivationPolicy_(self, policy: NSApplicationActivationPolicy) -> BOOL;
unsafe fn setPresentationOptions_(self, options: NSApplicationPresentationOptions) -> BOOL;
unsafe fn setPresentationOptions_(self, options: NSApplicationPresentationOptions);
unsafe fn presentationOptions_(self) -> NSApplicationPresentationOptions;
unsafe fn setMainMenu_(self, menu: id);
unsafe fn setServicesMenu_(self, menu: id);
Expand Down Expand Up @@ -618,7 +619,7 @@ impl NSApplication for id {
msg_send![self, setActivationPolicy: policy as NSInteger]
}

unsafe fn setPresentationOptions_(self, options: NSApplicationPresentationOptions) -> BOOL {
unsafe fn setPresentationOptions_(self, options: NSApplicationPresentationOptions) {
msg_send![self, setPresentationOptions:options.bits]
}

Expand Down Expand Up @@ -4580,6 +4581,13 @@ pub trait NSColorSpace: Sized {
unsafe fn localizedName(self) -> id;
}

#[repr(transparent)]
struct CGColorSpaceRef(*const c_void);

unsafe impl Encode for CGColorSpaceRef {
const ENCODING: Encoding = Encoding::Pointer(&Encoding::Struct("CGColorSpace", &[]));
}

impl NSColorSpace for id {
unsafe fn deviceRGBColorSpace(_: Self) -> id {
msg_send![class!(NSColorSpace), deviceRGBColorSpace]
Expand Down Expand Up @@ -4622,14 +4630,12 @@ impl NSColorSpace for id {
msg_send![class!(NSColorSpace), alloc]
}

unsafe fn initWithCGColorSpace_(
self,
cg_color_space: *const c_void, /* (CGColorSpaceRef) */
) -> id {
msg_send![self, initWithCGColorSpace: cg_color_space]
unsafe fn initWithCGColorSpace_(self, cg_color_space: *const c_void) -> id {
msg_send![self, initWithCGColorSpace: CGColorSpaceRef(cg_color_space)]
}
unsafe fn CGColorSpace(self) -> *const c_void /* (CGColorSpaceRef) */ {
msg_send![self, CGColorSpace]
unsafe fn CGColorSpace(self) -> *const c_void {
let res: CGColorSpaceRef = msg_send![self, CGColorSpace];
res.0
}
unsafe fn localizedName(self) -> id {
msg_send![self, localizedName]
Expand Down

0 comments on commit cd0a306

Please sign in to comment.