diff --git a/src/macos/window.rs b/src/macos/window.rs index a457b89..b94c839 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")]