From 0fb91f81770f38fedf4cca9c3c2326ce78a9cc61 Mon Sep 17 00:00:00 2001 From: Adrien Prokopowicz <6529475+prokopyl@users.noreply.github.com> Date: Tue, 21 Jul 2026 08:10:14 +0200 Subject: [PATCH 1/3] Make ParentWindowHandle public --- src/platform/macos/window.rs | 8 ++++++- src/platform/win/window.rs | 2 +- src/platform/x11/mod.rs | 2 +- src/platform/x11/window_shared.rs | 2 +- src/window_open_options.rs | 37 ++++++++++++++++++++++--------- 5 files changed, 37 insertions(+), 14 deletions(-) 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/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 } + } +} From 9f5a30affe94cdd37f6e627b0c177b4010e4bfbe Mon Sep 17 00:00:00 2001 From: Adrien Prokopowicz <6529475+prokopyl@users.noreply.github.com> Date: Tue, 21 Jul 2026 08:46:48 +0200 Subject: [PATCH 2/3] fix --- src/platform/macos/mod.rs | 2 +- src/platform/win/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/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, } From ffe4c76e311202803252f66efd2bc069179c5e55 Mon Sep 17 00:00:00 2001 From: Adrien Prokopowicz <6529475+prokopyl@users.noreply.github.com> Date: Tue, 21 Jul 2026 08:48:55 +0200 Subject: [PATCH 3/3] fix --- src/wrappers/win32/window/handle.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 {