Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/refactor-macos.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tao": patch
---

Replace NSString::from_str with ns_string macro in macOS. No user facing changes.
4 changes: 2 additions & 2 deletions src/platform_impl/macos/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<NSScreen> = msg_send![&screens, objectAtIndex: i as NSUInteger];
let device_description = NSScreen::deviceDescription(&screen);
Expand Down
14 changes: 7 additions & 7 deletions src/platform_impl/macos/util/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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<NSString> =
msg_send![&cursor_root, stringByAppendingPathComponent: &*cursor_name];
msg_send![cursor_root, stringByAppendingPathComponent: &*cursor_name];
let pdf_path: Retained<NSString> =
msg_send![&cursor_path, stringByAppendingPathComponent: &*cursor_pdf];
let info_path: Retained<NSString> =
Expand Down
6 changes: 3 additions & 3 deletions src/platform_impl/macos/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/platform_impl/macos/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -1437,7 +1437,7 @@ impl UnownedWindow {
unsafe {
let screen: Retained<NSScreen> = 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 {
Expand Down
4 changes: 2 additions & 2 deletions src/platform_impl/macos/window_delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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
Expand Down
Loading