Skip to content

Commit

Permalink
expose HWND directly
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir committed Jan 18, 2025
1 parent 1c30af1 commit 44f1288
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
10 changes: 5 additions & 5 deletions src/platform/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,18 +234,18 @@ impl EventLoopBuilderExtWindows for EventLoopBuilder {
}

pub trait ActiveEventLoopExtWindows {
/// Get the raw-window-handle HWND used by the event loop window target .
fn rwh_06_window_handle(&self) -> &dyn rwh_06::HasWindowHandle;
/// Get the HWND for the window target used by the event loop.
fn target_window_hwnd(&self) -> HWND;
}

impl ActiveEventLoopExtWindows for dyn ActiveEventLoop + '_ {
/// Get the raw-window-handle HWND used by the event loop window target .
fn rwh_06_window_handle(&self) -> &dyn rwh_06::HasWindowHandle {
/// Get the HWND for the window target used by the event loop.
fn target_window_hwnd(&self) -> HWND {
let event_loop = self
.as_any()
.downcast_ref::<crate::platform_impl::ActiveEventLoop>()
.expect("non Windows event loop on Windows");
event_loop
event_loop.thread_msg_target
}
}

Expand Down
11 changes: 1 addition & 10 deletions src/platform_impl/windows/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ impl std::hash::Hash for PlatformSpecificEventLoopAttributes {

pub struct ActiveEventLoop {
thread_id: u32,
thread_msg_target: HWND,
pub(crate) thread_msg_target: HWND,
pub(crate) runner_shared: Rc<EventLoopRunner>,
}

Expand Down Expand Up @@ -532,15 +532,6 @@ impl rwh_06::HasDisplayHandle for ActiveEventLoop {
}
}

impl rwh_06::HasWindowHandle for ActiveEventLoop {
fn window_handle(&self) -> Result<rwh_06::WindowHandle<'_>, rwh_06::HandleError> {
let hwnd = unsafe { std::num::NonZeroIsize::new_unchecked(self.thread_msg_target) };
let win32 = rwh_06::Win32WindowHandle::new(hwnd);
let raw = rwh_06::RawWindowHandle::Win32(win32);
unsafe { Ok(rwh_06::WindowHandle::borrow_raw(raw)) }
}
}

#[derive(Clone)]
pub(crate) struct OwnedDisplayHandle;

Expand Down

0 comments on commit 44f1288

Please sign in to comment.