From 0eabee918aab688ac5e25825c8310fc9f84c6dd7 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Tue, 21 May 2024 07:25:45 +0200 Subject: [PATCH] Change usage of `Id` to `Retained` `Id` is a soft-deprecated to `Retained`, that name better reflects what it actually represents. See also https://github.com/madsmtm/objc2/issues/617. --- src/platform/ios.rs | 2 +- src/platform/macos.rs | 2 +- src/platform_impl/ios/app_state.rs | 28 ++++++++-------- src/platform_impl/ios/event_loop.rs | 4 +-- src/platform_impl/ios/monitor.rs | 24 +++++++------- src/platform_impl/ios/view.rs | 18 +++++----- src/platform_impl/ios/view_controller.rs | 6 ++-- src/platform_impl/ios/window.rs | 30 ++++++++--------- src/platform_impl/macos/app_delegate.rs | 12 +++---- src/platform_impl/macos/cursor.rs | 28 ++++++++-------- src/platform_impl/macos/event.rs | 4 +-- src/platform_impl/macos/event_loop.rs | 12 +++---- src/platform_impl/macos/menu.rs | 4 +-- src/platform_impl/macos/monitor.rs | 4 +-- src/platform_impl/macos/view.rs | 26 +++++++-------- src/platform_impl/macos/window.rs | 6 ++-- src/platform_impl/macos/window_delegate.rs | 38 +++++++++++----------- 17 files changed, 125 insertions(+), 123 deletions(-) diff --git a/src/platform/ios.rs b/src/platform/ios.rs index daba5827ba..59f5396163 100644 --- a/src/platform/ios.rs +++ b/src/platform/ios.rs @@ -357,7 +357,7 @@ impl MonitorHandleExtIOS for MonitorHandle { fn ui_screen(&self) -> *mut c_void { // SAFETY: The marker is only used to get the pointer of the screen let mtm = unsafe { objc2_foundation::MainThreadMarker::new_unchecked() }; - objc2::rc::Id::as_ptr(self.inner.ui_screen(mtm)) as *mut c_void + objc2::rc::Retained::as_ptr(self.inner.ui_screen(mtm)) as *mut c_void } #[inline] diff --git a/src/platform/macos.rs b/src/platform/macos.rs index 74d400f327..66f25c92b2 100644 --- a/src/platform/macos.rs +++ b/src/platform/macos.rs @@ -375,7 +375,7 @@ impl MonitorHandleExtMacOS for MonitorHandle { fn ns_screen(&self) -> Option<*mut c_void> { // SAFETY: We only use the marker to get a pointer let mtm = unsafe { objc2_foundation::MainThreadMarker::new_unchecked() }; - self.inner.ns_screen(mtm).map(|s| objc2::rc::Id::as_ptr(&s) as _) + self.inner.ns_screen(mtm).map(|s| objc2::rc::Retained::as_ptr(&s) as _) } } diff --git a/src/platform_impl/ios/app_state.rs b/src/platform_impl/ios/app_state.rs index 0b7ff7564b..630590ce2a 100644 --- a/src/platform_impl/ios/app_state.rs +++ b/src/platform_impl/ios/app_state.rs @@ -13,7 +13,7 @@ use core_foundation::runloop::{ kCFRunLoopCommonModes, CFRunLoopAddTimer, CFRunLoopGetMain, CFRunLoopRef, CFRunLoopTimerCreate, CFRunLoopTimerInvalidate, CFRunLoopTimerRef, CFRunLoopTimerSetNextFireDate, }; -use objc2::rc::Id; +use objc2::rc::Retained; use objc2::runtime::AnyObject; use objc2::{msg_send, sel}; use objc2_foundation::{ @@ -72,7 +72,7 @@ pub(crate) enum EventWrapper { #[derive(Debug)] pub struct ScaleFactorChanged { - pub(super) window: Id, + pub(super) window: Retained, pub(super) suggested_size: PhysicalSize, pub(super) scale_factor: f64, } @@ -99,25 +99,25 @@ impl Event { #[must_use = "dropping `AppStateImpl` without inspecting it is probably a bug"] enum AppStateImpl { NotLaunched { - queued_windows: Vec>, + queued_windows: Vec>, queued_events: Vec, - queued_gpu_redraws: HashSet>, + queued_gpu_redraws: HashSet>, }, Launching { - queued_windows: Vec>, + queued_windows: Vec>, queued_events: Vec, queued_handler: EventLoopHandler, - queued_gpu_redraws: HashSet>, + queued_gpu_redraws: HashSet>, }, ProcessingEvents { handler: EventLoopHandler, - queued_gpu_redraws: HashSet>, + queued_gpu_redraws: HashSet>, active_control_flow: ControlFlow, }, // special state to deal with reentrancy and prevent mutable aliasing. InUserCallback { queued_events: Vec, - queued_gpu_redraws: HashSet>, + queued_gpu_redraws: HashSet>, }, ProcessingRedraws { handler: EventLoopHandler, @@ -228,7 +228,9 @@ impl AppState { }); } - fn did_finish_launching_transition(&mut self) -> (Vec>, Vec) { + fn did_finish_launching_transition( + &mut self, + ) -> (Vec>, Vec) { let (windows, events, handler, queued_gpu_redraws) = match self.take_state() { AppStateImpl::Launching { queued_windows, @@ -344,7 +346,7 @@ impl AppState { UserCallbackTransitionResult::Success { handler, active_control_flow, processing_redraws } } - fn main_events_cleared_transition(&mut self) -> HashSet> { + fn main_events_cleared_transition(&mut self) -> HashSet> { let (handler, queued_gpu_redraws, active_control_flow) = match self.take_state() { AppStateImpl::ProcessingEvents { handler, queued_gpu_redraws, active_control_flow } => { (handler, queued_gpu_redraws, active_control_flow) @@ -412,7 +414,7 @@ impl AppState { } } -pub(crate) fn set_key_window(mtm: MainThreadMarker, window: &Id) { +pub(crate) fn set_key_window(mtm: MainThreadMarker, window: &Retained) { let mut this = AppState::get_mut(mtm); match this.state_mut() { &mut AppStateImpl::NotLaunched { ref mut queued_windows, .. } => { @@ -432,7 +434,7 @@ pub(crate) fn set_key_window(mtm: MainThreadMarker, window: &Id) window.makeKeyAndVisible(); } -pub(crate) fn queue_gl_or_metal_redraw(mtm: MainThreadMarker, window: Id) { +pub(crate) fn queue_gl_or_metal_redraw(mtm: MainThreadMarker, window: Retained) { let mut this = AppState::get_mut(mtm); match this.state_mut() { &mut AppStateImpl::NotLaunched { ref mut queued_gpu_redraws, .. } @@ -722,7 +724,7 @@ fn handle_hidpi_proxy(handler: &mut EventLoopHandler, event: ScaleFactorChanged) view.setFrame(new_frame); } -fn get_view_and_screen_frame(window: &WinitUIWindow) -> (Id, CGRect) { +fn get_view_and_screen_frame(window: &WinitUIWindow) -> (Retained, CGRect) { let view_controller = window.rootViewController().unwrap(); let view = view_controller.view().unwrap(); let bounds = window.bounds(); diff --git a/src/platform_impl/ios/event_loop.rs b/src/platform_impl/ios/event_loop.rs index 02fe101834..7881a7d1ab 100644 --- a/src/platform_impl/ios/event_loop.rs +++ b/src/platform_impl/ios/event_loop.rs @@ -11,7 +11,7 @@ use core_foundation::runloop::{ CFRunLoopObserverCreate, CFRunLoopObserverRef, CFRunLoopSourceContext, CFRunLoopSourceCreate, CFRunLoopSourceInvalidate, CFRunLoopSourceRef, CFRunLoopSourceSignal, CFRunLoopWakeUp, }; -use objc2::rc::Id; +use objc2::rc::Retained; use objc2::{msg_send_id, ClassType}; use objc2_foundation::{MainThreadMarker, NSString}; use objc2_ui_kit::{UIApplication, UIApplicationMain, UIDevice, UIScreen, UIUserInterfaceIdiom}; @@ -174,7 +174,7 @@ impl EventLoop { } pub fn run_app>(self, app: &mut A) -> ! { - let application: Option> = + let application: Option> = unsafe { msg_send_id![UIApplication::class(), sharedApplication] }; assert!( application.is_none(), diff --git a/src/platform_impl/ios/monitor.rs b/src/platform_impl/ios/monitor.rs index 477d1af9f5..1c707a3ac4 100644 --- a/src/platform_impl/ios/monitor.rs +++ b/src/platform_impl/ios/monitor.rs @@ -4,7 +4,7 @@ use std::collections::{BTreeSet, VecDeque}; use std::{fmt, hash, ptr}; use objc2::mutability::IsRetainable; -use objc2::rc::Id; +use objc2::rc::Retained; use objc2::Message; use objc2_foundation::{run_on_main, MainThreadBound, MainThreadMarker, NSInteger}; use objc2_ui_kit::{UIScreen, UIScreenMode}; @@ -15,11 +15,11 @@ use crate::platform_impl::platform::app_state; // Workaround for `MainThreadBound` implementing almost no traits #[derive(Debug)] -struct MainThreadBoundDelegateImpls(MainThreadBound>); +struct MainThreadBoundDelegateImpls(MainThreadBound>); impl Clone for MainThreadBoundDelegateImpls { fn clone(&self) -> Self { - Self(run_on_main(|mtm| MainThreadBound::new(Id::clone(self.0.get(mtm)), mtm))) + Self(run_on_main(|mtm| MainThreadBound::new(Retained::clone(self.0.get(mtm)), mtm))) } } @@ -27,7 +27,7 @@ impl hash::Hash for MainThreadBoundDelegateImpls { fn hash(&self, state: &mut H) { // SAFETY: Marker only used to get the pointer let mtm = unsafe { MainThreadMarker::new_unchecked() }; - Id::as_ptr(self.0.get(mtm)).hash(state); + Retained::as_ptr(self.0.get(mtm)).hash(state); } } @@ -35,7 +35,7 @@ impl PartialEq for MainThreadBoundDelegateImpls { fn eq(&self, other: &Self) -> bool { // SAFETY: Marker only used to get the pointer let mtm = unsafe { MainThreadMarker::new_unchecked() }; - Id::as_ptr(self.0.get(mtm)) == Id::as_ptr(other.0.get(mtm)) + Retained::as_ptr(self.0.get(mtm)) == Retained::as_ptr(other.0.get(mtm)) } } @@ -52,8 +52,8 @@ pub struct VideoModeHandle { impl VideoModeHandle { fn new( - uiscreen: Id, - screen_mode: Id, + uiscreen: Retained, + screen_mode: Retained, mtm: MainThreadMarker, ) -> VideoModeHandle { let refresh_rate_millihertz = refresh_rate_millihertz(&uiscreen); @@ -83,13 +83,13 @@ impl VideoModeHandle { self.monitor.clone() } - pub(super) fn screen_mode(&self, mtm: MainThreadMarker) -> &Id { + pub(super) fn screen_mode(&self, mtm: MainThreadMarker) -> &Retained { self.screen_mode.0.get(mtm) } } pub struct MonitorHandle { - ui_screen: MainThreadBound>, + ui_screen: MainThreadBound>, } impl Clone for MonitorHandle { @@ -140,8 +140,8 @@ impl fmt::Debug for MonitorHandle { } impl MonitorHandle { - pub(crate) fn new(ui_screen: Id) -> Self { - // Holding `Id` implies we're on the main thread. + pub(crate) fn new(ui_screen: Retained) -> Self { + // Holding `Retained` implies we're on the main thread. let mtm = MainThreadMarker::new().unwrap(); Self { ui_screen: MainThreadBound::new(ui_screen, mtm) } } @@ -199,7 +199,7 @@ impl MonitorHandle { }) } - pub(crate) fn ui_screen(&self, mtm: MainThreadMarker) -> &Id { + pub(crate) fn ui_screen(&self, mtm: MainThreadMarker) -> &Retained { self.ui_screen.get(mtm) } diff --git a/src/platform_impl/ios/view.rs b/src/platform_impl/ios/view.rs index 6585d7013a..75386d368e 100644 --- a/src/platform_impl/ios/view.rs +++ b/src/platform_impl/ios/view.rs @@ -1,7 +1,7 @@ #![allow(clippy::unnecessary_cast)] use std::cell::{Cell, RefCell}; -use objc2::rc::Id; +use objc2::rc::Retained; use objc2::runtime::{NSObjectProtocol, ProtocolObject}; use objc2::{declare_class, msg_send, msg_send_id, mutability, sel, ClassType, DeclaredClass}; use objc2_foundation::{CGFloat, CGPoint, CGRect, MainThreadMarker, NSObject, NSSet}; @@ -20,10 +20,10 @@ use crate::platform_impl::platform::DEVICE_ID; use crate::window::{WindowAttributes, WindowId as RootWindowId}; pub struct WinitViewState { - pinch_gesture_recognizer: RefCell>>, - doubletap_gesture_recognizer: RefCell>>, - rotation_gesture_recognizer: RefCell>>, - pan_gesture_recognizer: RefCell>>, + pinch_gesture_recognizer: RefCell>>, + doubletap_gesture_recognizer: RefCell>>, + rotation_gesture_recognizer: RefCell>>, + pan_gesture_recognizer: RefCell>>, // for iOS delta references the start of the Gesture rotation_last_delta: Cell, @@ -331,7 +331,7 @@ impl WinitView { mtm: MainThreadMarker, window_attributes: &WindowAttributes, frame: CGRect, - ) -> Id { + ) -> Retained { let this = mtm.alloc().set_ivars(WinitViewState { pinch_gesture_recognizer: RefCell::new(None), doubletap_gesture_recognizer: RefCell::new(None), @@ -342,7 +342,7 @@ impl WinitView { pinch_last_delta: Cell::new(0.0), pan_last_delta: Cell::new(CGPoint { x: 0.0, y: 0.0 }), }); - let this: Id = unsafe { msg_send_id![super(this), initWithFrame: frame] }; + let this: Retained = unsafe { msg_send_id![super(this), initWithFrame: frame] }; this.setMultipleTouchEnabled(true); @@ -353,9 +353,9 @@ impl WinitView { this } - fn window(&self) -> Option> { + fn window(&self) -> Option> { // SAFETY: `WinitView`s are always installed in a `WinitUIWindow` - (**self).window().map(|window| unsafe { Id::cast(window) }) + (**self).window().map(|window| unsafe { Retained::cast(window) }) } pub(crate) fn recognize_pinch_gesture(&self, should_recognize: bool) { diff --git a/src/platform_impl/ios/view_controller.rs b/src/platform_impl/ios/view_controller.rs index 1f6785fdf1..dd658682e2 100644 --- a/src/platform_impl/ios/view_controller.rs +++ b/src/platform_impl/ios/view_controller.rs @@ -1,6 +1,6 @@ use std::cell::Cell; -use objc2::rc::Id; +use objc2::rc::Retained; use objc2::{declare_class, msg_send_id, mutability, ClassType, DeclaredClass}; use objc2_foundation::{MainThreadMarker, NSObject}; use objc2_ui_kit::{ @@ -137,7 +137,7 @@ impl WinitViewController { mtm: MainThreadMarker, window_attributes: &WindowAttributes, view: &UIView, - ) -> Id { + ) -> Retained { // These are set properly below, we just to set them to something in the meantime. let this = mtm.alloc().set_ivars(ViewControllerState { prefers_status_bar_hidden: Cell::new(false), @@ -146,7 +146,7 @@ impl WinitViewController { supported_orientations: Cell::new(UIInterfaceOrientationMask::All), preferred_screen_edges_deferring_system_gestures: Cell::new(UIRectEdge::empty()), }); - let this: Id = unsafe { msg_send_id![super(this), init] }; + let this: Retained = unsafe { msg_send_id![super(this), init] }; this.set_prefers_status_bar_hidden( window_attributes.platform_specific.prefers_status_bar_hidden, diff --git a/src/platform_impl/ios/window.rs b/src/platform_impl/ios/window.rs index 346aa5fb7e..8ea7aeae91 100644 --- a/src/platform_impl/ios/window.rs +++ b/src/platform_impl/ios/window.rs @@ -2,7 +2,7 @@ use std::collections::VecDeque; -use objc2::rc::Id; +use objc2::rc::Retained; use objc2::runtime::{AnyObject, NSObject}; use objc2::{class, declare_class, msg_send, msg_send_id, mutability, ClassType, DeclaredClass}; use objc2_foundation::{ @@ -79,8 +79,8 @@ impl WinitUIWindow { window_attributes: &WindowAttributes, frame: CGRect, view_controller: &UIViewController, - ) -> Id { - let this: Id = unsafe { msg_send_id![mtm.alloc(), initWithFrame: frame] }; + ) -> Retained { + let this: Retained = unsafe { msg_send_id![mtm.alloc(), initWithFrame: frame] }; this.setRootViewController(Some(view_controller)); @@ -107,9 +107,9 @@ impl WinitUIWindow { } pub struct Inner { - window: Id, - view_controller: Id, - view: Id, + window: Retained, + view_controller: Retained, + view: Retained, gl_or_metal_backed: bool, } @@ -408,18 +408,18 @@ impl Inner { #[cfg(feature = "rwh_04")] pub fn raw_window_handle_rwh_04(&self) -> rwh_04::RawWindowHandle { let mut window_handle = rwh_04::UiKitHandle::empty(); - window_handle.ui_window = Id::as_ptr(&self.window) as _; - window_handle.ui_view = Id::as_ptr(&self.view) as _; - window_handle.ui_view_controller = Id::as_ptr(&self.view_controller) as _; + window_handle.ui_window = Retained::as_ptr(&self.window) as _; + window_handle.ui_view = Retained::as_ptr(&self.view) as _; + window_handle.ui_view_controller = Retained::as_ptr(&self.view_controller) as _; rwh_04::RawWindowHandle::UiKit(window_handle) } #[cfg(feature = "rwh_05")] pub fn raw_window_handle_rwh_05(&self) -> rwh_05::RawWindowHandle { let mut window_handle = rwh_05::UiKitWindowHandle::empty(); - window_handle.ui_window = Id::as_ptr(&self.window) as _; - window_handle.ui_view = Id::as_ptr(&self.view) as _; - window_handle.ui_view_controller = Id::as_ptr(&self.view_controller) as _; + window_handle.ui_window = Retained::as_ptr(&self.window) as _; + window_handle.ui_view = Retained::as_ptr(&self.view) as _; + window_handle.ui_view_controller = Retained::as_ptr(&self.view_controller) as _; rwh_05::RawWindowHandle::UiKit(window_handle) } @@ -431,11 +431,11 @@ impl Inner { #[cfg(feature = "rwh_06")] pub fn raw_window_handle_rwh_06(&self) -> rwh_06::RawWindowHandle { let mut window_handle = rwh_06::UiKitWindowHandle::new({ - let ui_view = Id::as_ptr(&self.view) as _; - std::ptr::NonNull::new(ui_view).expect("Id should never be null") + let ui_view = Retained::as_ptr(&self.view) as _; + std::ptr::NonNull::new(ui_view).expect("Retained should never be null") }); window_handle.ui_view_controller = - std::ptr::NonNull::new(Id::as_ptr(&self.view_controller) as _); + std::ptr::NonNull::new(Retained::as_ptr(&self.view_controller) as _); rwh_06::RawWindowHandle::UiKit(window_handle) } diff --git a/src/platform_impl/macos/app_delegate.rs b/src/platform_impl/macos/app_delegate.rs index 984f4d099e..3ab2357eed 100644 --- a/src/platform_impl/macos/app_delegate.rs +++ b/src/platform_impl/macos/app_delegate.rs @@ -5,7 +5,7 @@ use std::rc::Weak; use std::sync::{Arc, Mutex}; use std::time::Instant; -use objc2::rc::Id; +use objc2::rc::Retained; use objc2::runtime::AnyObject; use objc2::{declare_class, msg_send_id, mutability, ClassType, DeclaredClass}; use objc2_app_kit::{NSApplication, NSApplicationActivationPolicy, NSApplicationDelegate}; @@ -133,7 +133,7 @@ impl ApplicationDelegate { activation_policy: NSApplicationActivationPolicy, default_menu: bool, activate_ignoring_other_apps: bool, - ) -> Id { + ) -> Retained { let this = mtm.alloc().set_ivars(State { activation_policy: Policy(activation_policy), default_menu, @@ -143,13 +143,13 @@ impl ApplicationDelegate { unsafe { msg_send_id![super(this), init] } } - pub fn get(mtm: MainThreadMarker) -> Id { + pub fn get(mtm: MainThreadMarker) -> Retained { let app = NSApplication::sharedApplication(mtm); let delegate = unsafe { app.delegate() }.expect("a delegate was not configured on the application"); if delegate.is_kind_of::() { // SAFETY: Just checked that the delegate is an instance of `ApplicationDelegate` - unsafe { Id::cast(delegate) } + unsafe { Retained::cast(delegate) } } else { panic!("tried to get a delegate that was not the one Winit has registered") } @@ -247,7 +247,7 @@ impl ApplicationDelegate { pub fn queue_static_scale_factor_changed_event( &self, - window: Id, + window: Retained, suggested_size: PhysicalSize, scale_factor: f64, ) { @@ -423,7 +423,7 @@ pub(crate) enum QueuedEvent { WindowEvent(WindowId, WindowEvent), DeviceEvent(DeviceEvent), ScaleFactorChanged { - window: Id, + window: Retained, suggested_size: PhysicalSize, scale_factor: f64, }, diff --git a/src/platform_impl/macos/cursor.rs b/src/platform_impl/macos/cursor.rs index 4084be122e..cc8f5f3088 100644 --- a/src/platform_impl/macos/cursor.rs +++ b/src/platform_impl/macos/cursor.rs @@ -2,7 +2,7 @@ use std::ffi::c_uchar; use std::slice; use std::sync::OnceLock; -use objc2::rc::Id; +use objc2::rc::Retained; use objc2::runtime::Sel; use objc2::{msg_send_id, sel, ClassType}; use objc2_app_kit::{NSBitmapImageRep, NSCursor, NSDeviceRGBColorSpace, NSImage}; @@ -15,7 +15,7 @@ use crate::cursor::{CursorImage, OnlyCursorImageSource}; use crate::window::CursorIcon; #[derive(Clone, Debug, PartialEq, Eq, Hash)] -pub struct CustomCursor(pub(crate) Id); +pub struct CustomCursor(pub(crate) Retained); // SAFETY: NSCursor is immutable and thread-safe // TODO(madsmtm): Put this logic in objc2-app-kit itself @@ -28,7 +28,7 @@ impl CustomCursor { } } -pub(crate) fn cursor_from_image(cursor: &CursorImage) -> Id { +pub(crate) fn cursor_from_image(cursor: &CursorImage) -> Retained { let width = cursor.width; let height = cursor.height; @@ -60,14 +60,14 @@ pub(crate) fn cursor_from_image(cursor: &CursorImage) -> Id { NSCursor::initWithImage_hotSpot(NSCursor::alloc(), &image, hotspot) } -pub(crate) fn default_cursor() -> Id { +pub(crate) fn default_cursor() -> Retained { NSCursor::arrowCursor() } -unsafe fn try_cursor_from_selector(sel: Sel) -> Option> { +unsafe fn try_cursor_from_selector(sel: Sel) -> Option> { let cls = NSCursor::class(); if cls.responds_to(sel) { - let cursor: Id = unsafe { msg_send_id![cls, performSelector: sel] }; + let cursor: Retained = unsafe { msg_send_id![cls, performSelector: sel] }; Some(cursor) } else { tracing::warn!("cursor `{sel}` appears to be invalid"); @@ -82,7 +82,7 @@ macro_rules! def_undocumented_cursor { )*} => {$( $(#[$($m)*])* #[allow(non_snake_case)] - fn $name() -> Id { + fn $name() -> Retained { unsafe { try_cursor_from_selector(sel!($name)).unwrap_or_else(|| default_cursor()) } } )*}; @@ -112,7 +112,7 @@ def_undocumented_cursor!( // Note that loading `busybutclickable` with this code won't animate // the frames; instead you'll just get them all in a column. -unsafe fn load_webkit_cursor(name: &NSString) -> Id { +unsafe fn load_webkit_cursor(name: &NSString) -> Retained { // Snatch a cursor from WebKit; They fit the style of the native // cursors, and will seem completely standard to macOS users. // @@ -128,7 +128,7 @@ unsafe fn load_webkit_cursor(name: &NSString) -> Id { // TODO: Handle PLists better let info_path = cursor_path.stringByAppendingPathComponent(ns_string!("info.plist")); - let info: Id> = unsafe { + let info: Retained> = unsafe { msg_send_id![ >::class(), dictionaryWithContentsOfFile: &*info_path, @@ -155,15 +155,15 @@ unsafe fn load_webkit_cursor(name: &NSString) -> Id { NSCursor::initWithImage_hotSpot(NSCursor::alloc(), &image, hotspot) } -fn webkit_move() -> Id { +fn webkit_move() -> Retained { unsafe { load_webkit_cursor(ns_string!("move")) } } -fn webkit_cell() -> Id { +fn webkit_cell() -> Retained { unsafe { load_webkit_cursor(ns_string!("cell")) } } -pub(crate) fn invisible_cursor() -> Id { +pub(crate) fn invisible_cursor() -> Retained { // 16x16 GIF data for invisible cursor // You can reproduce this via ImageMagick. // $ convert -size 16x16 xc:none cursor.gif @@ -174,7 +174,7 @@ pub(crate) fn invisible_cursor() -> Id { 0xa3, 0x9c, 0xb4, 0xda, 0x8b, 0xb3, 0x3e, 0x05, 0x00, 0x3b, ]; - fn new_invisible() -> Id { + fn new_invisible() -> Retained { // TODO: Consider using `dataWithBytesNoCopy:` let data = NSData::with_bytes(CURSOR_BYTES); let image = NSImage::initWithData(NSImage::alloc(), &data).unwrap(); @@ -187,7 +187,7 @@ pub(crate) fn invisible_cursor() -> Id { CURSOR.get_or_init(|| CustomCursor(new_invisible())).0.clone() } -pub(crate) fn cursor_from_icon(icon: CursorIcon) -> Id { +pub(crate) fn cursor_from_icon(icon: CursorIcon) -> Retained { match icon { CursorIcon::Default => default_cursor(), CursorIcon::Pointer => NSCursor::pointingHandCursor(), diff --git a/src/platform_impl/macos/event.rs b/src/platform_impl/macos/event.rs index 013f8752d3..602ab6278f 100644 --- a/src/platform_impl/macos/event.rs +++ b/src/platform_impl/macos/event.rs @@ -2,7 +2,7 @@ use std::ffi::c_void; use core_foundation::base::CFRelease; use core_foundation::data::{CFDataGetBytePtr, CFDataRef}; -use objc2::rc::Id; +use objc2::rc::Retained; use objc2_app_kit::{NSEvent, NSEventModifierFlags, NSEventSubtype, NSEventType}; use objc2_foundation::{run_on_main, NSPoint}; use smol_str::SmolStr; @@ -344,7 +344,7 @@ pub(super) fn event_mods(event: &NSEvent) -> Modifiers { Modifiers { state, pressed_mods } } -pub(super) fn dummy_event() -> Option> { +pub(super) fn dummy_event() -> Option> { unsafe { NSEvent::otherEventWithType_location_modifierFlags_timestamp_windowNumber_context_subtype_data1_data2( NSEventType::ApplicationDefined, diff --git a/src/platform_impl/macos/event_loop.rs b/src/platform_impl/macos/event_loop.rs index ccdc9da2b7..68f411cef9 100644 --- a/src/platform_impl/macos/event_loop.rs +++ b/src/platform_impl/macos/event_loop.rs @@ -14,7 +14,7 @@ use core_foundation::runloop::{ kCFRunLoopCommonModes, CFRunLoopAddSource, CFRunLoopGetMain, CFRunLoopSourceContext, CFRunLoopSourceCreate, CFRunLoopSourceRef, CFRunLoopSourceSignal, CFRunLoopWakeUp, }; -use objc2::rc::{autoreleasepool, Id}; +use objc2::rc::{autoreleasepool, Retained}; use objc2::runtime::ProtocolObject; use objc2::{msg_send_id, ClassType}; use objc2_app_kit::{NSApplication, NSApplicationActivationPolicy, NSWindow}; @@ -68,12 +68,12 @@ impl PanicInfo { #[derive(Debug)] pub struct ActiveEventLoop { - delegate: Id, + delegate: Retained, pub(super) mtm: MainThreadMarker, } impl ActiveEventLoop { - pub(super) fn new_root(delegate: Id) -> RootWindowTarget { + pub(super) fn new_root(delegate: Retained) -> RootWindowTarget { let mtm = MainThreadMarker::from(&*delegate); let p = Self { delegate, mtm }; RootWindowTarget { p, _marker: PhantomData } @@ -186,12 +186,12 @@ pub struct EventLoop { /// /// We intentionally don't store `WinitApplication` since we want to have /// the possibility of swapping that out at some point. - app: Id, + app: Retained, /// The application delegate that we've registered. /// /// The delegate is only weakly referenced by NSApplication, so we must /// keep it around here as well. - delegate: Id, + delegate: Retained, // Event sender and receiver, used for EventLoopProxy. sender: mpsc::Sender, @@ -225,7 +225,7 @@ impl EventLoop { let mtm = MainThreadMarker::new() .expect("on macOS, `EventLoop` must be created on the main thread!"); - let app: Id = + let app: Retained = unsafe { msg_send_id![WinitApplication::class(), sharedApplication] }; if !app.is_kind_of::() { diff --git a/src/platform_impl/macos/menu.rs b/src/platform_impl/macos/menu.rs index b0492c8ba9..cdebea0b9d 100644 --- a/src/platform_impl/macos/menu.rs +++ b/src/platform_impl/macos/menu.rs @@ -1,4 +1,4 @@ -use objc2::rc::Id; +use objc2::rc::Retained; use objc2::runtime::Sel; use objc2::sel; use objc2_app_kit::{NSApplication, NSEventModifierFlags, NSMenu, NSMenuItem}; @@ -91,7 +91,7 @@ fn menu_item( title: &NSString, selector: Option, key_equivalent: Option>, -) -> Id { +) -> Retained { let (key, masks) = match key_equivalent { Some(ke) => (ke.key, ke.masks), None => (ns_string!(""), None), diff --git a/src/platform_impl/macos/monitor.rs b/src/platform_impl/macos/monitor.rs index 6229e5070d..e78d84f0be 100644 --- a/src/platform_impl/macos/monitor.rs +++ b/src/platform_impl/macos/monitor.rs @@ -9,7 +9,7 @@ use core_foundation::string::CFString; use core_graphics::display::{ CGDirectDisplayID, CGDisplay, CGDisplayBounds, CGDisplayCopyDisplayMode, }; -use objc2::rc::Id; +use objc2::rc::Retained; use objc2::runtime::AnyObject; use objc2_app_kit::NSScreen; use objc2_foundation::{ns_string, run_on_main, MainThreadMarker, NSNumber, NSPoint, NSRect}; @@ -295,7 +295,7 @@ impl MonitorHandle { } } - pub(crate) fn ns_screen(&self, mtm: MainThreadMarker) -> Option> { + pub(crate) fn ns_screen(&self, mtm: MainThreadMarker) -> Option> { let uuid = unsafe { ffi::CGDisplayCreateUUIDFromDisplayID(self.0) }; NSScreen::screens(mtm).into_iter().find(|screen| { let other_native_id = get_display_id(screen); diff --git a/src/platform_impl/macos/view.rs b/src/platform_impl/macos/view.rs index 19d8ea53e5..f6aa85c61c 100644 --- a/src/platform_impl/macos/view.rs +++ b/src/platform_impl/macos/view.rs @@ -3,7 +3,7 @@ use std::cell::{Cell, RefCell}; use std::collections::{HashMap, VecDeque}; use std::ptr; -use objc2::rc::{Id, WeakId}; +use objc2::rc::{Retained, WeakId}; use objc2::runtime::{AnyObject, Sel}; use objc2::{declare_class, msg_send_id, mutability, sel, ClassType, DeclaredClass}; use objc2_app_kit::{ @@ -35,7 +35,7 @@ use crate::platform::macos::OptionAsAlt; #[derive(Debug)] struct CursorState { visible: bool, - cursor: Id, + cursor: Retained, } impl Default for CursorState { @@ -111,7 +111,7 @@ fn get_left_modifier_code(key: &Key) -> KeyCode { #[derive(Debug)] pub struct ViewState { /// Strong reference to the global application state. - app_delegate: Id, + app_delegate: Retained, cursor_state: RefCell, ime_position: Cell, @@ -131,7 +131,7 @@ pub struct ViewState { /// to the application, even during IME forward_key_to_app: Cell, - marked_text: RefCell>, + marked_text: RefCell>, accepts_first_mouse: bool, // Weak reference because the window keeps a strong reference to the view @@ -221,7 +221,7 @@ declare_class!( // IMKInputSession [0x7fc573576ff0 presentFunctionRowItemTextInputViewWithEndpoint:completionHandler:] : [self textInputContext]=0x7fc573558e10 *NO* NSRemoteViewController to client, NSError=Error Domain=NSCocoaErrorDomain Code=4099 "The connection from pid 0 was invalidated from this process." UserInfo={NSDebugDescription=The connection from pid 0 was invalidated from this process.}, com.apple.inputmethod.EmojiFunctionRowItem // TODO: Add an API extension for using `NSTouchBar` #[method_id(touchBar)] - fn touch_bar(&self) -> Option> { + fn touch_bar(&self) -> Option> { trace_scope!("touchBar"); None } @@ -340,7 +340,7 @@ declare_class!( } #[method_id(validAttributesForMarkedText)] - fn valid_attributes_for_marked_text(&self) -> Id> { + fn valid_attributes_for_marked_text(&self) -> Retained> { trace_scope!("validAttributesForMarkedText"); NSArray::new() } @@ -350,7 +350,7 @@ declare_class!( &self, _range: NSRange, _actual_range: *mut NSRange, - ) -> Option> { + ) -> Option> { trace_scope!("attributedSubstringForProposedRange:actualRange:"); None } @@ -776,7 +776,7 @@ impl WinitView { window: &WinitWindow, accepts_first_mouse: bool, option_as_alt: OptionAsAlt, - ) -> Id { + ) -> Retained { let mtm = MainThreadMarker::from(window); let this = mtm.alloc().set_ivars(ViewState { app_delegate: app_delegate.retain(), @@ -795,7 +795,7 @@ impl WinitView { _ns_window: WeakId::new(&window.retain()), option_as_alt: Cell::new(option_as_alt), }); - let this: Id = unsafe { msg_send_id![super(this), init] }; + let this: Retained = unsafe { msg_send_id![super(this), init] }; this.setPostsFrameChangedNotifications(true); let notification_center = unsafe { NSNotificationCenter::defaultCenter() }; @@ -813,7 +813,7 @@ impl WinitView { this } - fn window(&self) -> Id { + fn window(&self) -> Retained { // TODO: Simply use `window` property on `NSView`. // That only returns a window _after_ the view has been attached though! // (which is incompatible with `frameDidChange:`) @@ -846,11 +846,11 @@ impl WinitView { .unwrap_or_default() } - pub(super) fn cursor_icon(&self) -> Id { + pub(super) fn cursor_icon(&self) -> Retained { self.ivars().cursor_state.borrow().cursor.clone() } - pub(super) fn set_cursor_icon(&self, icon: Id) { + pub(super) fn set_cursor_icon(&self, icon: Retained) { let mut cursor_state = self.ivars().cursor_state.borrow_mut(); cursor_state.cursor = icon; } @@ -1083,7 +1083,7 @@ fn mouse_button(event: &NSEvent) -> MouseButton { // NOTE: to get option as alt working we need to rewrite events // we're getting from the operating system, which makes it // impossible to provide such events as extra in `KeyEvent`. -fn replace_event(event: &NSEvent, option_as_alt: OptionAsAlt) -> Id { +fn replace_event(event: &NSEvent, option_as_alt: OptionAsAlt) -> Retained { let ev_mods = event_mods(event).state; let ignore_alt_characters = match option_as_alt { OptionAsAlt::OnlyLeft if lalt_pressed(event) => true, diff --git a/src/platform_impl/macos/window.rs b/src/platform_impl/macos/window.rs index d19ea9171f..eb1f75deea 100644 --- a/src/platform_impl/macos/window.rs +++ b/src/platform_impl/macos/window.rs @@ -1,6 +1,6 @@ #![allow(clippy::unnecessary_cast)] -use objc2::rc::{autoreleasepool, Id}; +use objc2::rc::{autoreleasepool, Retained}; use objc2::{declare_class, mutability, ClassType, DeclaredClass}; use objc2_app_kit::{NSResponder, NSWindow}; use objc2_foundation::{MainThreadBound, MainThreadMarker, NSObject}; @@ -11,9 +11,9 @@ use crate::error::OsError as RootOsError; use crate::window::WindowAttributes; pub(crate) struct Window { - window: MainThreadBound>, + window: MainThreadBound>, /// The window only keeps a weak reference to this, so we must keep it around here. - delegate: MainThreadBound>, + delegate: MainThreadBound>, } impl Drop for Window { diff --git a/src/platform_impl/macos/window_delegate.rs b/src/platform_impl/macos/window_delegate.rs index 78a9ab6dea..3909b98c18 100644 --- a/src/platform_impl/macos/window_delegate.rs +++ b/src/platform_impl/macos/window_delegate.rs @@ -4,7 +4,7 @@ use std::collections::VecDeque; use core_graphics::display::{CGDisplay, CGPoint}; use monitor::VideoModeHandle; -use objc2::rc::{autoreleasepool, Id}; +use objc2::rc::{autoreleasepool, Retained}; use objc2::runtime::{AnyObject, ProtocolObject}; use objc2::{declare_class, msg_send_id, mutability, sel, ClassType, DeclaredClass}; use objc2_app_kit::{ @@ -73,9 +73,9 @@ impl Default for PlatformSpecificWindowAttributes { #[derive(Debug)] pub(crate) struct State { /// Strong reference to the global application state. - app_delegate: Id, + app_delegate: Retained, - window: Id, + window: Retained, current_theme: Cell>, @@ -355,9 +355,9 @@ declare_class!( use std::path::PathBuf; - let pb: Id = unsafe { msg_send_id![sender, draggingPasteboard] }; + let pb: Retained = unsafe { msg_send_id![sender, draggingPasteboard] }; let filenames = pb.propertyListForType(unsafe { NSFilenamesPboardType }).unwrap(); - let filenames: Id> = unsafe { Id::cast(filenames) }; + let filenames: Retained> = unsafe { Retained::cast(filenames) }; filenames.into_iter().for_each(|file| { let path = PathBuf::from(file.to_string()); @@ -381,9 +381,9 @@ declare_class!( use std::path::PathBuf; - let pb: Id = unsafe { msg_send_id![sender, draggingPasteboard] }; + let pb: Retained = unsafe { msg_send_id![sender, draggingPasteboard] }; let filenames = pb.propertyListForType(unsafe { NSFilenamesPboardType }).unwrap(); - let filenames: Id> = unsafe { Id::cast(filenames) }; + let filenames: Retained> = unsafe { Retained::cast(filenames) }; filenames.into_iter().for_each(|file| { let path = PathBuf::from(file.to_string()); @@ -437,7 +437,7 @@ fn new_window( app_delegate: &ApplicationDelegate, attrs: &WindowAttributes, mtm: MainThreadMarker, -) -> Option> { +) -> Option> { autoreleasepool(|_| { let screen = match attrs.fullscreen.clone().map(Into::into) { Some(Fullscreen::Borderless(Some(monitor))) @@ -509,7 +509,7 @@ fn new_window( masks |= NSWindowStyleMask::FullSizeContentView; } - let window: Option> = unsafe { + let window: Option> = unsafe { msg_send_id![ super(mtm.alloc().set_ivars(())), initWithContentRect: frame, @@ -618,7 +618,7 @@ impl WindowDelegate { app_delegate: &ApplicationDelegate, attrs: WindowAttributes, mtm: MainThreadMarker, - ) -> Result, RootOsError> { + ) -> Result, RootOsError> { let window = new_window(app_delegate, &attrs, mtm) .ok_or_else(|| os_error!(OsError::CreationError("couldn't create `NSWindow`")))?; @@ -627,8 +627,8 @@ impl WindowDelegate { Some(rwh_06::RawWindowHandle::AppKit(handle)) => { // SAFETY: Caller ensures the pointer is valid or NULL // Unwrap is fine, since the pointer comes from `NonNull`. - let parent_view: Id = - unsafe { Id::retain(handle.ns_view.as_ptr().cast()) }.unwrap(); + let parent_view: Retained = + unsafe { Retained::retain(handle.ns_view.as_ptr().cast()) }.unwrap(); let parent = parent_view.window().ok_or_else(|| { os_error!(OsError::CreationError("parent view should be installed in a window")) })?; @@ -678,7 +678,7 @@ impl WindowDelegate { is_simple_fullscreen: Cell::new(false), saved_style: Cell::new(None), }); - let delegate: Id = unsafe { msg_send_id![super(delegate), init] }; + let delegate: Retained = unsafe { msg_send_id![super(delegate), init] }; if scale_factor != 1.0 { delegate.queue_static_scale_factor_changed_event(); @@ -738,9 +738,9 @@ impl WindowDelegate { } #[track_caller] - pub(super) fn view(&self) -> Id { + pub(super) fn view(&self) -> Retained { // SAFETY: The view inside WinitWindow is always `WinitView` - unsafe { Id::cast(self.window().contentView().unwrap()) } + unsafe { Retained::cast(self.window().contentView().unwrap()) } } #[track_caller] @@ -1537,7 +1537,7 @@ impl WindowDelegate { pub fn raw_window_handle_rwh_04(&self) -> rwh_04::RawWindowHandle { let mut window_handle = rwh_04::AppKitHandle::empty(); window_handle.ns_window = self.window() as *const WinitWindow as *mut _; - window_handle.ns_view = Id::as_ptr(&self.contentView().unwrap()) as *mut _; + window_handle.ns_view = Retained::as_ptr(&self.contentView().unwrap()) as *mut _; rwh_04::RawWindowHandle::AppKit(window_handle) } @@ -1546,7 +1546,7 @@ impl WindowDelegate { pub fn raw_window_handle_rwh_05(&self) -> rwh_05::RawWindowHandle { let mut window_handle = rwh_05::AppKitWindowHandle::empty(); window_handle.ns_window = self.window() as *const WinitWindow as *mut _; - window_handle.ns_view = Id::as_ptr(&self.view()) as *mut _; + window_handle.ns_view = Retained::as_ptr(&self.view()) as *mut _; rwh_05::RawWindowHandle::AppKit(window_handle) } @@ -1560,8 +1560,8 @@ impl WindowDelegate { #[inline] pub fn raw_window_handle_rwh_06(&self) -> rwh_06::RawWindowHandle { let window_handle = rwh_06::AppKitWindowHandle::new({ - let ptr = Id::as_ptr(&self.view()) as *mut _; - std::ptr::NonNull::new(ptr).expect("Id should never be null") + let ptr = Retained::as_ptr(&self.view()) as *mut _; + std::ptr::NonNull::new(ptr).expect("Retained should never be null") }); rwh_06::RawWindowHandle::AppKit(window_handle) }