Skip to content
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 src/platform/macos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl fmt::Debug for PlatformHandle {
}
}

#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParentWindowHandle {
view: Retained<NSView>,
}
Expand Down
8 changes: 7 additions & 1 deletion src/platform/macos/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/platform/win/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Debug for PlatformHandle {
}
}

#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParentWindowHandle {
handle: HWnd,
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform/win/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
2 changes: 1 addition & 1 deletion src/platform/x11/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform/x11/window_shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
37 changes: 27 additions & 10 deletions src/window_open_options.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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<ParentWindowHandle>,
pub parent: Option<ParentWindowHandle>,

/// 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].
Expand Down Expand Up @@ -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
}

Expand All @@ -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 }
}
}
2 changes: 1 addition & 1 deletion src/wrappers/win32/window/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<c_void>);

impl HWnd {
Expand Down