diff --git a/src/platform_impl/ios/mod.rs b/src/platform_impl/ios/mod.rs index 06ce41ace..ebd962b31 100644 --- a/src/platform_impl/ios/mod.rs +++ b/src/platform_impl/ios/mod.rs @@ -65,7 +65,8 @@ // window size/position. macro_rules! assert_main_thread { ($($t:tt)*) => { - if !msg_send![class!(NSThread), isMainThread] { + let is_main_thread: ::objc::runtime::BOOL = msg_send!(class!(NSThread), isMainThread); + if is_main_thread == ::objc::runtime::NO { panic!($($t)*); } }; diff --git a/src/platform_impl/ios/window.rs b/src/platform_impl/ios/window.rs index f0fee5dc5..8fd8f28ba 100644 --- a/src/platform_impl/ios/window.rs +++ b/src/platform_impl/ios/window.rs @@ -229,7 +229,7 @@ impl Inner { let uiscreen = match monitor { Some(Fullscreen::Exclusive(video_mode)) => { let uiscreen = video_mode.video_mode.monitor.ui_screen() as id; - let () = msg_send![uiscreen, setCurrentMode: video_mode.video_mode.screen_mode]; + let () = msg_send![uiscreen, setCurrentMode: video_mode.video_mode.screen_mode.0]; uiscreen } Some(Fullscreen::Borderless(monitor)) => monitor diff --git a/src/platform_impl/macos/app_state.rs b/src/platform_impl/macos/app_state.rs index 4fcc01f4b..bf8f0bc9e 100644 --- a/src/platform_impl/macos/app_state.rs +++ b/src/platform_impl/macos/app_state.rs @@ -20,9 +20,7 @@ use cocoa::{ base::{id, nil}, foundation::{NSAutoreleasePool, NSSize}, }; -use objc::runtime::YES; - -use objc::runtime::Object; +use objc::runtime::{Object, BOOL, NO, YES}; use crate::{ dpi::LogicalSize, @@ -347,14 +345,16 @@ impl AppState { } pub fn queue_event(wrapper: EventWrapper) { - if !unsafe { msg_send![class!(NSThread), isMainThread] } { + let is_main_thread: BOOL = unsafe { msg_send!(class!(NSThread), isMainThread) }; + if is_main_thread == NO { panic!("Event queued from different thread: {:#?}", wrapper); } HANDLER.events().push_back(wrapper); } pub fn queue_events(mut wrappers: VecDeque) { - if !unsafe { msg_send![class!(NSThread), isMainThread] } { + let is_main_thread: BOOL = unsafe { msg_send!(class!(NSThread), isMainThread) }; + if is_main_thread == NO { panic!("Events queued from different thread: {:#?}", wrappers); } HANDLER.events().append(&mut wrappers); @@ -388,8 +388,9 @@ impl AppState { let dialog_open = if window_count > 1 { let dialog: id = msg_send![windows, lastObject]; - let is_main_window: bool = msg_send![dialog, isMainWindow]; - msg_send![dialog, isVisible] && !is_main_window + let is_main_window: BOOL = msg_send![dialog, isMainWindow]; + let is_visible: BOOL = msg_send![dialog, isVisible]; + is_visible != NO && is_main_window == NO } else { false }; @@ -404,9 +405,9 @@ impl AppState { pool.drain(); if window_count > 0 { - let window: id = msg_send![windows, objectAtIndex:0]; - let window_has_focus = msg_send![window, isKeyWindow]; - if !dialog_open && window_has_focus && dialog_is_closing { + let window: id = msg_send![windows, firstObject]; + let window_has_focus: BOOL = msg_send![window, isKeyWindow]; + if !dialog_open && window_has_focus != NO && dialog_is_closing { HANDLER.dialog_is_closing.store(false, Ordering::SeqCst); } if dialog_open { diff --git a/src/platform_impl/macos/event_loop.rs b/src/platform_impl/macos/event_loop.rs index 7ff8faa70..353dedc1b 100644 --- a/src/platform_impl/macos/event_loop.rs +++ b/src/platform_impl/macos/event_loop.rs @@ -14,9 +14,9 @@ use std::{ }; use cocoa::{ - appkit::{NSApp, NSEventType::NSApplicationDefined}, - base::{id, nil, YES}, - foundation::{NSAutoreleasePool, NSPoint}, + appkit::{NSApp, NSEventModifierFlags, NSEventSubtype, NSEventType::NSApplicationDefined}, + base::{id, nil, BOOL, NO, YES}, + foundation::{NSAutoreleasePool, NSInteger, NSPoint, NSTimeInterval}, }; use crossbeam_channel::{self as channel, Receiver, Sender}; use scopeguard::defer; @@ -107,7 +107,8 @@ pub struct EventLoop { impl EventLoop { pub fn new() -> Self { let delegate = unsafe { - if !msg_send![class!(NSThread), isMainThread] { + let is_main_thread: BOOL = msg_send!(class!(NSThread), isMainThread); + if is_main_thread == NO { panic!("On macOS, `EventLoop` must be created on the main thread!"); } @@ -200,13 +201,13 @@ pub unsafe fn post_dummy_event(target: id) { event_class, otherEventWithType: NSApplicationDefined location: NSPoint::new(0.0, 0.0) - modifierFlags: 0 - timestamp: 0 - windowNumber: 0 + modifierFlags: NSEventModifierFlags::empty() + timestamp: 0 as NSTimeInterval + windowNumber: 0 as NSInteger context: nil - subtype: 0 - data1: 0 - data2: 0 + subtype: NSEventSubtype::NSWindowExposedEventType + data1: 0 as NSInteger + data2: 0 as NSInteger ]; let () = msg_send![target, postEvent: dummy_event atStart: YES]; } diff --git a/src/platform_impl/macos/ffi.rs b/src/platform_impl/macos/ffi.rs index 26958aafa..f3cd43328 100644 --- a/src/platform_impl/macos/ffi.rs +++ b/src/platform_impl/macos/ffi.rs @@ -112,6 +112,7 @@ pub const kCGCursorWindowLevelKey: NSInteger = 19; pub const kCGNumberOfWindowLevelKeys: NSInteger = 20; #[derive(Debug, Clone, Copy)] +#[repr(isize)] pub enum NSWindowLevel { NSNormalWindowLevel = kCGBaseWindowLevelKey as _, NSFloatingWindowLevel = kCGFloatingWindowLevelKey as _, diff --git a/src/platform_impl/macos/util/async.rs b/src/platform_impl/macos/util/async.rs index d6e2b3165..00521e13c 100644 --- a/src/platform_impl/macos/util/async.rs +++ b/src/platform_impl/macos/util/async.rs @@ -15,7 +15,7 @@ use dispatch::Queue; use menu::Menu; use objc::{ rc::autoreleasepool, - runtime::{NO, YES}, + runtime::{BOOL, NO, YES}, }; use crate::{ @@ -57,7 +57,8 @@ pub unsafe fn set_style_mask_async(ns_window: id, ns_view: id, mask: NSWindowSty }); } pub unsafe fn set_style_mask_sync(ns_window: id, ns_view: id, mask: NSWindowStyleMask) { - if msg_send![class!(NSThread), isMainThread] { + let is_main_thread: BOOL = msg_send!(class!(NSThread), isMainThread); + if is_main_thread != NO { set_style_mask(ns_window, ns_view, mask); } else { let ns_window = MainThreadSafe(ns_window); diff --git a/src/platform_impl/macos/util/mod.rs b/src/platform_impl/macos/util/mod.rs index ee904f6e6..05b758109 100644 --- a/src/platform_impl/macos/util/mod.rs +++ b/src/platform_impl/macos/util/mod.rs @@ -48,7 +48,7 @@ impl IdRef { #[allow(dead_code)] pub fn retain(inner: id) -> IdRef { if inner != nil { - let () = unsafe { msg_send![inner, retain] }; + let _: id = unsafe { msg_send![inner, retain] }; } IdRef(inner) } @@ -84,10 +84,7 @@ impl Deref for IdRef { impl Clone for IdRef { fn clone(&self) -> IdRef { - if self.0 != nil { - let _: id = unsafe { msg_send![self.0, retain] }; - } - IdRef(self.0) + IdRef::retain(self.0) } } @@ -147,8 +144,8 @@ pub unsafe fn app_name() -> Option { } pub unsafe fn superclass<'a>(this: &'a Object) -> &'a Class { - let superclass: id = msg_send![this, superclass]; - &*(superclass as *const _) + let superclass: *const Class = msg_send![this, superclass]; + &*superclass } pub unsafe fn create_input_context(view: id) -> IdRef { diff --git a/src/platform_impl/macos/view.rs b/src/platform_impl/macos/view.rs index 92d946141..764260aad 100644 --- a/src/platform_impl/macos/view.rs +++ b/src/platform_impl/macos/view.rs @@ -5,7 +5,7 @@ use std::{ boxed::Box, collections::{HashSet, VecDeque}, os::raw::*, - slice, str, + ptr, slice, str, sync::{Arc, Mutex, Weak}, }; @@ -349,7 +349,7 @@ extern "C" fn view_did_move_to_window(this: &Object, _sel: Sel) { let tracking_rect: NSInteger = msg_send![this, addTrackingRect:rect owner:this - userData:nil + userData:ptr::null_mut::() assumeInside:NO ]; state.tracking_rect = Some(tracking_rect); @@ -370,7 +370,7 @@ extern "C" fn frame_did_change(this: &Object, _sel: Sel, _event: id) { let tracking_rect: NSInteger = msg_send![this, addTrackingRect:rect owner:this - userData:nil + userData:ptr::null_mut::() assumeInside:NO ]; @@ -462,8 +462,8 @@ extern "C" fn set_marked_text( trace!("Triggered `setMarkedText`"); unsafe { let marked_text_ref = clear_marked_text(this); - let has_attr = msg_send![string, isKindOfClass: class!(NSAttributedString)]; - if has_attr { + let has_attr: BOOL = msg_send![string, isKindOfClass: class!(NSAttributedString)]; + if has_attr != NO { marked_text_ref.initWithAttributedString(string); } else { marked_text_ref.initWithString(string); @@ -538,8 +538,8 @@ extern "C" fn insert_text(this: &Object, _sel: Sel, string: id, _replacement_ran let state_ptr: *mut c_void = *this.get_ivar("taoState"); let state = &mut *(state_ptr as *mut ViewState); - let has_attr = msg_send![string, isKindOfClass: class!(NSAttributedString)]; - let characters = if has_attr { + let has_attr: BOOL = msg_send![string, isKindOfClass: class!(NSAttributedString)]; + let characters = if has_attr != NO { // This is a *mut NSAttributedString msg_send![string, string] } else { @@ -1006,7 +1006,7 @@ fn mouse_motion(this: &Object, event: id) { || view_point.x > view_rect.size.width || view_point.y > view_rect.size.height { - let mouse_buttons_down: NSInteger = msg_send![class!(NSEvent), pressedMouseButtons]; + let mouse_buttons_down: NSUInteger = msg_send![class!(NSEvent), pressedMouseButtons]; if mouse_buttons_down == 0 { // Point is outside of the client area (view) and no buttons are pressed return; diff --git a/src/platform_impl/macos/window.rs b/src/platform_impl/macos/window.rs index c38bc4847..c5f18fdf2 100644 --- a/src/platform_impl/macos/window.rs +++ b/src/platform_impl/macos/window.rs @@ -4,6 +4,7 @@ use raw_window_handle::{AppKitHandle, RawWindowHandle}; use std::{ collections::VecDeque, + convert::TryInto, f64, os::raw::c_void, sync::{ @@ -38,7 +39,7 @@ use cocoa::{ NSWindowStyleMask, }, base::{id, nil}, - foundation::{NSAutoreleasePool, NSDictionary, NSPoint, NSRect, NSSize}, + foundation::{NSAutoreleasePool, NSDictionary, NSPoint, NSRect, NSSize, NSUInteger}, }; use core_graphics::display::{CGDisplay, CGDisplayMode}; use objc::{ @@ -347,7 +348,8 @@ impl UnownedWindow { pl_attribs: PlatformSpecificWindowBuilderAttributes, ) -> Result<(Arc, IdRef), RootOsError> { unsafe { - if !msg_send![class!(NSThread), isMainThread] { + let is_main_thread: BOOL = msg_send!(class!(NSThread), isMainThread); + if is_main_thread == NO { panic!("Windows can only be created on the main thread on macOS"); } } @@ -1089,9 +1091,9 @@ impl UnownedWindow { let desc = NSScreen::deviceDescription(screen); let key = util::ns_string_id_ref("NSScreenNumber"); let value = NSDictionary::valueForKey_(desc, *key); - let display_id = msg_send![value, unsignedIntegerValue]; + let display_id: NSUInteger = msg_send![value, unsignedIntegerValue]; RootMonitorHandle { - inner: MonitorHandle::new(display_id), + inner: MonitorHandle::new(display_id.try_into().unwrap()), } } }