Skip to content

Commit a133504

Browse files
authored
refactor: replace NSString::from_str with ns_string macro in macOS (#1184)
* refactor: replace NSString::from_str with ns_string macro in macOS * fix: fmt
1 parent e1c9cb6 commit a133504

File tree

6 files changed

+22
-17
lines changed

6 files changed

+22
-17
lines changed

.changes/refactor-macos.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tao": patch
3+
---
4+
5+
Replace NSString::from_str with ns_string macro in macOS. No user facing changes.

src/platform_impl/macos/monitor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use core_graphics::{
2020
};
2121
use objc2::{msg_send, rc::Retained};
2222
use objc2_app_kit::NSScreen;
23-
use objc2_foundation::{MainThreadMarker, NSString, NSUInteger};
23+
use objc2_foundation::{ns_string, MainThreadMarker, NSString, NSUInteger};
2424

2525
#[derive(Clone)]
2626
pub struct VideoMode {
@@ -318,7 +318,7 @@ impl MonitorHandle {
318318
let uuid = ffi::CGDisplayCreateUUIDFromDisplayID(self.0);
319319
let screens = NSScreen::screens(mtm);
320320
let count: NSUInteger = msg_send![&screens, count];
321-
let key = NSString::from_str("NSScreenNumber");
321+
let key = ns_string!("NSScreenNumber");
322322
for i in 0..count {
323323
let screen: Retained<NSScreen> = msg_send![&screens, objectAtIndex: i as NSUInteger];
324324
let device_description = NSScreen::deviceDescription(&screen);

src/platform_impl/macos/util/cursor.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use objc2::{
1010
AllocAnyThread,
1111
};
1212
use objc2_app_kit::NSImage;
13-
use objc2_foundation::{NSDictionary, NSPoint, NSString};
13+
use objc2_foundation::{ns_string, NSDictionary, NSPoint, NSString};
1414
use std::{
1515
cell::RefCell,
1616
ffi::{c_void, CString},
@@ -111,15 +111,15 @@ impl Cursor {
111111
// instead you'll just get them all in a column.
112112
pub unsafe fn load_webkit_cursor(cursor_name: &str) -> id {
113113
const CURSOR_ROOT: &str = "/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/HIServices.framework/Versions/A/Resources/cursors";
114-
let cursor_root = NSString::from_str(CURSOR_ROOT);
114+
let cursor_root = ns_string!(CURSOR_ROOT);
115115
let cursor_name = NSString::from_str(cursor_name);
116-
let cursor_pdf = NSString::from_str("cursor.pdf");
117-
let cursor_plist = NSString::from_str("info.plist");
118-
let key_x = NSString::from_str("hotx");
119-
let key_y = NSString::from_str("hoty");
116+
let cursor_pdf = ns_string!("cursor.pdf");
117+
let cursor_plist = ns_string!("info.plist");
118+
let key_x = ns_string!("hotx");
119+
let key_y = ns_string!("hoty");
120120

121121
let cursor_path: Retained<NSString> =
122-
msg_send![&cursor_root, stringByAppendingPathComponent: &*cursor_name];
122+
msg_send![cursor_root, stringByAppendingPathComponent: &*cursor_name];
123123
let pdf_path: Retained<NSString> =
124124
msg_send![&cursor_path, stringByAppendingPathComponent: &*cursor_pdf];
125125
let info_path: Retained<NSString> =

src/platform_impl/macos/view.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ use objc2_app_kit::{
2525
NSApp, NSEvent, NSEventModifierFlags, NSEventPhase, NSView, NSWindow, NSWindowButton,
2626
};
2727
use objc2_foundation::{
28-
MainThreadMarker, NSAttributedString, NSInteger, NSMutableAttributedString, NSPoint, NSRange,
29-
NSRect, NSSize, NSString, NSUInteger,
28+
ns_string, MainThreadMarker, NSAttributedString, NSInteger, NSMutableAttributedString, NSPoint,
29+
NSRange, NSRect, NSSize, NSString, NSUInteger,
3030
};
3131
use once_cell::sync::Lazy;
3232

@@ -282,7 +282,7 @@ extern "C" fn init_with_tao(this: &Object, _sel: Sel, state: *mut c_void) -> id
282282
let _: () = msg_send![this, setPostsFrameChangedNotifications: YES];
283283

284284
let notification_center: &Object = msg_send![class!(NSNotificationCenter), defaultCenter];
285-
let notification_name = NSString::from_str("NSViewFrameDidChangeNotification");
285+
let notification_name = ns_string!("NSViewFrameDidChangeNotification");
286286
let _: () = msg_send![
287287
notification_center,
288288
addObserver: this

src/platform_impl/macos/window.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ use objc2_app_kit::{
5757
NSWindowOrderingMode, NSWindowSharingType, NSWindowStyleMask,
5858
};
5959
use objc2_foundation::{
60-
MainThreadMarker, NSArray, NSAutoreleasePool, NSDictionary, NSInteger, NSPoint, NSRect, NSSize,
61-
NSString, NSTimeInterval, NSUInteger,
60+
ns_string, MainThreadMarker, NSArray, NSAutoreleasePool, NSDictionary, NSInteger, NSPoint,
61+
NSRect, NSSize, NSString, NSTimeInterval, NSUInteger,
6262
};
6363
use once_cell::sync::Lazy;
6464

@@ -1437,7 +1437,7 @@ impl UnownedWindow {
14371437
unsafe {
14381438
let screen: Retained<NSScreen> = self.ns_window.screen()?;
14391439
let desc = NSScreen::deviceDescription(&screen);
1440-
let key = NSString::from_str("NSScreenNumber");
1440+
let key = ns_string!("NSScreenNumber");
14411441
let value = NSDictionary::objectForKey(&desc, &key).unwrap();
14421442
let display_id: NSUInteger = msg_send![&value, unsignedIntegerValue];
14431443
Some(RootMonitorHandle {

src/platform_impl/macos/window_delegate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use objc2::{
1717
use objc2_app_kit::{
1818
self as appkit, NSApplicationPresentationOptions, NSPasteboard, NSView, NSWindow,
1919
};
20-
use objc2_foundation::{NSArray, NSAutoreleasePool, NSString, NSUInteger};
20+
use objc2_foundation::{ns_string, NSArray, NSAutoreleasePool, NSString, NSUInteger};
2121
use once_cell::sync::Lazy;
2222

2323
use crate::{
@@ -298,7 +298,7 @@ extern "C" fn init_with_tao(this: &Object, _sel: Sel, state: *mut c_void) -> id
298298

299299
let notification_center: &Object =
300300
msg_send![class!(NSDistributedNotificationCenter), defaultCenter];
301-
let notification_name = NSString::from_str("AppleInterfaceThemeChangedNotification");
301+
let notification_name = ns_string!("AppleInterfaceThemeChangedNotification");
302302
let _: () = msg_send![
303303
notification_center,
304304
addObserver: this

0 commit comments

Comments
 (0)