mirror of
https://github.com/rust-windowing/winit.git
synced 2026-06-28 07:33:14 -04:00
Initial transition to objc2 (#2452)
* Use objc2 * Use objc2's NSInteger/NSUInteger/NSRange
This commit is contained in:
@@ -9,8 +9,9 @@ use cocoa::{
|
||||
foundation::{NSPoint, NSSize, NSString},
|
||||
};
|
||||
use dispatch::Queue;
|
||||
use objc::foundation::is_main_thread;
|
||||
use objc::rc::autoreleasepool;
|
||||
use objc::runtime::{BOOL, NO, YES};
|
||||
use objc::runtime::Bool;
|
||||
|
||||
use crate::{
|
||||
dpi::LogicalSize,
|
||||
@@ -55,8 +56,7 @@ pub unsafe fn set_style_mask_async(ns_window: id, ns_view: id, mask: NSWindowSty
|
||||
});
|
||||
}
|
||||
pub unsafe fn set_style_mask_sync(ns_window: id, ns_view: id, mask: NSWindowStyleMask) {
|
||||
let is_main_thread: BOOL = msg_send!(class!(NSThread), isMainThread);
|
||||
if is_main_thread != NO {
|
||||
if is_main_thread() {
|
||||
set_style_mask(ns_window, ns_view, mask);
|
||||
} else {
|
||||
let ns_window = MainThreadSafe(ns_window);
|
||||
@@ -97,7 +97,7 @@ pub unsafe fn set_level_async(ns_window: id, level: ffi::NSWindowLevel) {
|
||||
pub unsafe fn set_ignore_mouse_events(ns_window: id, ignore: bool) {
|
||||
let ns_window = MainThreadSafe(ns_window);
|
||||
Queue::main().exec_async(move || {
|
||||
ns_window.setIgnoresMouseEvents_(if ignore { YES } else { NO });
|
||||
ns_window.setIgnoresMouseEvents_(Bool::from(ignore).as_raw());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ pub unsafe fn set_maximized_async(
|
||||
} else {
|
||||
shared_state_lock.saved_standard_frame()
|
||||
};
|
||||
ns_window.setFrame_display_(new_rect, NO);
|
||||
ns_window.setFrame_display_(new_rect, Bool::NO.as_raw());
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -229,7 +229,7 @@ pub unsafe fn set_title_async(ns_window: id, title: String) {
|
||||
pub unsafe fn close_async(ns_window: IdRef) {
|
||||
let ns_window = MainThreadSafe(ns_window);
|
||||
Queue::main().exec_async(move || {
|
||||
autoreleasepool(move || {
|
||||
autoreleasepool(move |_| {
|
||||
ns_window.close();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,7 +3,7 @@ use cocoa::{
|
||||
base::{id, nil},
|
||||
foundation::{NSDictionary, NSPoint, NSString},
|
||||
};
|
||||
use objc::{runtime::Sel, runtime::NO};
|
||||
use objc::runtime::Sel;
|
||||
use std::cell::RefCell;
|
||||
|
||||
use crate::window::CursorIcon;
|
||||
@@ -147,10 +147,11 @@ pub unsafe fn invisible_cursor() -> id {
|
||||
CURSOR_OBJECT.with(|cursor_obj| {
|
||||
if *cursor_obj.borrow() == nil {
|
||||
// Create a cursor from `CURSOR_BYTES`
|
||||
let cursor_data: id = msg_send![class!(NSData),
|
||||
dataWithBytesNoCopy:CURSOR_BYTES as *const [u8]
|
||||
length:CURSOR_BYTES.len()
|
||||
freeWhenDone:NO
|
||||
let cursor_data: id = msg_send![
|
||||
class!(NSData),
|
||||
dataWithBytesNoCopy: CURSOR_BYTES.as_ptr(),
|
||||
length: CURSOR_BYTES.len(),
|
||||
freeWhenDone: false,
|
||||
];
|
||||
|
||||
let ns_image: id = msg_send![class!(NSImage), alloc];
|
||||
|
||||
@@ -9,10 +9,11 @@ use std::os::raw::c_uchar;
|
||||
use cocoa::{
|
||||
appkit::{CGFloat, NSApp, NSWindowStyleMask},
|
||||
base::{id, nil},
|
||||
foundation::{NSPoint, NSRect, NSString, NSUInteger},
|
||||
foundation::{NSPoint, NSRect, NSString},
|
||||
};
|
||||
use core_graphics::display::CGDisplay;
|
||||
use objc::runtime::{Class, Object, BOOL, NO};
|
||||
use objc::foundation::{NSRange, NSUInteger};
|
||||
use objc::runtime::{Class, Object};
|
||||
|
||||
use crate::dpi::LogicalPosition;
|
||||
use crate::platform_impl::platform::ffi;
|
||||
@@ -28,7 +29,7 @@ where
|
||||
bitset & flag == flag
|
||||
}
|
||||
|
||||
pub const EMPTY_RANGE: ffi::NSRange = ffi::NSRange {
|
||||
pub const EMPTY_RANGE: NSRange = NSRange {
|
||||
location: ffi::NSNotFound as NSUInteger,
|
||||
length: 0,
|
||||
};
|
||||
@@ -172,8 +173,8 @@ pub unsafe fn toggle_style_mask(window: id, view: id, mask: NSWindowStyleMask, o
|
||||
///
|
||||
/// Safety: Assumes that `string` is an instance of `NSAttributedString` or `NSString`
|
||||
pub unsafe fn id_to_string_lossy(string: id) -> String {
|
||||
let has_attr: BOOL = msg_send![string, isKindOfClass: class!(NSAttributedString)];
|
||||
let characters = if has_attr != NO {
|
||||
let has_attr = msg_send![string, isKindOfClass: class!(NSAttributedString)];
|
||||
let characters = if has_attr {
|
||||
// This is a *mut NSAttributedString
|
||||
msg_send![string, string]
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user