From 18c09debea3070f7550bfbb48b8d3a0791720673 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Thu, 18 Apr 2024 00:13:08 +0200 Subject: [PATCH] Update objc2 crates - From objc2 0.5.0 to 0.5.1 - From icrate 0.1.0 to objc2-foundation 0.2.0 and objc2-app-kit 0.2.0 --- Cargo.toml | 97 +++++---- src/platform/ios.rs | 2 +- src/platform/macos.rs | 2 +- src/platform_impl/ios/app_delegate.rs | 2 +- src/platform_impl/ios/app_state.rs | 6 +- src/platform_impl/ios/event_loop.rs | 2 +- src/platform_impl/ios/monitor.rs | 12 +- src/platform_impl/ios/uikit/application.rs | 2 +- .../ios/uikit/coordinate_space.rs | 2 +- src/platform_impl/ios/uikit/device.rs | 2 +- src/platform_impl/ios/uikit/event.rs | 2 +- src/platform_impl/ios/uikit/geometry.rs | 2 +- .../ios/uikit/gesture_recognizer.rs | 2 +- src/platform_impl/ios/uikit/mod.rs | 2 +- src/platform_impl/ios/uikit/responder.rs | 2 +- src/platform_impl/ios/uikit/screen.rs | 2 +- src/platform_impl/ios/uikit/screen_mode.rs | 2 +- .../ios/uikit/status_bar_style.rs | 2 +- src/platform_impl/ios/uikit/touch.rs | 2 +- .../ios/uikit/trait_collection.rs | 2 +- src/platform_impl/ios/uikit/view.rs | 2 +- .../ios/uikit/view_controller.rs | 2 +- src/platform_impl/ios/uikit/window.rs | 2 +- src/platform_impl/ios/view.rs | 2 +- src/platform_impl/ios/view_controller.rs | 2 +- src/platform_impl/ios/window.rs | 2 +- src/platform_impl/macos/app.rs | 25 +-- src/platform_impl/macos/app_delegate.rs | 19 +- src/platform_impl/macos/cursor.rs | 12 +- src/platform_impl/macos/event.rs | 46 ++--- src/platform_impl/macos/event_loop.rs | 13 +- src/platform_impl/macos/menu.rs | 12 +- src/platform_impl/macos/monitor.rs | 6 +- src/platform_impl/macos/observer.rs | 2 +- src/platform_impl/macos/util.rs | 4 +- src/platform_impl/macos/view.rs | 68 +++---- src/platform_impl/macos/window.rs | 4 +- src/platform_impl/macos/window_delegate.rs | 185 +++++++++--------- 38 files changed, 288 insertions(+), 269 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5bc64bf0fcf..2846c35efbb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -88,58 +88,71 @@ ndk-sys = "0.5.0" [target.'cfg(any(target_os = "ios", target_os = "macos"))'.dependencies] core-foundation = "0.9.3" -objc2 = "0.5.0" +objc2 = "0.5.1" [target.'cfg(target_os = "macos")'.dependencies] core-graphics = "0.23.1" -[target.'cfg(target_os = "macos")'.dependencies.icrate] -version = "0.1.0" +[target.'cfg(target_os = "macos")'.dependencies.objc2-foundation] +version = "0.2.0" features = [ "dispatch", - "Foundation", - "Foundation_NSArray", - "Foundation_NSAttributedString", - "Foundation_NSMutableAttributedString", - "Foundation_NSData", - "Foundation_NSDictionary", - "Foundation_NSString", - "Foundation_NSProcessInfo", - "Foundation_NSThread", - "Foundation_NSNumber", - "AppKit", - "AppKit_NSAppearance", - "AppKit_NSApplication", - "AppKit_NSBitmapImageRep", - "AppKit_NSButton", - "AppKit_NSColor", - "AppKit_NSControl", - "AppKit_NSCursor", - "AppKit_NSEvent", - "AppKit_NSGraphicsContext", - "AppKit_NSImage", - "AppKit_NSImageRep", - "AppKit_NSMenu", - "AppKit_NSMenuItem", - "AppKit_NSPasteboard", - "AppKit_NSResponder", - "AppKit_NSScreen", - "AppKit_NSTextInputContext", - "AppKit_NSView", - "AppKit_NSWindow", - "AppKit_NSWindowTabGroup", + "NSArray", + "NSAttributedString", + "NSData", + "NSDictionary", + "NSEnumerator", + "NSObjCRuntime", + "NSString", + "NSPathUtilities", + "NSProcessInfo", + "NSThread", + "NSValue", ] -[target.'cfg(target_os = "ios")'.dependencies.icrate] -version = "0.1.0" +[target.'cfg(target_os = "macos")'.dependencies.objc2-app-kit] +version = "0.2.0" +features = [ + "NSAppearance", + "NSApplication", + "NSBitmapImageRep", + "NSButton", + "NSColor", + "NSControl", + "NSCursor", + "NSDragging", + "NSEvent", + "NSGraphics", + "NSGraphicsContext", + "NSImage", + "NSImageRep", + "NSMenu", + "NSMenuItem", + "NSOpenGLView", + "NSPasteboard", + "NSResponder", + "NSRunningApplication", + "NSScreen", + "NSTextInputClient", + "NSTextInputContext", + "NSView", + "NSWindow", + "NSWindowScripting", + "NSWindowTabGroup", +] + +[target.'cfg(target_os = "ios")'.dependencies.objc2-foundation] +version = "0.2.0" features = [ "dispatch", - "Foundation", - "Foundation_NSArray", - "Foundation_NSString", - "Foundation_NSProcessInfo", - "Foundation_NSThread", - "Foundation_NSSet", + "NSArray", + "NSEnumerator", + "NSGeometry", + "NSObjCRuntime", + "NSString", + "NSProcessInfo", + "NSThread", + "NSSet", ] [target.'cfg(target_os = "windows")'.dependencies] diff --git a/src/platform/ios.rs b/src/platform/ios.rs index 2d01628c8d3..2e8d4548f7d 100644 --- a/src/platform/ios.rs +++ b/src/platform/ios.rs @@ -336,7 +336,7 @@ impl MonitorHandleExtIOS for MonitorHandle { #[inline] fn ui_screen(&self) -> *mut c_void { // SAFETY: The marker is only used to get the pointer of the screen - let mtm = unsafe { icrate::Foundation::MainThreadMarker::new_unchecked() }; + let mtm = unsafe { objc2_foundation::MainThreadMarker::new_unchecked() }; objc2::rc::Id::as_ptr(self.inner.ui_screen(mtm)) as *mut c_void } diff --git a/src/platform/macos.rs b/src/platform/macos.rs index 4d74c94d96b..dafbd59b090 100644 --- a/src/platform/macos.rs +++ b/src/platform/macos.rs @@ -383,7 +383,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 { icrate::Foundation::MainThreadMarker::new_unchecked() }; + let mtm = unsafe { objc2_foundation::MainThreadMarker::new_unchecked() }; self.inner .ns_screen(mtm) .map(|s| objc2::rc::Id::as_ptr(&s) as _) diff --git a/src/platform_impl/ios/app_delegate.rs b/src/platform_impl/ios/app_delegate.rs index eb93cdf34cd..ecc02553e58 100644 --- a/src/platform_impl/ios/app_delegate.rs +++ b/src/platform_impl/ios/app_delegate.rs @@ -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}; diff --git a/src/platform_impl/ios/app_state.rs b/src/platform_impl/ios/app_state.rs index 40ef438484a..4ab33685bea 100644 --- a/src/platform_impl/ios/app_state.rs +++ b/src/platform_impl/ios/app_state.rs @@ -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; diff --git a/src/platform_impl/ios/event_loop.rs b/src/platform_impl/ios/event_loop.rs index 27921c1bedf..3064a0869f1 100644 --- a/src/platform_impl/ios/event_loop.rs +++ b/src/platform_impl/ios/event_loop.rs @@ -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, diff --git a/src/platform_impl/ios/monitor.rs b/src/platform_impl/ios/monitor.rs index dff73ba5060..d109401bfbb 100644 --- a/src/platform_impl/ios/monitor.rs +++ b/src/platform_impl/ios/monitor.rs @@ -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(MainThreadBound>); impl Clone for MainThreadBoundDelegateImpls { 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 { - 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 { - 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(), diff --git a/src/platform_impl/ios/uikit/application.rs b/src/platform_impl/ios/uikit/application.rs index fe64dec8239..ce9685cabe7 100644 --- a/src/platform_impl/ios/uikit/application.rs +++ b/src/platform_impl/ios/uikit/application.rs @@ -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}; diff --git a/src/platform_impl/ios/uikit/coordinate_space.rs b/src/platform_impl/ios/uikit/coordinate_space.rs index 790c4756336..3c3b9303d19 100644 --- a/src/platform_impl/ios/uikit/coordinate_space.rs +++ b/src/platform_impl/ios/uikit/coordinate_space.rs @@ -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)] diff --git a/src/platform_impl/ios/uikit/device.rs b/src/platform_impl/ios/uikit/device.rs index 5314e7b7519..24c57a948c3 100644 --- a/src/platform_impl/ios/uikit/device.rs +++ b/src/platform_impl/ios/uikit/device.rs @@ -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)] diff --git a/src/platform_impl/ios/uikit/event.rs b/src/platform_impl/ios/uikit/event.rs index fbaccf60522..d72159e981a 100644 --- a/src/platform_impl/ios/uikit/event.rs +++ b/src/platform_impl/ios/uikit/event.rs @@ -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)] diff --git a/src/platform_impl/ios/uikit/geometry.rs b/src/platform_impl/ios/uikit/geometry.rs index 7ad355d6c84..022160b640e 100644 --- a/src/platform_impl/ios/uikit/geometry.rs +++ b/src/platform_impl/ios/uikit/geometry.rs @@ -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)] diff --git a/src/platform_impl/ios/uikit/gesture_recognizer.rs b/src/platform_impl/ios/uikit/gesture_recognizer.rs index 77eca499a37..7afe759fff3 100644 --- a/src/platform_impl/ios/uikit/gesture_recognizer.rs +++ b/src/platform_impl/ios/uikit/gesture_recognizer.rs @@ -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!( diff --git a/src/platform_impl/ios/uikit/mod.rs b/src/platform_impl/ios/uikit/mod.rs index 3d09180dd9c..88d5a84656f 100644 --- a/src/platform_impl/ios/uikit/mod.rs +++ b/src/platform_impl/ios/uikit/mod.rs @@ -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; diff --git a/src/platform_impl/ios/uikit/responder.rs b/src/platform_impl/ios/uikit/responder.rs index fc5563f7ff6..108113624d2 100644 --- a/src/platform_impl/ios/uikit/responder.rs +++ b/src/platform_impl/ios/uikit/responder.rs @@ -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)] diff --git a/src/platform_impl/ios/uikit/screen.rs b/src/platform_impl/ios/uikit/screen.rs index 94a55b1634c..578fff5d592 100644 --- a/src/platform_impl/ios/uikit/screen.rs +++ b/src/platform_impl/ios/uikit/screen.rs @@ -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}; diff --git a/src/platform_impl/ios/uikit/screen_mode.rs b/src/platform_impl/ios/uikit/screen_mode.rs index 096cae49f9a..1d86c96f00d 100644 --- a/src/platform_impl/ios/uikit/screen_mode.rs +++ b/src/platform_impl/ios/uikit/screen_mode.rs @@ -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)] diff --git a/src/platform_impl/ios/uikit/status_bar_style.rs b/src/platform_impl/ios/uikit/status_bar_style.rs index 775ddb1f264..6c4aaf756e2 100644 --- a/src/platform_impl/ios/uikit/status_bar_style.rs +++ b/src/platform_impl/ios/uikit/status_bar_style.rs @@ -1,4 +1,4 @@ -use icrate::Foundation::NSInteger; +use objc2_foundation::NSInteger; use objc2::encode::{Encode, Encoding}; #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] diff --git a/src/platform_impl/ios/uikit/touch.rs b/src/platform_impl/ios/uikit/touch.rs index bff0e8fb35e..6db47642b0c 100644 --- a/src/platform_impl/ios/uikit/touch.rs +++ b/src/platform_impl/ios/uikit/touch.rs @@ -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; diff --git a/src/platform_impl/ios/uikit/trait_collection.rs b/src/platform_impl/ios/uikit/trait_collection.rs index b6af7c9d786..13c6834f2cb 100644 --- a/src/platform_impl/ios/uikit/trait_collection.rs +++ b/src/platform_impl/ios/uikit/trait_collection.rs @@ -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)] diff --git a/src/platform_impl/ios/uikit/view.rs b/src/platform_impl/ios/uikit/view.rs index 429627d8e70..719b7c4d6df 100644 --- a/src/platform_impl/ios/uikit/view.rs +++ b/src/platform_impl/ios/uikit/view.rs @@ -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}; diff --git a/src/platform_impl/ios/uikit/view_controller.rs b/src/platform_impl/ios/uikit/view_controller.rs index 48121ea9627..80d9e8960dd 100644 --- a/src/platform_impl/ios/uikit/view_controller.rs +++ b/src/platform_impl/ios/uikit/view_controller.rs @@ -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}; diff --git a/src/platform_impl/ios/uikit/window.rs b/src/platform_impl/ios/uikit/window.rs index b99e96d4797..28cbef87c14 100644 --- a/src/platform_impl/ios/uikit/window.rs +++ b/src/platform_impl/ios/uikit/window.rs @@ -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}; diff --git a/src/platform_impl/ios/view.rs b/src/platform_impl/ios/view.rs index 3f3fa8b6cbf..79a1eb95468 100644 --- a/src/platform_impl/ios/view.rs +++ b/src/platform_impl/ios/view.rs @@ -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::{ diff --git a/src/platform_impl/ios/view_controller.rs b/src/platform_impl/ios/view_controller.rs index 94fa01d43df..8e2cf12b05b 100644 --- a/src/platform_impl/ios/view_controller.rs +++ b/src/platform_impl/ios/view_controller.rs @@ -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::{ diff --git a/src/platform_impl/ios/window.rs b/src/platform_impl/ios/window.rs index 03f63cc73e3..7fd5b6a4289 100644 --- a/src/platform_impl/ios/window.rs +++ b/src/platform_impl/ios/window.rs @@ -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; diff --git a/src/platform_impl/macos/app.rs b/src/platform_impl/macos/app.rs index d3dee9827ea..a97ae57d731 100644 --- a/src/platform_impl/macos/app.rs +++ b/src/platform_impl/macos/app.rs @@ -1,13 +1,8 @@ #![allow(clippy::unnecessary_cast)] -use icrate::AppKit::{ - NSApplication, NSEvent, NSEventModifierFlagCommand, NSEventTypeKeyUp, NSEventTypeLeftMouseDown, - NSEventTypeLeftMouseDragged, NSEventTypeLeftMouseUp, NSEventTypeMouseMoved, - NSEventTypeOtherMouseDown, NSEventTypeOtherMouseDragged, NSEventTypeOtherMouseUp, - NSEventTypeRightMouseDown, NSEventTypeRightMouseDragged, NSEventTypeRightMouseUp, NSResponder, -}; -use icrate::Foundation::{MainThreadMarker, NSObject}; use objc2::{declare_class, msg_send, mutability, ClassType, DeclaredClass}; +use objc2_app_kit::{NSApplication, NSEvent, NSEventModifierFlags, NSEventType, NSResponder}; +use objc2_foundation::{MainThreadMarker, NSObject}; use super::app_delegate::ApplicationDelegate; use super::event::flags_contains; @@ -36,8 +31,8 @@ declare_class!( // but that doesn't really matter here. let event_type = unsafe { event.r#type() }; let modifier_flags = unsafe { event.modifierFlags() }; - if event_type == NSEventTypeKeyUp - && flags_contains(modifier_flags, NSEventModifierFlagCommand) + if event_type == NSEventType::KeyUp + && flags_contains(modifier_flags, NSEventModifierFlags::NSEventModifierFlagCommand) { if let Some(key_window) = self.keyWindow() { key_window.sendEvent(event); @@ -55,10 +50,10 @@ fn maybe_dispatch_device_event(delegate: &ApplicationDelegate, event: &NSEvent) let event_type = unsafe { event.r#type() }; #[allow(non_upper_case_globals)] match event_type { - NSEventTypeMouseMoved - | NSEventTypeLeftMouseDragged - | NSEventTypeOtherMouseDragged - | NSEventTypeRightMouseDragged => { + NSEventType::MouseMoved + | NSEventType::LeftMouseDragged + | NSEventType::OtherMouseDragged + | NSEventType::RightMouseDragged => { let delta_x = unsafe { event.deltaX() } as f64; let delta_y = unsafe { event.deltaY() } as f64; @@ -82,13 +77,13 @@ fn maybe_dispatch_device_event(delegate: &ApplicationDelegate, event: &NSEvent) }); } } - NSEventTypeLeftMouseDown | NSEventTypeRightMouseDown | NSEventTypeOtherMouseDown => { + NSEventType::LeftMouseDown | NSEventType::RightMouseDown | NSEventType::OtherMouseDown => { delegate.queue_device_event(DeviceEvent::Button { button: unsafe { event.buttonNumber() } as u32, state: ElementState::Pressed, }); } - NSEventTypeLeftMouseUp | NSEventTypeRightMouseUp | NSEventTypeOtherMouseUp => { + NSEventType::LeftMouseUp | NSEventType::RightMouseUp | NSEventType::OtherMouseUp => { delegate.queue_device_event(DeviceEvent::Button { button: unsafe { event.buttonNumber() } as u32, state: ElementState::Released, diff --git a/src/platform_impl/macos/app_delegate.rs b/src/platform_impl/macos/app_delegate.rs index 7d528ab2f3c..0c396fec130 100644 --- a/src/platform_impl/macos/app_delegate.rs +++ b/src/platform_impl/macos/app_delegate.rs @@ -5,11 +5,11 @@ use std::rc::Weak; use std::sync::{Arc, Mutex}; use std::time::Instant; -use icrate::AppKit::{NSApplication, NSApplicationActivationPolicy, NSApplicationDelegate}; -use icrate::Foundation::{MainThreadMarker, NSObject, NSObjectProtocol, NSSize}; use objc2::rc::Id; use objc2::runtime::AnyObject; use objc2::{declare_class, msg_send_id, mutability, ClassType, DeclaredClass}; +use objc2_app_kit::{NSApplication, NSApplicationActivationPolicy, NSApplicationDelegate}; +use objc2_foundation::{MainThreadMarker, NSObject, NSObjectProtocol, NSSize}; use super::event_handler::EventHandler; use super::event_loop::{stop_app_immediately, ActiveEventLoop, PanicInfo}; @@ -21,9 +21,18 @@ use crate::event::{DeviceEvent, Event, InnerSizeWriter, StartCause, WindowEvent} use crate::event_loop::{ActiveEventLoop as RootActiveEventLoop, ControlFlow}; use crate::window::WindowId as RootWindowId; +#[derive(Debug)] +struct Policy(NSApplicationActivationPolicy); + +impl Default for Policy { + fn default() -> Self { + Self(NSApplicationActivationPolicy::Regular) + } +} + #[derive(Debug, Default)] pub(super) struct State { - activation_policy: NSApplicationActivationPolicy, + activation_policy: Policy, default_menu: bool, activate_ignoring_other_apps: bool, event_handler: EventHandler, @@ -74,7 +83,7 @@ declare_class!( // We need to delay setting the activation policy and activating the app // until `applicationDidFinishLaunching` has been called. Otherwise the // menu bar is initially unresponsive on macOS 10.15. - app.setActivationPolicy(self.ivars().activation_policy); + app.setActivationPolicy(self.ivars().activation_policy.0); window_activation_hack(&app); #[allow(deprecated)] @@ -124,7 +133,7 @@ impl ApplicationDelegate { activate_ignoring_other_apps: bool, ) -> Id { let this = mtm.alloc().set_ivars(State { - activation_policy, + activation_policy: Policy(activation_policy), default_menu, activate_ignoring_other_apps, ..Default::default() diff --git a/src/platform_impl/macos/cursor.rs b/src/platform_impl/macos/cursor.rs index afa4fe88391..6d06393d068 100644 --- a/src/platform_impl/macos/cursor.rs +++ b/src/platform_impl/macos/cursor.rs @@ -2,14 +2,14 @@ use std::ffi::c_uchar; use std::slice; use std::sync::OnceLock; -use icrate::AppKit::{NSBitmapImageRep, NSCursor, NSDeviceRGBColorSpace, NSImage}; -use icrate::Foundation::{ - ns_string, NSData, NSDictionary, NSNumber, NSObject, NSObjectProtocol, NSPoint, NSSize, - NSString, -}; use objc2::rc::Id; use objc2::runtime::Sel; use objc2::{msg_send_id, sel, ClassType}; +use objc2_app_kit::{NSBitmapImageRep, NSCursor, NSDeviceRGBColorSpace, NSImage}; +use objc2_foundation::{ + ns_string, NSData, NSDictionary, NSNumber, NSObject, NSObjectProtocol, NSPoint, NSSize, + NSString, +}; use crate::cursor::CursorImage; use crate::cursor::OnlyCursorImageSource; @@ -19,7 +19,7 @@ use crate::window::CursorIcon; pub struct CustomCursor(pub(crate) Id); // SAFETY: NSCursor is immutable and thread-safe -// TODO(madsmtm): Put this logic in icrate itself +// TODO(madsmtm): Put this logic in objc2-app-kit itself unsafe impl Send for CustomCursor {} unsafe impl Sync for CustomCursor {} diff --git a/src/platform_impl/macos/event.rs b/src/platform_impl/macos/event.rs index 103eae38b25..d83d2ca7d06 100644 --- a/src/platform_impl/macos/event.rs +++ b/src/platform_impl/macos/event.rs @@ -4,13 +4,9 @@ use core_foundation::{ base::CFRelease, data::{CFDataGetBytePtr, CFDataRef}, }; -use icrate::AppKit::{ - NSEvent, NSEventModifierFlagCommand, NSEventModifierFlagControl, NSEventModifierFlagOption, - NSEventModifierFlagShift, NSEventModifierFlags, NSEventSubtypeWindowExposed, - NSEventTypeApplicationDefined, -}; -use icrate::Foundation::{MainThreadMarker, NSPoint}; use objc2::rc::Id; +use objc2_app_kit::{NSEvent, NSEventModifierFlags, NSEventSubtype, NSEventType}; +use objc2_foundation::{run_on_main, NSPoint}; use smol_str::SmolStr; use crate::{ @@ -48,7 +44,7 @@ pub fn get_modifierless_char(scancode: u16) -> Key { } layout = CFDataGetBytePtr(layout_data as CFDataRef) as *const ffi::UCKeyboardLayout; } - let keyboard_type = MainThreadMarker::run_on_main(|_mtm| unsafe { ffi::LMGetKbdType() }); + let keyboard_type = run_on_main(|_mtm| unsafe { ffi::LMGetKbdType() }); let mut result_len = 0; let mut dead_keys = 0; @@ -145,8 +141,8 @@ pub(crate) fn create_key_event( let key_without_modifiers = get_modifierless_char(scancode); let modifiers = unsafe { ns_event.modifierFlags() }; - let has_ctrl = flags_contains(modifiers, NSEventModifierFlagControl); - let has_cmd = flags_contains(modifiers, NSEventModifierFlagCommand); + let has_ctrl = flags_contains(modifiers, NSEventModifierFlags::NSEventModifierFlagControl); + let has_cmd = flags_contains(modifiers, NSEventModifierFlags::NSEventModifierFlagCommand); let logical_key = match text_with_all_modifiers.as_ref() { // Only checking for ctrl and cmd here, not checking for alt because we DO want to @@ -315,17 +311,17 @@ pub fn extra_function_key_to_code(scancode: u16, string: &str) -> PhysicalKey { } // The values are from the https://github.com/apple-oss-distributions/IOHIDFamily/blob/19666c840a6d896468416ff0007040a10b7b46b8/IOHIDSystem/IOKit/hidsystem/IOLLEvent.h#L258-L259 -const NX_DEVICELCTLKEYMASK: NSEventModifierFlags = 0x00000001; -const NX_DEVICELSHIFTKEYMASK: NSEventModifierFlags = 0x00000002; -const NX_DEVICERSHIFTKEYMASK: NSEventModifierFlags = 0x00000004; -const NX_DEVICELCMDKEYMASK: NSEventModifierFlags = 0x00000008; -const NX_DEVICERCMDKEYMASK: NSEventModifierFlags = 0x00000010; -const NX_DEVICELALTKEYMASK: NSEventModifierFlags = 0x00000020; -const NX_DEVICERALTKEYMASK: NSEventModifierFlags = 0x00000040; -const NX_DEVICERCTLKEYMASK: NSEventModifierFlags = 0x00002000; +const NX_DEVICELCTLKEYMASK: NSEventModifierFlags = NSEventModifierFlags(0x00000001); +const NX_DEVICELSHIFTKEYMASK: NSEventModifierFlags = NSEventModifierFlags(0x00000002); +const NX_DEVICERSHIFTKEYMASK: NSEventModifierFlags = NSEventModifierFlags(0x00000004); +const NX_DEVICELCMDKEYMASK: NSEventModifierFlags = NSEventModifierFlags(0x00000008); +const NX_DEVICERCMDKEYMASK: NSEventModifierFlags = NSEventModifierFlags(0x00000010); +const NX_DEVICELALTKEYMASK: NSEventModifierFlags = NSEventModifierFlags(0x00000020); +const NX_DEVICERALTKEYMASK: NSEventModifierFlags = NSEventModifierFlags(0x00000040); +const NX_DEVICERCTLKEYMASK: NSEventModifierFlags = NSEventModifierFlags(0x00002000); pub(super) fn flags_contains(flags: NSEventModifierFlags, value: NSEventModifierFlags) -> bool { - flags & value == value + flags.0 & value.0 == value.0 } pub(super) fn lalt_pressed(event: &NSEvent) -> bool { @@ -343,7 +339,7 @@ pub(super) fn event_mods(event: &NSEvent) -> Modifiers { state.set( ModifiersState::SHIFT, - flags_contains(flags, NSEventModifierFlagShift), + flags_contains(flags, NSEventModifierFlags::NSEventModifierFlagShift), ); pressed_mods.set( ModifiersKeys::LSHIFT, @@ -356,7 +352,7 @@ pub(super) fn event_mods(event: &NSEvent) -> Modifiers { state.set( ModifiersState::CONTROL, - flags_contains(flags, NSEventModifierFlagControl), + flags_contains(flags, NSEventModifierFlags::NSEventModifierFlagControl), ); pressed_mods.set( ModifiersKeys::LCONTROL, @@ -369,7 +365,7 @@ pub(super) fn event_mods(event: &NSEvent) -> Modifiers { state.set( ModifiersState::ALT, - flags_contains(flags, NSEventModifierFlagOption), + flags_contains(flags, NSEventModifierFlags::NSEventModifierFlagOption), ); pressed_mods.set( ModifiersKeys::LALT, @@ -382,7 +378,7 @@ pub(super) fn event_mods(event: &NSEvent) -> Modifiers { state.set( ModifiersState::SUPER, - flags_contains(flags, NSEventModifierFlagCommand), + flags_contains(flags, NSEventModifierFlags::NSEventModifierFlagCommand), ); pressed_mods.set( ModifiersKeys::LSUPER, @@ -402,13 +398,13 @@ pub(super) fn event_mods(event: &NSEvent) -> Modifiers { pub(super) fn dummy_event() -> Option> { unsafe { NSEvent::otherEventWithType_location_modifierFlags_timestamp_windowNumber_context_subtype_data1_data2( - NSEventTypeApplicationDefined, + NSEventType::ApplicationDefined, NSPoint::new(0.0, 0.0), - 0, // Empty NSEventModifierFlags + NSEventModifierFlags(0), 0.0, 0, None, - NSEventSubtypeWindowExposed, + NSEventSubtype::WindowExposed.0, 0, 0, ) diff --git a/src/platform_impl/macos/event_loop.rs b/src/platform_impl/macos/event_loop.rs index 1e0e34ee37d..56f802d524c 100644 --- a/src/platform_impl/macos/event_loop.rs +++ b/src/platform_impl/macos/event_loop.rs @@ -16,16 +16,13 @@ use core_foundation::runloop::{ kCFRunLoopCommonModes, CFRunLoopAddSource, CFRunLoopGetMain, CFRunLoopSourceContext, CFRunLoopSourceCreate, CFRunLoopSourceRef, CFRunLoopSourceSignal, CFRunLoopWakeUp, }; -use icrate::AppKit::{ - NSApplication, NSApplicationActivationPolicyAccessory, NSApplicationActivationPolicyProhibited, - NSApplicationActivationPolicyRegular, NSWindow, -}; -use icrate::Foundation::{MainThreadMarker, NSObjectProtocol}; use objc2::{msg_send_id, ClassType}; use objc2::{ rc::{autoreleasepool, Id}, runtime::ProtocolObject, }; +use objc2_app_kit::{NSApplication, NSApplicationActivationPolicy, NSWindow}; +use objc2_foundation::{MainThreadMarker, NSObjectProtocol}; use super::event::dummy_event; use super::{ @@ -232,9 +229,9 @@ impl EventLoop { } let activation_policy = match attributes.activation_policy { - ActivationPolicy::Regular => NSApplicationActivationPolicyRegular, - ActivationPolicy::Accessory => NSApplicationActivationPolicyAccessory, - ActivationPolicy::Prohibited => NSApplicationActivationPolicyProhibited, + ActivationPolicy::Regular => NSApplicationActivationPolicy::Regular, + ActivationPolicy::Accessory => NSApplicationActivationPolicy::Accessory, + ActivationPolicy::Prohibited => NSApplicationActivationPolicy::Prohibited, }; let delegate = ApplicationDelegate::new( mtm, diff --git a/src/platform_impl/macos/menu.rs b/src/platform_impl/macos/menu.rs index 6d6142d9bee..319047331db 100644 --- a/src/platform_impl/macos/menu.rs +++ b/src/platform_impl/macos/menu.rs @@ -1,11 +1,8 @@ -use icrate::AppKit::{ - NSApplication, NSEventModifierFlagCommand, NSEventModifierFlagOption, NSEventModifierFlags, - NSMenu, NSMenuItem, -}; -use icrate::Foundation::{ns_string, MainThreadMarker, NSProcessInfo, NSString}; use objc2::rc::Id; use objc2::runtime::Sel; use objc2::sel; +use objc2_app_kit::{NSApplication, NSEventModifierFlags, NSMenu, NSMenuItem}; +use objc2_foundation::{ns_string, MainThreadMarker, NSProcessInfo, NSString}; struct KeyEquivalent<'a> { key: &'a NSString, @@ -58,7 +55,10 @@ pub fn initialize(app: &NSApplication) { Some(sel!(hideOtherApplications:)), Some(KeyEquivalent { key: ns_string!("h"), - masks: Some(NSEventModifierFlagOption | NSEventModifierFlagCommand), + masks: Some(NSEventModifierFlags( + NSEventModifierFlags::NSEventModifierFlagOption.0 + | NSEventModifierFlags::NSEventModifierFlagCommand.0, + )), }), ); diff --git a/src/platform_impl/macos/monitor.rs b/src/platform_impl/macos/monitor.rs index 17972c9d962..a47ba6674d2 100644 --- a/src/platform_impl/macos/monitor.rs +++ b/src/platform_impl/macos/monitor.rs @@ -10,9 +10,9 @@ use core_foundation::{ use core_graphics::display::{ CGDirectDisplayID, CGDisplay, CGDisplayBounds, CGDisplayCopyDisplayMode, }; -use icrate::AppKit::NSScreen; -use icrate::Foundation::{ns_string, MainThreadMarker, NSNumber, NSPoint, NSRect}; use objc2::{rc::Id, runtime::AnyObject}; +use objc2_app_kit::NSScreen; +use objc2_foundation::{ns_string, run_on_main, MainThreadMarker, NSNumber, NSPoint, NSRect}; use super::ffi; use crate::dpi::{LogicalPosition, PhysicalPosition, PhysicalSize}; @@ -203,7 +203,7 @@ impl MonitorHandle { } pub fn scale_factor(&self) -> f64 { - MainThreadMarker::run_on_main(|mtm| { + run_on_main(|mtm| { match self.ns_screen(mtm) { Some(screen) => screen.backingScaleFactor() as f64, None => 1.0, // default to 1.0 when we can't find the screen diff --git a/src/platform_impl/macos/observer.rs b/src/platform_impl/macos/observer.rs index 3317595fd5d..ca5dd5f18d2 100644 --- a/src/platform_impl/macos/observer.rs +++ b/src/platform_impl/macos/observer.rs @@ -15,7 +15,7 @@ use core_foundation::runloop::{ CFRunLoopObserverRef, CFRunLoopRef, CFRunLoopTimerCreate, CFRunLoopTimerInvalidate, CFRunLoopTimerRef, CFRunLoopTimerSetNextFireDate, CFRunLoopWakeUp, }; -use icrate::Foundation::MainThreadMarker; +use objc2_foundation::MainThreadMarker; use super::ffi; use super::{ diff --git a/src/platform_impl/macos/util.rs b/src/platform_impl/macos/util.rs index 1fb8468719b..4a1b7cb425e 100644 --- a/src/platform_impl/macos/util.rs +++ b/src/platform_impl/macos/util.rs @@ -1,7 +1,7 @@ -use icrate::Foundation::{NSNotFound, NSRange, NSUInteger}; +use objc2_foundation::{NSNotFound, NSRange, NSUInteger}; use tracing::trace; -pub const EMPTY_RANGE: NSRange = NSRange { +pub static EMPTY_RANGE: NSRange = NSRange { location: NSNotFound as NSUInteger, length: 0, }; diff --git a/src/platform_impl/macos/view.rs b/src/platform_impl/macos/view.rs index 382813bcec7..63e9dd05885 100644 --- a/src/platform_impl/macos/view.rs +++ b/src/platform_impl/macos/view.rs @@ -3,21 +3,20 @@ use std::cell::{Cell, RefCell}; use std::collections::{HashMap, VecDeque}; use std::ptr; -use icrate::AppKit::{ - NSApplication, NSCursor, NSEvent, NSEventPhaseBegan, NSEventPhaseCancelled, - NSEventPhaseChanged, NSEventPhaseEnded, NSEventPhaseMayBegin, NSResponder, NSTextInputClient, +use objc2::rc::{Id, WeakId}; +use objc2::runtime::{AnyObject, Sel}; +use objc2::{ + class, declare_class, msg_send, msg_send_id, mutability, sel, ClassType, DeclaredClass, +}; +use objc2_app_kit::{ + NSApplication, NSCursor, NSEvent, NSEventPhase, NSResponder, NSTextInputClient, NSTrackingRectTag, NSView, }; -use icrate::Foundation::{ +use objc2_foundation::{ MainThreadMarker, NSArray, NSAttributedString, NSAttributedStringKey, NSCopying, NSMutableAttributedString, NSObject, NSObjectProtocol, NSPoint, NSRange, NSRect, NSSize, NSString, NSUInteger, }; -use objc2::rc::{Id, WeakId}; -use objc2::runtime::{AnyObject, Sel}; -use objc2::{ - class, declare_class, msg_send, msg_send_id, mutability, sel, ClassType, DeclaredClass, -}; use super::app_delegate::ApplicationDelegate; use super::cursor::{default_cursor, invisible_cursor}; @@ -175,7 +174,9 @@ declare_class!( } let rect = self.frame(); - let tracking_rect = unsafe { self.addTrackingRect_owner_userData_assumeInside(rect, self, ptr::null_mut(), false) }; + let tracking_rect = unsafe { + self.addTrackingRect_owner_userData_assumeInside(rect, self, ptr::null_mut(), false) + }; assert_ne!(tracking_rect, 0, "failed adding tracking rect"); self.ivars().tracking_rect.set(Some(tracking_rect)); } @@ -188,7 +189,9 @@ declare_class!( } let rect = self.frame(); - let tracking_rect = unsafe { self.addTrackingRect_owner_userData_assumeInside(rect, self, ptr::null_mut(), false) }; + let tracking_rect = unsafe { + self.addTrackingRect_owner_userData_assumeInside(rect, self, ptr::null_mut(), false) + }; assert_ne!(tracking_rect, 0, "failed adding tracking rect"); self.ivars().tracking_rect.set(Some(tracking_rect)); @@ -371,9 +374,13 @@ declare_class!( _actual_range: *mut NSRange, ) -> NSRect { trace_scope!("firstRectForCharacterRange:actualRange:"); - let rect = dbg!(NSRect::new(self.ivars().ime_position.get(), self.ivars().ime_size.get())); + let rect = dbg!(NSRect::new( + self.ivars().ime_position.get(), + self.ivars().ime_size.get() + )); // Return value is expected to be in screen coordinates, so we need a conversion here - unsafe { self.window().convertRectToScreen(self.convertRect_toView(rect, None)) } + self.window() + .convertRectToScreen(self.convertRect_toView(rect, None)) } #[method(insertText:replacementRange:)] @@ -415,7 +422,8 @@ declare_class!( self.ivars().forward_key_to_app.set(true); - if unsafe { self.hasMarkedText() } && self.ivars().ime_state.get() == ImeState::Preedit { + if unsafe { self.hasMarkedText() } && self.ivars().ime_state.get() == ImeState::Preedit + { // Leave preedit so that we also report the key-up for this key. self.ivars().ime_state.set(ImeState::Ground); } @@ -666,19 +674,11 @@ declare_class!( // report the touch phase. #[allow(non_upper_case_globals)] let phase = match unsafe { event.momentumPhase() } { - NSEventPhaseMayBegin | NSEventPhaseBegan => { - TouchPhase::Started - } - NSEventPhaseEnded | NSEventPhaseCancelled => { - TouchPhase::Ended - } + NSEventPhase::MayBegin | NSEventPhase::Began => TouchPhase::Started, + NSEventPhase::Ended | NSEventPhase::Cancelled => TouchPhase::Ended, _ => match unsafe { event.phase() } { - NSEventPhaseMayBegin | NSEventPhaseBegan => { - TouchPhase::Started - } - NSEventPhaseEnded | NSEventPhaseCancelled => { - TouchPhase::Ended - } + NSEventPhase::MayBegin | NSEventPhase::Began => TouchPhase::Started, + NSEventPhase::Ended | NSEventPhase::Cancelled => TouchPhase::Ended, _ => TouchPhase::Moved, }, }; @@ -701,10 +701,10 @@ declare_class!( #[allow(non_upper_case_globals)] let phase = match unsafe { event.phase() } { - NSEventPhaseBegan => TouchPhase::Started, - NSEventPhaseChanged => TouchPhase::Moved, - NSEventPhaseCancelled => TouchPhase::Cancelled, - NSEventPhaseEnded => TouchPhase::Ended, + NSEventPhase::Began => TouchPhase::Started, + NSEventPhase::Changed => TouchPhase::Moved, + NSEventPhase::Cancelled => TouchPhase::Cancelled, + NSEventPhase::Ended => TouchPhase::Ended, _ => return, }; @@ -734,10 +734,10 @@ declare_class!( #[allow(non_upper_case_globals)] let phase = match unsafe { event.phase() } { - NSEventPhaseBegan => TouchPhase::Started, - NSEventPhaseChanged => TouchPhase::Moved, - NSEventPhaseCancelled => TouchPhase::Cancelled, - NSEventPhaseEnded => TouchPhase::Ended, + NSEventPhase::Began => TouchPhase::Started, + NSEventPhase::Changed => TouchPhase::Moved, + NSEventPhase::Cancelled => TouchPhase::Cancelled, + NSEventPhase::Ended => TouchPhase::Ended, _ => return, }; diff --git a/src/platform_impl/macos/window.rs b/src/platform_impl/macos/window.rs index a70deacd51a..e585c78002c 100644 --- a/src/platform_impl/macos/window.rs +++ b/src/platform_impl/macos/window.rs @@ -1,9 +1,9 @@ #![allow(clippy::unnecessary_cast)] -use icrate::AppKit::{NSResponder, NSWindow}; -use icrate::Foundation::{MainThreadBound, MainThreadMarker, NSObject}; use objc2::rc::{autoreleasepool, Id}; use objc2::{declare_class, mutability, ClassType, DeclaredClass}; +use objc2_app_kit::{NSResponder, NSWindow}; +use objc2_foundation::{MainThreadBound, MainThreadMarker, NSObject}; use super::event_loop::ActiveEventLoop; use super::window_delegate::WindowDelegate; diff --git a/src/platform_impl/macos/window_delegate.rs b/src/platform_impl/macos/window_delegate.rs index d00257f4cc1..bbb958aa75e 100644 --- a/src/platform_impl/macos/window_delegate.rs +++ b/src/platform_impl/macos/window_delegate.rs @@ -4,29 +4,24 @@ use std::collections::VecDeque; use std::ptr; use core_graphics::display::{CGDisplay, CGPoint}; -use icrate::AppKit::{ - NSAppKitVersionNumber, NSAppKitVersionNumber10_12, NSAppearance, NSApplication, - NSApplicationPresentationAutoHideDock, NSApplicationPresentationAutoHideMenuBar, - NSApplicationPresentationFullScreen, NSApplicationPresentationHideDock, - NSApplicationPresentationHideMenuBar, NSApplicationPresentationOptions, NSBackingStoreBuffered, - NSColor, NSCriticalRequest, NSDraggingDestination, NSFilenamesPboardType, - NSInformationalRequest, NSPasteboard, NSScreen, NSView, NSWindowAbove, NSWindowCloseButton, - NSWindowDelegate, NSWindowFullScreenButton, NSWindowLevel, NSWindowMiniaturizeButton, - NSWindowOcclusionStateVisible, NSWindowSharingNone, NSWindowSharingReadOnly, NSWindowStyleMask, - NSWindowStyleMaskBorderless, NSWindowStyleMaskClosable, NSWindowStyleMaskFullSizeContentView, - NSWindowStyleMaskMiniaturizable, NSWindowStyleMaskResizable, NSWindowStyleMaskTitled, - NSWindowTabbingModePreferred, NSWindowTitleHidden, NSWindowZoomButton, -}; -use icrate::Foundation::{ - CGFloat, MainThreadMarker, NSArray, NSCopying, NSObject, NSObjectProtocol, NSPoint, NSRect, - NSSize, NSString, -}; use monitor::VideoModeHandle; use objc2::rc::{autoreleasepool, Id}; use objc2::runtime::{AnyObject, ProtocolObject}; use objc2::{ class, declare_class, msg_send, msg_send_id, mutability, sel, ClassType, DeclaredClass, }; +use objc2_app_kit::{ + NSAppKitVersionNumber, NSAppKitVersionNumber10_12, NSAppearance, NSApplication, + NSApplicationPresentationOptions, NSBackingStoreType, NSColor, NSDraggingDestination, + NSFilenamesPboardType, NSPasteboard, NSRequestUserAttentionType, NSScreen, NSView, + NSWindowButton, NSWindowDelegate, NSWindowFullScreenButton, NSWindowLevel, + NSWindowOcclusionState, NSWindowOrderingMode, NSWindowSharingType, NSWindowStyleMask, + NSWindowTabbingMode, NSWindowTitleVisibility, +}; +use objc2_foundation::{ + CGFloat, MainThreadMarker, NSArray, NSCopying, NSObject, NSObjectProtocol, NSPoint, NSRect, + NSSize, NSString, +}; use super::app_delegate::ApplicationDelegate; use super::cursor::cursor_from_icon; @@ -266,9 +261,11 @@ declare_class!( let mut options = proposed_options; let fullscreen = self.ivars().fullscreen.borrow(); if let Some(Fullscreen::Exclusive(_)) = &*fullscreen { - options = NSApplicationPresentationFullScreen - | NSApplicationPresentationHideDock - | NSApplicationPresentationHideMenuBar; + options = NSApplicationPresentationOptions( + NSApplicationPresentationOptions::NSApplicationPresentationFullScreen.0 + | NSApplicationPresentationOptions::NSApplicationPresentationHideDock.0 + | NSApplicationPresentationOptions::NSApplicationPresentationHideMenuBar.0, + ); } options @@ -337,8 +334,8 @@ declare_class!( #[method(windowDidChangeOcclusionState:)] fn window_did_change_occlusion_state(&self, _: Option<&AnyObject>) { trace_scope!("windowDidChangeOcclusionState:"); - let visible = self.window().occlusionState() & NSWindowOcclusionStateVisible - == NSWindowOcclusionStateVisible; + let visible = self.window().occlusionState().0 & NSWindowOcclusionState::Visible.0 + == NSWindowOcclusionState::Visible.0; self.queue_event(WindowEvent::Occluded(!visible)); } @@ -490,39 +487,39 @@ fn new_window(attrs: &WindowAttributes, mtm: MainThreadMarker) -> Option> = unsafe { msg_send_id![ super(mtm.alloc().set_ivars(())), initWithContentRect: frame, - styleMask: masks, - backing: NSBackingStoreBuffered, + styleMask: NSWindowStyleMask(masks), + backing: NSBackingStoreType::NSBackingStoreBuffered, defer: false, ] }; @@ -538,26 +535,26 @@ fn new_window(attrs: &WindowAttributes, mtm: MainThreadMarker) -> Option Option child -> parent cycles since the only place in `winit` // where we allow making a window a child window is right here, just after it's been created. - unsafe { parent.addChildWindow_ordered(&window, NSWindowAbove) }; + unsafe { + parent.addChildWindow_ordered(&window, NSWindowOrderingMode::NSWindowAbove) + }; } Some(raw) => panic!("invalid raw window handle {raw:?} on macOS"), None => (), @@ -975,13 +974,13 @@ impl WindowDelegate { self.ivars().resizable.set(resizable); let fullscreen = self.ivars().fullscreen.borrow().is_some(); if !fullscreen { - let mut mask = self.window().styleMask(); + let mut mask = self.window().styleMask().0; if resizable { - mask |= NSWindowStyleMaskResizable; + mask |= NSWindowStyleMask::Resizable.0; } else { - mask &= !NSWindowStyleMaskResizable; + mask &= !NSWindowStyleMask::Resizable.0; } - self.set_style_mask(mask); + self.set_style_mask(NSWindowStyleMask(mask)); } // Otherwise, we don't change the mask until we exit fullscreen. } @@ -993,28 +992,31 @@ impl WindowDelegate { #[inline] pub fn set_enabled_buttons(&self, buttons: WindowButtons) { - let mut mask = self.window().styleMask(); + let mut mask = self.window().styleMask().0; if buttons.contains(WindowButtons::CLOSE) { - mask |= NSWindowStyleMaskClosable; + mask |= NSWindowStyleMask::Closable.0; } else { - mask &= !NSWindowStyleMaskClosable; + mask &= !NSWindowStyleMask::Closable.0; } if buttons.contains(WindowButtons::MINIMIZE) { - mask |= NSWindowStyleMaskMiniaturizable; + mask |= NSWindowStyleMask::Miniaturizable.0; } else { - mask &= !NSWindowStyleMaskMiniaturizable; + mask &= !NSWindowStyleMask::Miniaturizable.0; } // This must happen before the button's "enabled" status has been set, // hence we do it synchronously. - self.set_style_mask(mask); + self.set_style_mask(NSWindowStyleMask(mask)); // We edit the button directly instead of using `NSResizableWindowMask`, // since that mask also affect the resizability of the window (which is // controllable by other means in `winit`). - if let Some(button) = self.window().standardWindowButton(NSWindowZoomButton) { + if let Some(button) = self + .window() + .standardWindowButton(NSWindowButton::NSWindowZoomButton) + { button.setEnabled(buttons.contains(WindowButtons::MAXIMIZE)); } } @@ -1027,7 +1029,7 @@ impl WindowDelegate { } if self .window() - .standardWindowButton(NSWindowZoomButton) + .standardWindowButton(NSWindowButton::NSWindowZoomButton) .map(|b| b.isEnabled()) .unwrap_or(true) { @@ -1131,7 +1133,8 @@ impl WindowDelegate { // we make it resizable temporarily. let curr_mask = self.window().styleMask(); - let required = NSWindowStyleMaskTitled | NSWindowStyleMaskResizable; + let required = + NSWindowStyleMask(NSWindowStyleMask::Titled.0 | NSWindowStyleMask::Resizable.0); let needs_temp_mask = !mask_contains(curr_mask, required); if needs_temp_mask { self.set_style_mask(required); @@ -1152,12 +1155,13 @@ impl WindowDelegate { .ivars() .saved_style .take() - .unwrap_or_else(|| self.window().styleMask()); - if self.ivars().resizable.get() { - base_mask | NSWindowStyleMaskResizable + .unwrap_or_else(|| self.window().styleMask()) + .0; + NSWindowStyleMask(if self.ivars().resizable.get() { + base_mask | NSWindowStyleMask::Resizable.0 } else { - base_mask & !NSWindowStyleMaskResizable - } + base_mask & !NSWindowStyleMask::Resizable.0 + }) } /// This is called when the window is exiting fullscreen, whether by the @@ -1212,7 +1216,7 @@ impl WindowDelegate { return; } - if mask_contains(self.window().styleMask(), NSWindowStyleMaskResizable) { + if mask_contains(self.window().styleMask(), NSWindowStyleMask::Resizable) { // Just use the native zoom if resizable self.window().zoom(None); } else { @@ -1369,7 +1373,8 @@ impl WindowDelegate { // set a normal style temporarily. The previous state will be // restored in `WindowDelegate::window_did_exit_fullscreen`. let curr_mask = self.window().styleMask(); - let required = NSWindowStyleMaskTitled | NSWindowStyleMaskResizable; + let required = + NSWindowStyleMask(NSWindowStyleMask::Titled.0 | NSWindowStyleMask::Resizable.0); if !mask_contains(curr_mask, required) { self.set_style_mask(required); self.ivars().saved_style.set(Some(curr_mask)); @@ -1403,9 +1408,11 @@ impl WindowDelegate { .save_presentation_opts .set(Some(app.presentationOptions())); - let presentation_options = NSApplicationPresentationFullScreen - | NSApplicationPresentationHideDock - | NSApplicationPresentationHideMenuBar; + let presentation_options = NSApplicationPresentationOptions( + NSApplicationPresentationOptions::NSApplicationPresentationFullScreen.0 + | NSApplicationPresentationOptions::NSApplicationPresentationHideDock.0 + | NSApplicationPresentationOptions::NSApplicationPresentationHideMenuBar.0, + ); app.setPresentationOptions(presentation_options); let window_level = unsafe { ffi::CGShieldingWindowLevel() } as NSWindowLevel + 1; @@ -1413,9 +1420,9 @@ impl WindowDelegate { } (Some(Fullscreen::Exclusive(ref video_mode)), Some(Fullscreen::Borderless(_))) => { let presentation_options = self.ivars().save_presentation_opts.get().unwrap_or( - NSApplicationPresentationFullScreen - | NSApplicationPresentationAutoHideDock - | NSApplicationPresentationAutoHideMenuBar, + NSApplicationPresentationOptions(NSApplicationPresentationOptions::NSApplicationPresentationFullScreen.0 + | NSApplicationPresentationOptions::NSApplicationPresentationAutoHideDock.0 + | NSApplicationPresentationOptions::NSApplicationPresentationAutoHideMenuBar.0), ); app.setPresentationOptions(presentation_options); @@ -1455,19 +1462,19 @@ impl WindowDelegate { let new_mask = { let mut new_mask = if decorations { - NSWindowStyleMaskClosable - | NSWindowStyleMaskMiniaturizable - | NSWindowStyleMaskResizable - | NSWindowStyleMaskTitled + NSWindowStyleMask::Closable.0 + | NSWindowStyleMask::Miniaturizable.0 + | NSWindowStyleMask::Resizable.0 + | NSWindowStyleMask::Titled.0 } else { - NSWindowStyleMaskBorderless | NSWindowStyleMaskResizable + NSWindowStyleMask::Borderless.0 | NSWindowStyleMask::Resizable.0 }; if !resizable { - new_mask &= !NSWindowStyleMaskResizable; + new_mask &= !NSWindowStyleMask::Resizable.0; } new_mask }; - self.set_style_mask(new_mask); + self.set_style_mask(NSWindowStyleMask(new_mask)); } #[inline] @@ -1534,8 +1541,8 @@ impl WindowDelegate { pub fn request_user_attention(&self, request_type: Option) { let mtm = MainThreadMarker::from(self); let ns_request_type = request_type.map(|ty| match ty { - UserAttentionType::Critical => NSCriticalRequest, - UserAttentionType::Informational => NSInformationalRequest, + UserAttentionType::Critical => NSRequestUserAttentionType::NSCriticalRequest, + UserAttentionType::Informational => NSRequestUserAttentionType::NSInformationalRequest, }); if let Some(ty) = ns_request_type { NSApplication::sharedApplication(mtm).requestUserAttention(ty); @@ -1602,9 +1609,9 @@ impl WindowDelegate { fn toggle_style_mask(&self, mask: NSWindowStyleMask, on: bool) { let current_style_mask = self.window().styleMask(); if on { - self.set_style_mask(current_style_mask | mask); + self.set_style_mask(NSWindowStyleMask(current_style_mask.0 | mask.0)); } else { - self.set_style_mask(current_style_mask & (!mask)); + self.set_style_mask(NSWindowStyleMask(current_style_mask.0 & (!mask.0))); } } @@ -1629,9 +1636,9 @@ impl WindowDelegate { #[inline] pub fn set_content_protected(&self, protected: bool) { self.window().setSharingType(if protected { - NSWindowSharingNone + NSWindowSharingType::NSWindowSharingNone } else { - NSWindowSharingReadOnly + NSWindowSharingType::NSWindowSharingReadOnly }) } @@ -1683,12 +1690,14 @@ impl WindowExtMacOS for WindowDelegate { self.ivars().is_simple_fullscreen.set(true); // Simulate pre-Lion fullscreen by hiding the dock and menu bar - let presentation_options = - NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar; + let presentation_options = NSApplicationPresentationOptions( + NSApplicationPresentationOptions::NSApplicationPresentationAutoHideDock.0 + | NSApplicationPresentationOptions::NSApplicationPresentationAutoHideMenuBar.0, + ); app.setPresentationOptions(presentation_options); // Hide the titlebar - self.toggle_style_mask(NSWindowStyleMaskTitled, false); + self.toggle_style_mask(NSWindowStyleMask::Titled, false); // Set the window frame to the screen frame size let screen = self @@ -1698,8 +1707,8 @@ impl WindowExtMacOS for WindowDelegate { self.window().setFrame_display(screen.frame(), true); // Fullscreen windows can't be resized, minimized, or moved - self.toggle_style_mask(NSWindowStyleMaskMiniaturizable, false); - self.toggle_style_mask(NSWindowStyleMaskResizable, false); + self.toggle_style_mask(NSWindowStyleMask::Miniaturizable, false); + self.toggle_style_mask(NSWindowStyleMask::Resizable, false); self.window().setMovable(false); true @@ -1793,7 +1802,7 @@ impl WindowExtMacOS for WindowDelegate { } fn mask_contains(mask: NSWindowStyleMask, value: NSWindowStyleMask) -> bool { - mask & value == value + mask.0 & value.0 == value.0 } const DEFAULT_STANDARD_FRAME: NSRect =