diff --git a/src/platform/macos/mod.rs b/src/platform/macos/mod.rs index 67f2a2fd..156e7cfa 100644 --- a/src/platform/macos/mod.rs +++ b/src/platform/macos/mod.rs @@ -69,7 +69,7 @@ impl fmt::Debug for PlatformHandle { } } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct ParentWindowHandle { view: Retained, } diff --git a/src/platform/macos/window.rs b/src/platform/macos/window.rs index d6f31033..3996cf91 100644 --- a/src/platform/macos/window.rs +++ b/src/platform/macos/window.rs @@ -42,7 +42,13 @@ impl WindowHandle { let _ = NSApplication::sharedApplication(mtm); if let Some(parent) = options.parent.take() { - return Self::create_window_parented(options, handler, host, parent.view, mtm); + return Self::create_window_parented( + options, + handler, + host, + parent.inner.view, + mtm, + ); } Self::create_window_standalone(options, handler, host, mtm) diff --git a/src/platform/win/mod.rs b/src/platform/win/mod.rs index 0580927c..a295679e 100644 --- a/src/platform/win/mod.rs +++ b/src/platform/win/mod.rs @@ -49,7 +49,7 @@ impl Debug for PlatformHandle { } } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct ParentWindowHandle { handle: HWnd, } diff --git a/src/platform/win/window.rs b/src/platform/win/window.rs index f3644bdb..4743cebf 100644 --- a/src/platform/win/window.rs +++ b/src/platform/win/window.rs @@ -571,7 +571,7 @@ impl WindowHandle { } }; - let parent = options.parent.map(|p| p.handle); + let parent = options.parent.map(|p| p.inner.handle); let rect = dpi_ctx.client_area_to_nc_area(window_size.into(), style, None)?; let window = create_window(&title, style, rect.size(), parent, &dpi_ctx, initializer)?; diff --git a/src/platform/x11/mod.rs b/src/platform/x11/mod.rs index 009970c4..b45c1990 100644 --- a/src/platform/x11/mod.rs +++ b/src/platform/x11/mod.rs @@ -65,7 +65,7 @@ impl std::fmt::Debug for PlatformHandle { } } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct ParentWindowHandle { window_id: NonZeroU32, } diff --git a/src/platform/x11/window_shared.rs b/src/platform/x11/window_shared.rs index 990af08b..44cb0fb8 100644 --- a/src/platform/x11/window_shared.rs +++ b/src/platform/x11/window_shared.rs @@ -92,7 +92,7 @@ impl WindowInner { Rc::clone(&connection), physical_size, &visual_info, - options.parent.map(|p| p.window_id), + options.parent.map(|p| p.inner.window_id), )?; let cookies = [ diff --git a/src/window_open_options.rs b/src/window_open_options.rs index 64c9d17d..80b87542 100644 --- a/src/window_open_options.rs +++ b/src/window_open_options.rs @@ -1,6 +1,6 @@ #[cfg(feature = "opengl")] use crate::gl::GlConfig; -use crate::platform::ParentWindowHandle; +use crate::platform; use dpi::{LogicalSize, Size}; use raw_window_handle::HasWindowHandle; @@ -12,7 +12,7 @@ pub struct WindowOpenOptions { /// The size of the window, either in physical or logical coordinates pub size: Size, - pub(crate) parent: Option, + pub parent: Option, /// If provided, then an OpenGL context will be created for this window. You'll be able to /// access this context through [crate::WindowContext::gl_context]. @@ -46,14 +46,7 @@ impl WindowOpenOptions { ) -> Self { let Some(parent) = parent.into() else { return self }; - let parent = match ParentWindowHandle::extract(parent) { - Ok(parent) => parent, - Err(e) => { - panic!("Invalid parent window handle: {e}") - } - }; - - self.parent = Some(parent); + self.parent = Some(ParentWindowHandle::from_window(parent)); self } @@ -76,3 +69,27 @@ impl Default for WindowOpenOptions { } } } + +/// An owned handle to a parent window. +/// +/// This type holds just what's needed for baseview to create a child window into this window. +/// +/// This can safely be constructed from only a temporary reference to any [`HasWindowHandle`]. +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct ParentWindowHandle { + pub(crate) inner: platform::ParentWindowHandle, +} + +impl ParentWindowHandle { + /// Grabs a handle to the given `parent_window`, to later create a child window in it. + pub fn from_window(parent_window: &impl HasWindowHandle) -> Self { + let inner = match platform::ParentWindowHandle::extract(parent_window) { + Ok(parent) => parent, + Err(e) => { + panic!("Invalid parent window handle: {e}") + } + }; + + Self { inner } + } +} diff --git a/src/wrappers/win32/window/handle.rs b/src/wrappers/win32/window/handle.rs index 14475368..eed49cbc 100644 --- a/src/wrappers/win32/window/handle.rs +++ b/src/wrappers/win32/window/handle.rs @@ -25,7 +25,7 @@ use windows_sys::Win32::UI::WindowsAndMessaging::{ /// a handle from this type might still return an "invalid handle" error). /// /// The role of this type is to help safely encapsulating most of the unsafe Win32 HWND APIs. -#[derive(Copy, Clone, PartialEq, Debug)] +#[derive(Copy, Clone, PartialEq, Debug, Eq)] pub struct HWnd(NonNull); impl HWnd {