Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use objc2 #566

Merged
merged 1 commit into from
Apr 30, 2024
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ raw-window-handle-0-5 = { package = "raw-window-handle", version = "0.5.0"}
raw-window-handle-0-6 = { package = "raw-window-handle", version = "0.6.0", optional = true }

[target.'cfg(target_os = "macos")'.dependencies]
objc = "0.2"
objc2 = "0.5.1"

[target.'cfg(target_os = "windows")'.dependencies]
winapi = { version = "0.3", features = ["libloaderapi"] }
Expand Down
21 changes: 10 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,6 @@ extern crate log;
extern crate bitflags;
#[cfg(feature = "image")]
extern crate image;
#[cfg(target_os = "macos")]
#[macro_use]
extern crate objc;

#[cfg(feature = "raw-window-handle-v0-6")]
extern crate raw_window_handle_0_6 as raw_window_handle;
Expand Down Expand Up @@ -3646,15 +3643,17 @@ fn raw_window_handle<C: Context>(context: &C) -> RawWindowHandle {
}
#[cfg(target_os = "macos")]
{
use std::ptr::NonNull;
use objc2::msg_send_id;
use objc2::rc::Id;
use objc2::runtime::NSObject;
use raw_window_handle::AppKitWindowHandle;
let ns_view = unsafe {
let ns_window: *mut objc::runtime::Object = ffi::glfwGetCocoaWindow(context.window_ptr()) as *mut _;
let ns_view: *mut objc::runtime::Object = objc::msg_send![ns_window, contentView];
assert_ne!(ns_view, std::ptr::null_mut());
ns_view as *mut std::ffi::c_void
};
let handle = AppKitWindowHandle::new(NonNull::new(ns_view).unwrap());
use std::ptr::NonNull;
let ns_window: *mut NSObject =
unsafe { ffi::glfwGetCocoaWindow(context.window_ptr()) as *mut _ };
let ns_view: Option<Id<NSObject>> = unsafe { msg_send_id![ns_window, contentView] };
let ns_view = ns_view.expect("failed to access contentView on GLFW NSWindow");
let ns_view: NonNull<NSObject> = NonNull::from(&*ns_view);
let handle = AppKitWindowHandle::new(ns_view.cast());
RawWindowHandle::AppKit(handle)
}
#[cfg(target_os = "emscripten")]
Expand Down