Update objc2 crates (#3634)

Changes relevant to Winit:
- `icrate` has been deprecated in favour of separate crates per
  framework, in our case `objc2-foundation` and `objc2-app-kit` (and in
  the future `objc2-ui-kit` on iOS).
- Moved `MainThreadMarker::run_on_main` to free-standing function
  `run_on_main`.
- Changed how features work, this should result in less code that we
  need to compile.
- Enums are now real structs instead of type-aliases and free constants.
This commit is contained in:
Mads Marquart 2024-04-18 17:34:19 +02:00 committed by GitHub
parent 575d978202
commit 259e868c05
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
38 changed files with 289 additions and 270 deletions

View file

@ -1,5 +1,5 @@
use icrate::Foundation::{MainThreadMarker, NSObject, NSObjectProtocol};
use objc2::{declare_class, mutability, ClassType, DeclaredClass};
use objc2_foundation::{MainThreadMarker, NSObject, NSObjectProtocol};
use super::app_state::{self, EventWrapper};
use super::uikit::{UIApplication, UIWindow};

View file

@ -16,12 +16,12 @@ use core_foundation::runloop::{
kCFRunLoopCommonModes, CFRunLoopAddTimer, CFRunLoopGetMain, CFRunLoopRef, CFRunLoopTimerCreate,
CFRunLoopTimerInvalidate, CFRunLoopTimerRef, CFRunLoopTimerSetNextFireDate,
};
use icrate::Foundation::{
CGRect, CGSize, MainThreadMarker, NSInteger, NSOperatingSystemVersion, NSProcessInfo,
};
use objc2::rc::Id;
use objc2::runtime::AnyObject;
use objc2::{msg_send, sel};
use objc2_foundation::{
CGRect, CGSize, MainThreadMarker, NSInteger, NSOperatingSystemVersion, NSProcessInfo,
};
use super::uikit::UIView;
use super::window::WinitUIWindow;

View file

@ -13,8 +13,8 @@ use core_foundation::runloop::{
CFRunLoopObserverCreate, CFRunLoopObserverRef, CFRunLoopSourceContext, CFRunLoopSourceCreate,
CFRunLoopSourceInvalidate, CFRunLoopSourceRef, CFRunLoopSourceSignal, CFRunLoopWakeUp,
};
use icrate::Foundation::{MainThreadMarker, NSString};
use objc2::ClassType;
use objc2_foundation::{MainThreadMarker, NSString};
use crate::{
error::EventLoopError,

View file

@ -5,10 +5,10 @@ use std::{
fmt, hash, ptr,
};
use icrate::Foundation::{MainThreadBound, MainThreadMarker, NSInteger};
use objc2::mutability::IsRetainable;
use objc2::rc::Id;
use objc2::Message;
use objc2_foundation::{run_on_main, MainThreadBound, MainThreadMarker, NSInteger};
use super::uikit::{UIScreen, UIScreenMode};
use crate::{
@ -23,7 +23,7 @@ struct MainThreadBoundDelegateImpls<T>(MainThreadBound<Id<T>>);
impl<T: IsRetainable + Message> Clone for MainThreadBoundDelegateImpls<T> {
fn clone(&self) -> Self {
Self(MainThreadMarker::run_on_main(|mtm| {
Self(run_on_main(|mtm| {
MainThreadBound::new(Id::clone(self.0.get(mtm)), mtm)
}))
}
@ -100,7 +100,7 @@ pub struct MonitorHandle {
impl Clone for MonitorHandle {
fn clone(&self) -> Self {
MainThreadMarker::run_on_main(|mtm| Self {
run_on_main(|mtm| Self {
ui_screen: MainThreadBound::new(self.ui_screen.get(mtm).clone(), mtm),
})
}
@ -155,7 +155,7 @@ impl MonitorHandle {
}
pub fn name(&self) -> Option<String> {
MainThreadMarker::run_on_main(|mtm| {
run_on_main(|mtm| {
let main = UIScreen::main(mtm);
if *self.ui_screen(mtm) == main {
Some("Primary".to_string())
@ -197,7 +197,7 @@ impl MonitorHandle {
}
pub fn video_modes(&self) -> impl Iterator<Item = VideoModeHandle> {
MainThreadMarker::run_on_main(|mtm| {
run_on_main(|mtm| {
let ui_screen = self.ui_screen(mtm);
// Use Ord impl of RootVideoModeHandle
@ -218,7 +218,7 @@ impl MonitorHandle {
}
pub fn preferred_video_mode(&self) -> VideoModeHandle {
MainThreadMarker::run_on_main(|mtm| {
run_on_main(|mtm| {
VideoModeHandle::new(
self.ui_screen(mtm).clone(),
self.ui_screen(mtm).preferredMode().unwrap(),

View file

@ -1,6 +1,6 @@
use icrate::Foundation::{CGRect, MainThreadMarker, NSArray, NSObject};
use objc2::rc::Id;
use objc2::{extern_class, extern_methods, msg_send_id, mutability, ClassType};
use objc2_foundation::{CGRect, MainThreadMarker, NSArray, NSObject};
use super::{UIResponder, UIWindow};

View file

@ -1,5 +1,5 @@
use icrate::Foundation::NSObject;
use objc2::{extern_class, mutability, ClassType};
use objc2_foundation::NSObject;
extern_class!(
#[derive(Debug, PartialEq, Eq, Hash)]

View file

@ -1,7 +1,7 @@
use icrate::Foundation::{MainThreadMarker, NSInteger, NSObject};
use objc2::encode::{Encode, Encoding};
use objc2::rc::Id;
use objc2::{extern_class, extern_methods, msg_send_id, mutability, ClassType};
use objc2_foundation::{MainThreadMarker, NSInteger, NSObject};
extern_class!(
#[derive(Debug, PartialEq, Eq, Hash)]

View file

@ -1,5 +1,5 @@
use icrate::Foundation::NSObject;
use objc2::{extern_class, mutability, ClassType};
use objc2_foundation::NSObject;
extern_class!(
#[derive(Debug, PartialEq, Eq, Hash)]

View file

@ -1,5 +1,5 @@
use icrate::Foundation::NSUInteger;
use objc2::encode::{Encode, Encoding};
use objc2_foundation::NSUInteger;
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]

View file

@ -1,8 +1,8 @@
use icrate::Foundation::{CGFloat, NSInteger, NSObject, NSUInteger};
use objc2::{
encode::{Encode, Encoding},
extern_class, extern_methods, mutability, ClassType,
};
use objc2_foundation::{CGFloat, NSInteger, NSObject, NSUInteger};
// https://developer.apple.com/documentation/uikit/uigesturerecognizer
extern_class!(

View file

@ -3,7 +3,7 @@
use std::os::raw::{c_char, c_int};
use icrate::Foundation::NSString;
use objc2_foundation::NSString;
mod application;
mod coordinate_space;

View file

@ -1,5 +1,5 @@
use icrate::Foundation::NSObject;
use objc2::{extern_class, mutability, ClassType};
use objc2_foundation::NSObject;
extern_class!(
#[derive(Debug, PartialEq, Eq, Hash)]

View file

@ -1,7 +1,7 @@
use icrate::Foundation::{CGFloat, CGRect, MainThreadMarker, NSArray, NSInteger, NSObject};
use objc2::encode::{Encode, Encoding};
use objc2::rc::Id;
use objc2::{extern_class, extern_methods, msg_send_id, mutability, ClassType};
use objc2_foundation::{CGFloat, CGRect, MainThreadMarker, NSArray, NSInteger, NSObject};
use super::{UICoordinateSpace, UIScreenMode};

View file

@ -1,5 +1,5 @@
use icrate::Foundation::{CGSize, NSObject};
use objc2::{extern_class, extern_methods, mutability, ClassType};
use objc2_foundation::{CGSize, NSObject};
extern_class!(
#[derive(Debug, PartialEq, Eq, Hash)]

View file

@ -1,5 +1,5 @@
use icrate::Foundation::NSInteger;
use objc2::encode::{Encode, Encoding};
use objc2_foundation::NSInteger;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[allow(dead_code)]

View file

@ -1,6 +1,6 @@
use icrate::Foundation::{CGFloat, CGPoint, NSInteger, NSObject};
use objc2::encode::{Encode, Encoding};
use objc2::{extern_class, extern_methods, mutability, ClassType};
use objc2_foundation::{CGFloat, CGPoint, NSInteger, NSObject};
use super::UIView;

View file

@ -1,6 +1,6 @@
use icrate::Foundation::{NSInteger, NSObject};
use objc2::encode::{Encode, Encoding};
use objc2::{extern_class, extern_methods, mutability, ClassType};
use objc2_foundation::{NSInteger, NSObject};
extern_class!(
#[derive(Debug, PartialEq, Eq, Hash)]

View file

@ -1,7 +1,7 @@
use icrate::Foundation::{CGFloat, CGRect, NSObject};
use objc2::encode::{Encode, Encoding};
use objc2::rc::Id;
use objc2::{extern_class, extern_methods, msg_send_id, mutability, ClassType};
use objc2_foundation::{CGFloat, CGRect, NSObject};
use super::{UICoordinateSpace, UIGestureRecognizer, UIResponder, UIViewController};

View file

@ -1,7 +1,7 @@
use icrate::Foundation::{NSObject, NSUInteger};
use objc2::encode::{Encode, Encoding};
use objc2::rc::Id;
use objc2::{extern_class, extern_methods, msg_send_id, mutability, ClassType};
use objc2_foundation::{NSObject, NSUInteger};
use super::{UIResponder, UIView};

View file

@ -1,6 +1,6 @@
use icrate::Foundation::NSObject;
use objc2::rc::Id;
use objc2::{extern_class, extern_methods, msg_send_id, mutability, ClassType};
use objc2_foundation::NSObject;
use super::{UIResponder, UIScreen, UIView};

View file

@ -1,12 +1,12 @@
#![allow(clippy::unnecessary_cast)]
use std::cell::RefCell;
use icrate::Foundation::{CGFloat, CGRect, MainThreadMarker, NSObject, NSSet};
use objc2::rc::Id;
use objc2::runtime::AnyClass;
use objc2::{
declare_class, extern_methods, msg_send, msg_send_id, mutability, sel, ClassType, DeclaredClass,
};
use objc2_foundation::{CGFloat, CGRect, MainThreadMarker, NSObject, NSSet};
use super::app_state::{self, EventWrapper};
use super::uikit::{

View file

@ -1,8 +1,8 @@
use std::cell::Cell;
use icrate::Foundation::{MainThreadMarker, NSObject};
use objc2::rc::Id;
use objc2::{declare_class, msg_send_id, mutability, ClassType, DeclaredClass};
use objc2_foundation::{MainThreadMarker, NSObject};
use super::app_state::{self};
use super::uikit::{

View file

@ -2,10 +2,10 @@
use std::collections::VecDeque;
use icrate::Foundation::{CGFloat, CGPoint, CGRect, CGSize, MainThreadBound, MainThreadMarker};
use objc2::rc::Id;
use objc2::runtime::{AnyObject, NSObject};
use objc2::{class, declare_class, msg_send, msg_send_id, mutability, ClassType, DeclaredClass};
use objc2_foundation::{CGFloat, CGPoint, CGRect, CGSize, MainThreadBound, MainThreadMarker};
use tracing::{debug, warn};
use super::app_state::EventWrapper;