Skip to content
Closed
Changes from 1 commit
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
Next Next commit
fixed the raw-win-handle feature for windows
  • Loading branch information
sidit77 committed Jul 25, 2022
commit 264b2d37473610f0c3fe377832b104ca20dc4665
20 changes: 10 additions & 10 deletions druid-shell/src/backend/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ use winapi::Interface;
use wio::com::ComPtr;

#[cfg(feature = "raw-win-handle")]
use raw_window_handle::{windows::WindowsHandle, HasRawWindowHandle, RawWindowHandle};
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle, Win32Handle};

use piet_common::d2d::{D2DFactory, DeviceContext};
use piet_common::dwrite::DwriteFactory;
Expand Down Expand Up @@ -185,18 +185,18 @@ impl Eq for WindowHandle {}
unsafe impl HasRawWindowHandle for WindowHandle {
fn raw_window_handle(&self) -> RawWindowHandle {
if let Some(hwnd) = self.get_hwnd() {
let handle = WindowsHandle {
hwnd: hwnd as *mut core::ffi::c_void,
hinstance: unsafe {
winapi::um::libloaderapi::GetModuleHandleW(0 as winapi::um::winnt::LPCWSTR)
as *mut core::ffi::c_void
},
..WindowsHandle::empty()
// Using empty + set fields instead Win32Handle{...} to shut up a unexplainable compiler error
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't say it's "unexplainable." Win32Handle is marked as #[non_exhaustive], which is explained here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that explains it. Thanks.

// "cannot create non-exhaustive struct using struct expression"
let mut handle = Win32Handle::empty();
handle.hwnd = hwnd as *mut core::ffi::c_void;
handle.hinstance = unsafe {
winapi::um::libloaderapi::GetModuleHandleW(0 as winapi::um::winnt::LPCWSTR)
as *mut core::ffi::c_void
};
RawWindowHandle::Windows(handle)
RawWindowHandle::Win32(handle)
} else {
error!("Cannot retrieved HWND for window.");
RawWindowHandle::Windows(WindowsHandle::empty())
RawWindowHandle::Win32(Win32Handle::empty())
}
}
}
Expand Down