diff --git a/.changes/refactor-macos.md b/.changes/refactor-macos.md new file mode 100644 index 000000000..e1212b324 --- /dev/null +++ b/.changes/refactor-macos.md @@ -0,0 +1,5 @@ +--- +"tao": patch +--- + +Replace NSString::from_str with ns_string macro in macOS. No user facing changes. \ No newline at end of file diff --git a/src/platform_impl/macos/monitor.rs b/src/platform_impl/macos/monitor.rs index 6dd78109f..7cdbd3986 100644 --- a/src/platform_impl/macos/monitor.rs +++ b/src/platform_impl/macos/monitor.rs @@ -20,7 +20,7 @@ use core_graphics::{ }; use objc2::{msg_send, rc::Retained}; use objc2_app_kit::NSScreen; -use objc2_foundation::{MainThreadMarker, NSString, NSUInteger}; +use objc2_foundation::{ns_string, MainThreadMarker, NSString, NSUInteger}; #[derive(Clone)] pub struct VideoMode { @@ -318,7 +318,7 @@ impl MonitorHandle { let uuid = ffi::CGDisplayCreateUUIDFromDisplayID(self.0); let screens = NSScreen::screens(mtm); let count: NSUInteger = msg_send![&screens, count]; - let key = NSString::from_str("NSScreenNumber"); + let key = ns_string!("NSScreenNumber"); for i in 0..count { let screen: Retained = msg_send![&screens, objectAtIndex: i as NSUInteger]; let device_description = NSScreen::deviceDescription(&screen); diff --git a/src/platform_impl/macos/util/cursor.rs b/src/platform_impl/macos/util/cursor.rs index fcc38becc..4ecdce5ae 100644 --- a/src/platform_impl/macos/util/cursor.rs +++ b/src/platform_impl/macos/util/cursor.rs @@ -10,7 +10,7 @@ use objc2::{ AllocAnyThread, }; use objc2_app_kit::NSImage; -use objc2_foundation::{NSDictionary, NSPoint, NSString}; +use objc2_foundation::{ns_string, NSDictionary, NSPoint, NSString}; use std::{ cell::RefCell, ffi::{c_void, CString}, @@ -111,15 +111,15 @@ impl Cursor { // instead you'll just get them all in a column. pub unsafe fn load_webkit_cursor(cursor_name: &str) -> id { const CURSOR_ROOT: &str = "/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/HIServices.framework/Versions/A/Resources/cursors"; - let cursor_root = NSString::from_str(CURSOR_ROOT); + let cursor_root = ns_string!(CURSOR_ROOT); let cursor_name = NSString::from_str(cursor_name); - let cursor_pdf = NSString::from_str("cursor.pdf"); - let cursor_plist = NSString::from_str("info.plist"); - let key_x = NSString::from_str("hotx"); - let key_y = NSString::from_str("hoty"); + let cursor_pdf = ns_string!("cursor.pdf"); + let cursor_plist = ns_string!("info.plist"); + let key_x = ns_string!("hotx"); + let key_y = ns_string!("hoty"); let cursor_path: Retained = - msg_send![&cursor_root, stringByAppendingPathComponent: &*cursor_name]; + msg_send![cursor_root, stringByAppendingPathComponent: &*cursor_name]; let pdf_path: Retained = msg_send![&cursor_path, stringByAppendingPathComponent: &*cursor_pdf]; let info_path: Retained = diff --git a/src/platform_impl/macos/view.rs b/src/platform_impl/macos/view.rs index f381ab994..dfeba9414 100644 --- a/src/platform_impl/macos/view.rs +++ b/src/platform_impl/macos/view.rs @@ -25,8 +25,8 @@ use objc2_app_kit::{ NSApp, NSEvent, NSEventModifierFlags, NSEventPhase, NSView, NSWindow, NSWindowButton, }; use objc2_foundation::{ - MainThreadMarker, NSAttributedString, NSInteger, NSMutableAttributedString, NSPoint, NSRange, - NSRect, NSSize, NSString, NSUInteger, + ns_string, MainThreadMarker, NSAttributedString, NSInteger, NSMutableAttributedString, NSPoint, + NSRange, NSRect, NSSize, NSString, NSUInteger, }; use once_cell::sync::Lazy; @@ -282,7 +282,7 @@ extern "C" fn init_with_tao(this: &Object, _sel: Sel, state: *mut c_void) -> id let _: () = msg_send![this, setPostsFrameChangedNotifications: YES]; let notification_center: &Object = msg_send![class!(NSNotificationCenter), defaultCenter]; - let notification_name = NSString::from_str("NSViewFrameDidChangeNotification"); + let notification_name = ns_string!("NSViewFrameDidChangeNotification"); let _: () = msg_send![ notification_center, addObserver: this diff --git a/src/platform_impl/macos/window.rs b/src/platform_impl/macos/window.rs index e54b49a8e..54268dcf4 100644 --- a/src/platform_impl/macos/window.rs +++ b/src/platform_impl/macos/window.rs @@ -57,8 +57,8 @@ use objc2_app_kit::{ NSWindowOrderingMode, NSWindowSharingType, NSWindowStyleMask, }; use objc2_foundation::{ - MainThreadMarker, NSArray, NSAutoreleasePool, NSDictionary, NSInteger, NSPoint, NSRect, NSSize, - NSString, NSTimeInterval, NSUInteger, + ns_string, MainThreadMarker, NSArray, NSAutoreleasePool, NSDictionary, NSInteger, NSPoint, + NSRect, NSSize, NSString, NSTimeInterval, NSUInteger, }; use once_cell::sync::Lazy; @@ -1437,7 +1437,7 @@ impl UnownedWindow { unsafe { let screen: Retained = self.ns_window.screen()?; let desc = NSScreen::deviceDescription(&screen); - let key = NSString::from_str("NSScreenNumber"); + let key = ns_string!("NSScreenNumber"); let value = NSDictionary::objectForKey(&desc, &key).unwrap(); let display_id: NSUInteger = msg_send![&value, unsignedIntegerValue]; Some(RootMonitorHandle { diff --git a/src/platform_impl/macos/window_delegate.rs b/src/platform_impl/macos/window_delegate.rs index 3e9ee0594..fa6e63085 100644 --- a/src/platform_impl/macos/window_delegate.rs +++ b/src/platform_impl/macos/window_delegate.rs @@ -17,7 +17,7 @@ use objc2::{ use objc2_app_kit::{ self as appkit, NSApplicationPresentationOptions, NSPasteboard, NSView, NSWindow, }; -use objc2_foundation::{NSArray, NSAutoreleasePool, NSString, NSUInteger}; +use objc2_foundation::{ns_string, NSArray, NSAutoreleasePool, NSString, NSUInteger}; use once_cell::sync::Lazy; use crate::{ @@ -298,7 +298,7 @@ extern "C" fn init_with_tao(this: &Object, _sel: Sel, state: *mut c_void) -> id let notification_center: &Object = msg_send![class!(NSDistributedNotificationCenter), defaultCenter]; - let notification_name = NSString::from_str("AppleInterfaceThemeChangedNotification"); + let notification_name = ns_string!("AppleInterfaceThemeChangedNotification"); let _: () = msg_send![ notification_center, addObserver: this