BOOL handling differs on M1 vs x64.
The M1 ruined me. Fixes building and running on Intel-based Macs.
This commit is contained in:
parent
724b40e5a8
commit
9511a5a82c
|
@ -38,7 +38,7 @@ use objc::{class, msg_send, sel, sel_impl};
|
||||||
use objc::runtime::Object;
|
use objc::runtime::Object;
|
||||||
use objc_id::Id;
|
use objc_id::Id;
|
||||||
|
|
||||||
use crate::foundation::{id, nil, YES, NO, BOOL, NSData, NSString, NSDictionary, NSNumber};
|
use crate::foundation::{id, nil, to_bool, YES, NO, BOOL, NSData, NSString, NSDictionary, NSNumber};
|
||||||
|
|
||||||
mod value;
|
mod value;
|
||||||
pub use value::Value;
|
pub use value::Value;
|
||||||
|
@ -244,10 +244,7 @@ impl UserDefaults {
|
||||||
msg_send![&*self.0, objectIsForcedForKey:key.into_inner()]
|
msg_send![&*self.0, objectIsForcedForKey:key.into_inner()]
|
||||||
};
|
};
|
||||||
|
|
||||||
match result {
|
to_bool(result)
|
||||||
YES => true,
|
|
||||||
NO => false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Blocks for any asynchronous updates to the defaults database and returns.
|
/// Blocks for any asynchronous updates to the defaults database and returns.
|
||||||
|
|
|
@ -17,7 +17,7 @@ use objc::{class, msg_send, sel, sel_impl};
|
||||||
use objc::runtime::Object;
|
use objc::runtime::Object;
|
||||||
use objc_id::Id;
|
use objc_id::Id;
|
||||||
|
|
||||||
use crate::foundation::{id, BOOL, YES, NO, NSUInteger};
|
use crate::foundation::{id, to_bool, BOOL, YES, NO, NSUInteger};
|
||||||
|
|
||||||
/// Wrapper for a retained `NSData` object.
|
/// Wrapper for a retained `NSData` object.
|
||||||
///
|
///
|
||||||
|
@ -70,10 +70,7 @@ impl NSData {
|
||||||
msg_send![obj, isKindOfClass:class!(NSData)]
|
msg_send![obj, isKindOfClass:class!(NSData)]
|
||||||
};
|
};
|
||||||
|
|
||||||
match result {
|
to_bool(result)
|
||||||
YES => true,
|
|
||||||
NO => false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the length of the underlying `NSData` bytes.
|
/// Returns the length of the underlying `NSData` bytes.
|
||||||
|
|
|
@ -42,6 +42,20 @@ pub use number::NSNumber;
|
||||||
mod string;
|
mod string;
|
||||||
pub use string::NSString;
|
pub use string::NSString;
|
||||||
|
|
||||||
|
/// Bool mapping types differ between ARM and x64. There's a number of places that we need to check
|
||||||
|
/// against BOOL results throughout the framework, and this just simplifies some mismatches.
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn to_bool(result: BOOL) -> bool {
|
||||||
|
match result {
|
||||||
|
YES => true,
|
||||||
|
NO => false,
|
||||||
|
|
||||||
|
//#[cfg(target_arch = "aarch64")]
|
||||||
|
#[cfg(not(target_arch = "aarch64"))]
|
||||||
|
_ => { std::unreachable!(); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// More or less maps over to Objective-C's `id` type, which... can really be anything.
|
/// More or less maps over to Objective-C's `id` type, which... can really be anything.
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
pub type id = *mut runtime::Object;
|
pub type id = *mut runtime::Object;
|
||||||
|
|
|
@ -5,7 +5,7 @@ use objc::{class, msg_send, sel, sel_impl};
|
||||||
use objc::runtime::Object;
|
use objc::runtime::Object;
|
||||||
use objc_id::Id;
|
use objc_id::Id;
|
||||||
|
|
||||||
use crate::foundation::{id, BOOL, YES, NO, NSInteger};
|
use crate::foundation::{id, to_bool, BOOL, YES, NO, NSInteger};
|
||||||
|
|
||||||
/// Wrapper for a retained `NSNumber` object.
|
/// Wrapper for a retained `NSNumber` object.
|
||||||
///
|
///
|
||||||
|
@ -90,10 +90,7 @@ impl NSNumber {
|
||||||
msg_send![&*self.0, boolValue]
|
msg_send![&*self.0, boolValue]
|
||||||
};
|
};
|
||||||
|
|
||||||
match result {
|
to_bool(result)
|
||||||
YES => true,
|
|
||||||
NO => false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A helper method for determining if a given `NSObject` is an `NSNumber`.
|
/// A helper method for determining if a given `NSObject` is an `NSNumber`.
|
||||||
|
@ -102,10 +99,7 @@ impl NSNumber {
|
||||||
msg_send![obj, isKindOfClass:class!(NSNumber)]
|
msg_send![obj, isKindOfClass:class!(NSNumber)]
|
||||||
};
|
};
|
||||||
|
|
||||||
match result {
|
to_bool(result)
|
||||||
YES => true,
|
|
||||||
NO => false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Consumes and returns the underlying `NSNumber`.
|
/// Consumes and returns the underlying `NSNumber`.
|
||||||
|
|
|
@ -5,7 +5,7 @@ use objc::{class, msg_send, sel, sel_impl};
|
||||||
use objc::runtime::Object;
|
use objc::runtime::Object;
|
||||||
use objc_id::Id;
|
use objc_id::Id;
|
||||||
|
|
||||||
use crate::foundation::{id, BOOL, YES, NO};
|
use crate::foundation::{id, to_bool, BOOL, YES, NO};
|
||||||
|
|
||||||
const UTF8_ENCODING: usize = 4;
|
const UTF8_ENCODING: usize = 4;
|
||||||
|
|
||||||
|
@ -38,11 +38,7 @@ impl NSString {
|
||||||
/// Utility method for checking whether an `NSObject` is an `NSString`.
|
/// Utility method for checking whether an `NSObject` is an `NSString`.
|
||||||
pub fn is(obj: id) -> bool {
|
pub fn is(obj: id) -> bool {
|
||||||
let result: BOOL = unsafe { msg_send![obj, isKindOfClass:class!(NSString)] };
|
let result: BOOL = unsafe { msg_send![obj, isKindOfClass:class!(NSString)] };
|
||||||
|
to_bool(result)
|
||||||
match result {
|
|
||||||
YES => true,
|
|
||||||
NO => false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Helper method for returning the UTF8 bytes for this `NSString`.
|
/// Helper method for returning the UTF8 bytes for this `NSString`.
|
||||||
|
|
|
@ -14,7 +14,7 @@ use objc::runtime::{Class, Object, Sel};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
use crate::foundation::{id, nil, BOOL, YES, NO, NSUInteger, NSArray, NSString};
|
use crate::foundation::{id, nil, to_bool, BOOL, YES, NO, NSUInteger, NSArray, NSString};
|
||||||
use crate::macos::app::{APP_PTR, AppDelegate};
|
use crate::macos::app::{APP_PTR, AppDelegate};
|
||||||
use crate::macos::printing::PrintSettings;
|
use crate::macos::printing::PrintSettings;
|
||||||
use crate::user_activity::UserActivity;
|
use crate::user_activity::UserActivity;
|
||||||
|
@ -105,10 +105,7 @@ extern fn did_update<T: AppDelegate>(this: &Object, _: Sel, _: id) {
|
||||||
/// Fires when the Application Delegate receives a
|
/// Fires when the Application Delegate receives a
|
||||||
/// `applicationShouldHandleReopen:hasVisibleWindows:` notification.
|
/// `applicationShouldHandleReopen:hasVisibleWindows:` notification.
|
||||||
extern fn should_handle_reopen<T: AppDelegate>(this: &Object, _: Sel, _: id, has_visible_windows: BOOL) -> BOOL {
|
extern fn should_handle_reopen<T: AppDelegate>(this: &Object, _: Sel, _: id, has_visible_windows: BOOL) -> BOOL {
|
||||||
match app::<T>(this).should_handle_reopen(match has_visible_windows {
|
match app::<T>(this).should_handle_reopen(to_bool(has_visible_windows)) {
|
||||||
YES => true,
|
|
||||||
NO => false
|
|
||||||
}) {
|
|
||||||
true => YES,
|
true => YES,
|
||||||
false => NO
|
false => NO
|
||||||
}
|
}
|
||||||
|
@ -266,10 +263,7 @@ extern fn print_files<T: AppDelegate>(this: &Object, _: Sel, _: id, files: id, s
|
||||||
|
|
||||||
let settings = PrintSettings::with_inner(settings);
|
let settings = PrintSettings::with_inner(settings);
|
||||||
|
|
||||||
app::<T>(this).print_files(files, settings, match show_print_panels {
|
app::<T>(this).print_files(files, settings, to_bool(show_print_panels)).into()
|
||||||
YES => true,
|
|
||||||
NO => false
|
|
||||||
}).into()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Called when the application's occlusion state has changed.
|
/// Called when the application's occlusion state has changed.
|
||||||
|
|
|
@ -18,7 +18,7 @@ use objc::runtime::Object;
|
||||||
use objc_id::ShareId;
|
use objc_id::ShareId;
|
||||||
|
|
||||||
use crate::color::Color;
|
use crate::color::Color;
|
||||||
use crate::foundation::{id, nil, YES, NO, NSString, NSInteger, NSUInteger};
|
use crate::foundation::{id, nil, to_bool, YES, NO, NSString, NSInteger, NSUInteger};
|
||||||
use crate::layout::traits::Layout;
|
use crate::layout::traits::Layout;
|
||||||
use crate::macos::toolbar::{Toolbar, ToolbarDelegate};
|
use crate::macos::toolbar::{Toolbar, ToolbarDelegate};
|
||||||
use crate::utils::{os, Controller};
|
use crate::utils::{os, Controller};
|
||||||
|
@ -322,22 +322,16 @@ impl<T> Window<T> {
|
||||||
|
|
||||||
/// Returns whether this window is opaque or not.
|
/// Returns whether this window is opaque or not.
|
||||||
pub fn is_opaque(&self) -> bool {
|
pub fn is_opaque(&self) -> bool {
|
||||||
unsafe {
|
to_bool(unsafe {
|
||||||
match msg_send![&*self.objc, isOpaque] {
|
msg_send![&*self.objc, isOpaque]
|
||||||
YES => true,
|
})
|
||||||
NO => false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns whether this window is miniaturized or not.
|
/// Returns whether this window is miniaturized or not.
|
||||||
pub fn is_miniaturized(&self) -> bool {
|
pub fn is_miniaturized(&self) -> bool {
|
||||||
unsafe {
|
to_bool(unsafe {
|
||||||
match msg_send![&*self.objc, isMiniaturized] {
|
msg_send![&*self.objc, isMiniaturized]
|
||||||
YES => true,
|
})
|
||||||
NO => false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Miniaturize this window.
|
/// Miniaturize this window.
|
||||||
|
@ -371,42 +365,30 @@ impl<T> Window<T> {
|
||||||
/// space. For nonvisible windows, it indicates whether ordering the window onscreen would cause it to
|
/// space. For nonvisible windows, it indicates whether ordering the window onscreen would cause it to
|
||||||
/// be on the active space._
|
/// be on the active space._
|
||||||
pub fn is_on_active_space(&self) -> bool {
|
pub fn is_on_active_space(&self) -> bool {
|
||||||
unsafe {
|
to_bool(unsafe {
|
||||||
match msg_send![&*self.objc, isOnActiveSpace] {
|
msg_send![&*self.objc, isOnActiveSpace]
|
||||||
YES => true,
|
})
|
||||||
NO => false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns whether this window is visible or not.
|
/// Returns whether this window is visible or not.
|
||||||
pub fn is_visible(&self) -> bool {
|
pub fn is_visible(&self) -> bool {
|
||||||
unsafe {
|
to_bool(unsafe {
|
||||||
match msg_send![&*self.objc, isVisible] {
|
msg_send![&*self.objc, isVisible]
|
||||||
YES => true,
|
})
|
||||||
NO => false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns whether this window is the key or not.
|
/// Returns whether this window is the key or not.
|
||||||
pub fn is_key(&self) -> bool {
|
pub fn is_key(&self) -> bool {
|
||||||
unsafe {
|
to_bool(unsafe {
|
||||||
match msg_send![&*self.objc, isKeyWindow] {
|
msg_send![&*self.objc, isKeyWindow]
|
||||||
YES => true,
|
})
|
||||||
NO => false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns whether this window can become the key window.
|
/// Returns whether this window can become the key window.
|
||||||
pub fn can_become_key(&self) -> bool {
|
pub fn can_become_key(&self) -> bool {
|
||||||
unsafe {
|
to_bool(unsafe {
|
||||||
match msg_send![&*self.objc, canBecomeKeyWindow] {
|
msg_send![&*self.objc, canBecomeKeyWindow]
|
||||||
YES => true,
|
})
|
||||||
NO => false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Make this window the key window.
|
/// Make this window the key window.
|
||||||
|
@ -426,22 +408,16 @@ impl<T> Window<T> {
|
||||||
|
|
||||||
/// Returns if this is the main window or not.
|
/// Returns if this is the main window or not.
|
||||||
pub fn is_main_window(&self) -> bool {
|
pub fn is_main_window(&self) -> bool {
|
||||||
unsafe {
|
to_bool(unsafe {
|
||||||
match msg_send![&*self.objc, isMainWindow] {
|
msg_send![&*self.objc, isMainWindow]
|
||||||
YES => true,
|
})
|
||||||
NO => false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns if this can become the main window.
|
/// Returns if this can become the main window.
|
||||||
pub fn can_become_main_window(&self) -> bool {
|
pub fn can_become_main_window(&self) -> bool {
|
||||||
unsafe {
|
to_bool(unsafe {
|
||||||
match msg_send![&*self.objc, canBecomeMainWindow] {
|
msg_send![&*self.objc, canBecomeMainWindow]
|
||||||
YES => true,
|
})
|
||||||
NO => false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set whether this window should be excluded from the top-level "Windows" menu.
|
/// Set whether this window should be excluded from the top-level "Windows" menu.
|
||||||
|
|
16
src/utils.rs
16
src/utils.rs
|
@ -23,9 +23,12 @@ pub mod os {
|
||||||
/// In rare cases we need to check whether something is a specific version of macOS. This is a
|
/// In rare cases we need to check whether something is a specific version of macOS. This is a
|
||||||
/// runtime check thhat returns a boolean indicating whether the current version is a minimum target.
|
/// runtime check thhat returns a boolean indicating whether the current version is a minimum target.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn is_minimum_version(major: u64) -> bool {
|
pub fn is_minimum_version(minimum_major: u64) -> bool {
|
||||||
|
//println!("Looking for: {}", major);
|
||||||
|
//println!("VERSION: {}", OS_VERSION.version());
|
||||||
|
|
||||||
match OS_VERSION.version() {
|
match OS_VERSION.version() {
|
||||||
Version::Semantic(maj, _, _) => major >= *maj,
|
Version::Semantic(os_major, _, _) => { *os_major >= minimum_major },
|
||||||
_ => false
|
_ => false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,12 +143,3 @@ pub fn activate_cocoa_multithreading() {
|
||||||
let _: () = msg_send![thread, start];
|
let _: () = msg_send![thread, start];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Utility method for turning an Objective-C `BOOL` into a Rust `bool`.
|
|
||||||
#[inline]
|
|
||||||
pub fn as_bool(value: BOOL) -> bool {
|
|
||||||
match value {
|
|
||||||
YES => true,
|
|
||||||
NO => false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue