diff --git a/Cargo.toml b/Cargo.toml index 7f5a8ae0..8028f0ed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -74,14 +74,14 @@ ndk-sys = "0.4.0" [target.'cfg(any(target_os = "ios", target_os = "macos"))'.dependencies] core-foundation = "0.9.3" -objc2 = "0.4.0" +objc2 = "0.4.1" [target.'cfg(target_os = "macos")'.dependencies] core-graphics = "0.22.3" dispatch = "0.2.0" [target.'cfg(target_os = "macos")'.dependencies.icrate] -version = "0.0.3" +version = "0.0.4" features = [ "Foundation", "Foundation_NSArray", @@ -96,7 +96,7 @@ features = [ ] [target.'cfg(target_os = "ios")'.dependencies.icrate] -version = "0.0.3" +version = "0.0.4" features = [ "Foundation", "Foundation_NSArray", diff --git a/src/platform_impl/ios/app_state.rs b/src/platform_impl/ios/app_state.rs index 822ce60b..9ae2db4b 100644 --- a/src/platform_impl/ios/app_state.rs +++ b/src/platform_impl/ios/app_state.rs @@ -18,7 +18,7 @@ use core_foundation::runloop::{ }; use icrate::Foundation::{CGRect, CGSize, NSInteger, NSProcessInfo}; use objc2::rc::Id; -use objc2::runtime::Object; +use objc2::runtime::AnyObject; use objc2::{msg_send, sel}; use once_cell::sync::Lazy; @@ -538,7 +538,7 @@ pub unsafe fn did_finish_launching() { // completed. This may result in incorrect visual appearance. // ``` let screen = window.screen(); - let _: () = msg_send![&window, setScreen: ptr::null::()]; + let _: () = msg_send![&window, setScreen: ptr::null::()]; window.setScreen(&screen); let controller = window.rootViewController(); diff --git a/src/platform_impl/ios/view.rs b/src/platform_impl/ios/view.rs index 6e2ad3bb..b097d216 100644 --- a/src/platform_impl/ios/view.rs +++ b/src/platform_impl/ios/view.rs @@ -5,7 +5,7 @@ use std::ptr::NonNull; use icrate::Foundation::{CGFloat, CGRect, MainThreadMarker, NSObject, NSObjectProtocol, NSSet}; use objc2::declare::{Ivar, IvarDrop}; use objc2::rc::Id; -use objc2::runtime::Class; +use objc2::runtime::AnyClass; use objc2::{declare_class, extern_methods, msg_send, msg_send_id, mutability, ClassType}; use super::uikit::{ @@ -167,7 +167,7 @@ extern_methods!( // TODO: Allow the user to customize this #[method(layerClass)] - pub(crate) fn layerClass() -> &'static Class; + pub(crate) fn layerClass() -> &'static AnyClass; } ); diff --git a/src/platform_impl/ios/window.rs b/src/platform_impl/ios/window.rs index 71875be6..710e08ea 100644 --- a/src/platform_impl/ios/window.rs +++ b/src/platform_impl/ios/window.rs @@ -8,7 +8,7 @@ use std::{ use icrate::Foundation::{CGFloat, CGPoint, CGRect, CGSize, MainThreadMarker}; use objc2::rc::Id; -use objc2::runtime::Object; +use objc2::runtime::AnyObject; use objc2::{class, msg_send}; use raw_window_handle::{RawDisplayHandle, RawWindowHandle, UiKitDisplayHandle, UiKitWindowHandle}; @@ -646,8 +646,8 @@ impl From for WindowId { unsafe impl Send for WindowId {} unsafe impl Sync for WindowId {} -impl From<&Object> for WindowId { - fn from(window: &Object) -> WindowId { +impl From<&AnyObject> for WindowId { + fn from(window: &AnyObject) -> WindowId { WindowId { window: window as *const _ as _, } diff --git a/src/platform_impl/macos/app_delegate.rs b/src/platform_impl/macos/app_delegate.rs index 4b3be65f..4d398929 100644 --- a/src/platform_impl/macos/app_delegate.rs +++ b/src/platform_impl/macos/app_delegate.rs @@ -3,7 +3,7 @@ use std::ptr::NonNull; use icrate::Foundation::NSObject; use objc2::declare::{IvarBool, IvarEncode}; use objc2::rc::Id; -use objc2::runtime::Object; +use objc2::runtime::AnyObject; use objc2::{declare_class, msg_send, msg_send_id, mutability, ClassType}; use super::app_state::AppState; @@ -43,7 +43,7 @@ declare_class!( } #[method(applicationDidFinishLaunching:)] - fn did_finish_launching(&self, _sender: Option<&Object>) { + fn did_finish_launching(&self, _sender: Option<&AnyObject>) { trace_scope!("applicationDidFinishLaunching:"); AppState::launched( *self.activation_policy, @@ -53,7 +53,7 @@ declare_class!( } #[method(applicationWillTerminate:)] - fn will_terminate(&self, _sender: Option<&Object>) { + fn will_terminate(&self, _sender: Option<&AnyObject>) { trace_scope!("applicationWillTerminate:"); // TODO: Notify every window that it will be destroyed, like done in iOS? AppState::exit(); diff --git a/src/platform_impl/macos/appkit/application.rs b/src/platform_impl/macos/appkit/application.rs index 952f49d1..f5f2e77d 100644 --- a/src/platform_impl/macos/appkit/application.rs +++ b/src/platform_impl/macos/appkit/application.rs @@ -1,6 +1,6 @@ use icrate::Foundation::{MainThreadMarker, NSArray, NSInteger, NSObject, NSUInteger}; use objc2::rc::Id; -use objc2::runtime::Object; +use objc2::runtime::AnyObject; use objc2::{extern_class, extern_methods, msg_send_id, mutability, ClassType}; use objc2::{Encode, Encoding}; @@ -50,23 +50,23 @@ extern_methods!( // TODO: NSApplicationDelegate #[method(setDelegate:)] - pub fn setDelegate(&self, delegate: &Object); + pub fn setDelegate(&self, delegate: &AnyObject); #[method(setPresentationOptions:)] pub fn setPresentationOptions(&self, options: NSApplicationPresentationOptions); #[method(hide:)] - pub fn hide(&self, sender: Option<&Object>); + pub fn hide(&self, sender: Option<&AnyObject>); #[method(orderFrontCharacterPalette:)] #[allow(dead_code)] - pub fn orderFrontCharacterPalette(&self, sender: Option<&Object>); + pub fn orderFrontCharacterPalette(&self, sender: Option<&AnyObject>); #[method(hideOtherApplications:)] - pub fn hideOtherApplications(&self, sender: Option<&Object>); + pub fn hideOtherApplications(&self, sender: Option<&AnyObject>); #[method(stop:)] - pub fn stop(&self, sender: Option<&Object>); + pub fn stop(&self, sender: Option<&AnyObject>); #[method(activateIgnoringOtherApps:)] pub fn activateIgnoringOtherApps(&self, ignore: bool); diff --git a/src/platform_impl/macos/appkit/screen.rs b/src/platform_impl/macos/appkit/screen.rs index 8dfe570d..aa101239 100644 --- a/src/platform_impl/macos/appkit/screen.rs +++ b/src/platform_impl/macos/appkit/screen.rs @@ -1,7 +1,7 @@ use icrate::ns_string; use icrate::Foundation::{CGFloat, NSArray, NSDictionary, NSNumber, NSObject, NSRect, NSString}; use objc2::rc::Id; -use objc2::runtime::Object; +use objc2::runtime::AnyObject; use objc2::{extern_class, extern_methods, mutability, ClassType}; extern_class!( @@ -33,7 +33,7 @@ extern_methods!( pub fn visibleFrame(&self) -> NSRect; #[method_id(deviceDescription)] - pub fn deviceDescription(&self) -> Id>; + pub fn deviceDescription(&self) -> Id>; pub fn display_id(&self) -> u32 { let key = ns_string!("NSScreenNumber"); @@ -49,7 +49,7 @@ extern_methods!( let obj = device_description .get(key) .expect("failed getting screen display id from device description"); - let obj: *const Object = obj; + let obj: *const AnyObject = obj; let obj: *const NSNumber = obj.cast(); let obj: &NSNumber = unsafe { &*obj }; diff --git a/src/platform_impl/macos/appkit/view.rs b/src/platform_impl/macos/appkit/view.rs index 049bf61f..5dcf903a 100644 --- a/src/platform_impl/macos/appkit/view.rs +++ b/src/platform_impl/macos/appkit/view.rs @@ -4,7 +4,7 @@ use std::ptr; use icrate::Foundation::{NSObject, NSPoint, NSRect}; use objc2::rc::Id; -use objc2::runtime::Object; +use objc2::runtime::AnyObject; use objc2::{extern_class, extern_methods, mutability, ClassType}; use super::{NSCursor, NSResponder, NSTextInputContext, NSWindow}; @@ -74,7 +74,7 @@ extern_methods!( unsafe fn inner_addTrackingRect( &self, rect: NSRect, - owner: &Object, + owner: &AnyObject, user_data: *mut c_void, assume_inside: bool, ) -> Option; diff --git a/src/platform_impl/macos/appkit/window.rs b/src/platform_impl/macos/appkit/window.rs index 33ad316b..395e2e72 100644 --- a/src/platform_impl/macos/appkit/window.rs +++ b/src/platform_impl/macos/appkit/window.rs @@ -3,7 +3,7 @@ use icrate::Foundation::{ }; use objc2::encode::{Encode, Encoding}; use objc2::rc::Id; -use objc2::runtime::Object; +use objc2::runtime::AnyObject; use objc2::{extern_class, extern_methods, mutability, ClassType}; use super::{ @@ -116,31 +116,31 @@ extern_methods!( pub(crate) fn registerForDraggedTypes(&self, types: &NSArray); #[method(makeKeyAndOrderFront:)] - pub(crate) fn makeKeyAndOrderFront(&self, sender: Option<&Object>); + pub(crate) fn makeKeyAndOrderFront(&self, sender: Option<&AnyObject>); #[method(orderFront:)] - pub(crate) fn orderFront(&self, sender: Option<&Object>); + pub(crate) fn orderFront(&self, sender: Option<&AnyObject>); #[method(miniaturize:)] - pub(crate) fn miniaturize(&self, sender: Option<&Object>); + pub(crate) fn miniaturize(&self, sender: Option<&AnyObject>); #[method(sender:)] - pub(crate) fn deminiaturize(&self, sender: Option<&Object>); + pub(crate) fn deminiaturize(&self, sender: Option<&AnyObject>); #[method(toggleFullScreen:)] - pub(crate) fn toggleFullScreen(&self, sender: Option<&Object>); + pub(crate) fn toggleFullScreen(&self, sender: Option<&AnyObject>); #[method(orderOut:)] - pub(crate) fn orderOut(&self, sender: Option<&Object>); + pub(crate) fn orderOut(&self, sender: Option<&AnyObject>); #[method(zoom:)] - pub(crate) fn zoom(&self, sender: Option<&Object>); + pub(crate) fn zoom(&self, sender: Option<&AnyObject>); #[method(selectNextKeyView:)] - pub(crate) fn selectNextKeyView(&self, sender: Option<&Object>); + pub(crate) fn selectNextKeyView(&self, sender: Option<&AnyObject>); #[method(selectPreviousKeyView:)] - pub(crate) fn selectPreviousKeyView(&self, sender: Option<&Object>); + pub(crate) fn selectPreviousKeyView(&self, sender: Option<&AnyObject>); #[method_id(firstResponder)] pub(crate) fn firstResponder(&self) -> Option>; diff --git a/src/platform_impl/macos/view.rs b/src/platform_impl/macos/view.rs index eba06c19..c8e34e4a 100644 --- a/src/platform_impl/macos/view.rs +++ b/src/platform_impl/macos/view.rs @@ -10,7 +10,7 @@ use icrate::Foundation::{ }; use objc2::declare::{Ivar, IvarDrop}; use objc2::rc::{Id, WeakId}; -use objc2::runtime::{Object, Sel}; +use objc2::runtime::{AnyObject, Sel}; use objc2::{class, declare_class, msg_send, msg_send_id, mutability, sel, ClassType}; use super::{ @@ -182,7 +182,7 @@ declare_class!( this.setPostsFrameChangedNotifications(true); - let notification_center: &Object = + let notification_center: &AnyObject = unsafe { msg_send![class!(NSNotificationCenter), defaultCenter] }; // About frame change let frame_did_change_notification_name = @@ -550,7 +550,7 @@ declare_class!( } #[method(insertTab:)] - fn insert_tab(&self, _sender: Option<&Object>) { + fn insert_tab(&self, _sender: Option<&AnyObject>) { trace_scope!("insertTab:"); let window = self.window(); if let Some(first_responder) = window.firstResponder() { @@ -561,7 +561,7 @@ declare_class!( } #[method(insertBackTab:)] - fn insert_back_tab(&self, _sender: Option<&Object>) { + fn insert_back_tab(&self, _sender: Option<&AnyObject>) { trace_scope!("insertBackTab:"); let window = self.window(); if let Some(first_responder) = window.firstResponder() { @@ -574,7 +574,7 @@ declare_class!( // Allows us to receive Cmd-. (the shortcut for closing a dialog) // https://bugs.eclipse.org/bugs/show_bug.cgi?id=300620#c6 #[method(cancelOperation:)] - fn cancel_operation(&self, _sender: Option<&Object>) { + fn cancel_operation(&self, _sender: Option<&AnyObject>) { trace_scope!("cancelOperation:"); let event = NSApp() diff --git a/src/platform_impl/macos/window_delegate.rs b/src/platform_impl/macos/window_delegate.rs index 67eb8fe8..528e3a0b 100644 --- a/src/platform_impl/macos/window_delegate.rs +++ b/src/platform_impl/macos/window_delegate.rs @@ -5,7 +5,7 @@ use std::ptr::{self, NonNull}; use icrate::Foundation::{NSArray, NSObject, NSSize, NSString}; use objc2::declare::{Ivar, IvarDrop}; use objc2::rc::{autoreleasepool, Id}; -use objc2::runtime::Object; +use objc2::runtime::AnyObject; use objc2::{class, declare_class, msg_send, msg_send_id, mutability, sel, ClassType}; use super::appkit::{ @@ -83,7 +83,7 @@ declare_class!( this.window.setDelegate(Some(this)); // Enable theme change event - let notification_center: Id = + let notification_center: Id = unsafe { msg_send_id![class!(NSDistributedNotificationCenter), defaultCenter] }; let notification_name = NSString::from_str("AppleInterfaceThemeChangedNotification"); @@ -93,7 +93,7 @@ declare_class!( addObserver: &*this selector: sel!(effectiveAppearanceDidChange:) name: &*notification_name - object: ptr::null::() + object: ptr::null::() ] }; @@ -105,14 +105,14 @@ declare_class!( // NSWindowDelegate + NSDraggingDestination protocols unsafe impl WinitWindowDelegate { #[method(windowShouldClose:)] - fn window_should_close(&self, _: Option<&Object>) -> bool { + fn window_should_close(&self, _: Option<&AnyObject>) -> bool { trace_scope!("windowShouldClose:"); self.queue_event(WindowEvent::CloseRequested); false } #[method(windowWillClose:)] - fn window_will_close(&self, _: Option<&Object>) { + fn window_will_close(&self, _: Option<&AnyObject>) { trace_scope!("windowWillClose:"); // `setDelegate:` retains the previous value and then autoreleases it autoreleasepool(|_| { @@ -124,14 +124,14 @@ declare_class!( } #[method(windowDidResize:)] - fn window_did_resize(&self, _: Option<&Object>) { + fn window_did_resize(&self, _: Option<&AnyObject>) { trace_scope!("windowDidResize:"); // NOTE: WindowEvent::Resized is reported in frameDidChange. self.emit_move_event(); } #[method(windowWillStartLiveResize:)] - fn window_will_start_live_resize(&self, _: Option<&Object>) { + fn window_will_start_live_resize(&self, _: Option<&AnyObject>) { trace_scope!("windowWillStartLiveResize:"); let increments = self @@ -142,26 +142,26 @@ declare_class!( } #[method(windowDidEndLiveResize:)] - fn window_did_end_live_resize(&self, _: Option<&Object>) { + fn window_did_end_live_resize(&self, _: Option<&AnyObject>) { trace_scope!("windowDidEndLiveResize:"); self.window.set_resize_increments_inner(NSSize::new(1., 1.)); } // This won't be triggered if the move was part of a resize. #[method(windowDidMove:)] - fn window_did_move(&self, _: Option<&Object>) { + fn window_did_move(&self, _: Option<&AnyObject>) { trace_scope!("windowDidMove:"); self.emit_move_event(); } #[method(windowDidChangeBackingProperties:)] - fn window_did_change_backing_properties(&self, _: Option<&Object>) { + fn window_did_change_backing_properties(&self, _: Option<&AnyObject>) { trace_scope!("windowDidChangeBackingProperties:"); self.queue_static_scale_factor_changed_event(); } #[method(windowDidBecomeKey:)] - fn window_did_become_key(&self, _: Option<&Object>) { + fn window_did_become_key(&self, _: Option<&AnyObject>) { trace_scope!("windowDidBecomeKey:"); // TODO: center the cursor if the window had mouse grab when it // lost focus @@ -169,7 +169,7 @@ declare_class!( } #[method(windowDidResignKey:)] - fn window_did_resign_key(&self, _: Option<&Object>) { + fn window_did_resign_key(&self, _: Option<&AnyObject>) { trace_scope!("windowDidResignKey:"); // It happens rather often, e.g. when the user is Cmd+Tabbing, that the // NSWindowDelegate will receive a didResignKey event despite no event @@ -243,7 +243,7 @@ declare_class!( /// Invoked when before enter fullscreen #[method(windowWillEnterFullScreen:)] - fn window_will_enter_fullscreen(&self, _: Option<&Object>) { + fn window_will_enter_fullscreen(&self, _: Option<&AnyObject>) { trace_scope!("windowWillEnterFullScreen:"); let mut shared_state = self @@ -272,7 +272,7 @@ declare_class!( /// Invoked when before exit fullscreen #[method(windowWillExitFullScreen:)] - fn window_will_exit_fullscreen(&self, _: Option<&Object>) { + fn window_will_exit_fullscreen(&self, _: Option<&AnyObject>) { trace_scope!("windowWillExitFullScreen:"); let mut shared_state = self.window.lock_shared_state("window_will_exit_fullscreen"); @@ -282,7 +282,7 @@ declare_class!( #[method(window:willUseFullScreenPresentationOptions:)] fn window_will_use_fullscreen_presentation_options( &self, - _: Option<&Object>, + _: Option<&AnyObject>, proposed_options: NSApplicationPresentationOptions, ) -> NSApplicationPresentationOptions { trace_scope!("window:willUseFullScreenPresentationOptions:"); @@ -309,7 +309,7 @@ declare_class!( /// Invoked when entered fullscreen #[method(windowDidEnterFullScreen:)] - fn window_did_enter_fullscreen(&self, _: Option<&Object>) { + fn window_did_enter_fullscreen(&self, _: Option<&AnyObject>) { trace_scope!("windowDidEnterFullScreen:"); self.state.initial_fullscreen.set(false); let mut shared_state = self.window.lock_shared_state("window_did_enter_fullscreen"); @@ -323,7 +323,7 @@ declare_class!( /// Invoked when exited fullscreen #[method(windowDidExitFullScreen:)] - fn window_did_exit_fullscreen(&self, _: Option<&Object>) { + fn window_did_exit_fullscreen(&self, _: Option<&AnyObject>) { trace_scope!("windowDidExitFullScreen:"); self.window.restore_state_from_fullscreen(); @@ -353,7 +353,7 @@ declare_class!( /// This method indicates that there was an error, and you should clean up any /// work you may have done to prepare to enter full-screen mode. #[method(windowDidFailToEnterFullScreen:)] - fn window_did_fail_to_enter_fullscreen(&self, _: Option<&Object>) { + fn window_did_fail_to_enter_fullscreen(&self, _: Option<&AnyObject>) { trace_scope!("windowDidFailToEnterFullScreen:"); let mut shared_state = self .window @@ -366,7 +366,7 @@ declare_class!( let _: () = msg_send![ &*self.window, performSelector: sel!(toggleFullScreen:), - withObject: ptr::null::(), + withObject: ptr::null::(), afterDelay: 0.5, ]; }; @@ -377,7 +377,7 @@ declare_class!( // Invoked when the occlusion state of the window changes #[method(windowDidChangeOcclusionState:)] - fn window_did_change_occlusion_state(&self, _: Option<&Object>) { + fn window_did_change_occlusion_state(&self, _: Option<&AnyObject>) { trace_scope!("windowDidChangeOcclusionState:"); self.queue_event(WindowEvent::Occluded( !self @@ -389,7 +389,7 @@ declare_class!( // Observe theme change #[method(effectiveAppearanceDidChange:)] - fn effective_appearance_did_change(&self, sender: Option<&Object>) { + fn effective_appearance_did_change(&self, sender: Option<&AnyObject>) { trace_scope!("Triggered `effectiveAppearanceDidChange:`"); unsafe { msg_send![ @@ -402,7 +402,7 @@ declare_class!( } #[method(effectiveAppearanceDidChangedOnMainThread:)] - fn effective_appearance_did_changed_on_main_thread(&self, _: Option<&Object>) { + fn effective_appearance_did_changed_on_main_thread(&self, _: Option<&AnyObject>) { let theme = get_ns_theme(); let mut shared_state = self .window @@ -416,7 +416,7 @@ declare_class!( } #[method(windowDidChangeScreen:)] - fn window_did_change_screen(&self, _: Option<&Object>) { + fn window_did_change_screen(&self, _: Option<&AnyObject>) { trace_scope!("windowDidChangeScreen:"); let is_simple_fullscreen = self .window