From 86b3b9fcae881469caeefadd41f415af2a2f02ea Mon Sep 17 00:00:00 2001 From: Adrien Prokopowicz <6529475+prokopyl@users.noreply.github.com> Date: Sun, 3 May 2026 10:44:57 +0200 Subject: [PATCH 1/2] macOS: Set ns_window to the parent window when creating WindowHandles --- src/macos/window.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/macos/window.rs b/src/macos/window.rs index a457b893..1225c4f1 100644 --- a/src/macos/window.rs +++ b/src/macos/window.rs @@ -61,6 +61,10 @@ pub(super) struct WindowInner { /// Only set if we created the parent window, i.e. we are running in /// parentless mode ns_window: Cell>, + + /// Only set when running in parented mode. + parent_ns_window: Option, + /// Our subclassed NSView ns_view: id, @@ -109,7 +113,9 @@ impl WindowInner { fn raw_window_handle(&self) -> RawWindowHandle { if self.open.get() { - let ns_window = self.ns_window.get().unwrap_or(ptr::null_mut()) as *mut c_void; + let ns_window = self.ns_window.get() + .or(self.parent_ns_window) + .unwrap_or(ptr::null_mut()) as *mut c_void; let mut handle = AppKitWindowHandle::empty(); handle.ns_window = ns_window; @@ -155,6 +161,11 @@ impl<'a> Window<'a> { open: Cell::new(true), ns_app: Cell::new(None), ns_window: Cell::new(None), + parent_ns_window: if handle.ns_window.is_null() { + None + } else { + Some(handle.ns_window.cast()) + }, ns_view, #[cfg(feature = "opengl")] @@ -230,6 +241,7 @@ impl<'a> Window<'a> { open: Cell::new(true), ns_app: Cell::new(Some(app)), ns_window: Cell::new(Some(ns_window)), + parent_ns_window: None, ns_view, #[cfg(feature = "opengl")] From 0338230a7b1a271ee460efb8696a8df9683d0fc4 Mon Sep 17 00:00:00 2001 From: Adrien Prokopowicz <6529475+prokopyl@users.noreply.github.com> Date: Sun, 3 May 2026 10:51:40 +0200 Subject: [PATCH 2/2] rustfmt fix --- src/macos/window.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/macos/window.rs b/src/macos/window.rs index 1225c4f1..b94c8398 100644 --- a/src/macos/window.rs +++ b/src/macos/window.rs @@ -113,9 +113,9 @@ impl WindowInner { fn raw_window_handle(&self) -> RawWindowHandle { if self.open.get() { - let ns_window = self.ns_window.get() - .or(self.parent_ns_window) - .unwrap_or(ptr::null_mut()) as *mut c_void; + let ns_window = + self.ns_window.get().or(self.parent_ns_window).unwrap_or(ptr::null_mut()) + as *mut c_void; let mut handle = AppKitWindowHandle::empty(); handle.ns_window = ns_window;