From 5c23c62030ab7adfc2a17b88d876e74dd2d0127e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Frosteg=C3=A5rd?= Date: Wed, 23 Nov 2022 22:40:25 +0100 Subject: [PATCH] Add dummy HasRawDisplayHandle impls for Windows and X11 --- src/win/window.rs | 27 ++++++++++++++++++--------- src/x11/window.rs | 17 +++++++++++++---- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/win/window.rs b/src/win/window.rs index 2af1abe..f8c6156 100644 --- a/src/win/window.rs +++ b/src/win/window.rs @@ -24,7 +24,10 @@ use std::os::windows::ffi::OsStrExt; use std::ptr::null_mut; use std::rc::Rc; -use raw_window_handle::{HasRawWindowHandle, RawWindowHandle, Win32Handle}; +use raw_window_handle::{ + HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle, RawWindowHandle, Win32WindowHandle, + Win32WindowHandle, WindowsDisplayHandle, +}; const BV_WINDOW_MUST_CLOSE: UINT = WM_USER + 1; @@ -84,16 +87,22 @@ impl WindowHandle { unsafe impl HasRawWindowHandle for WindowHandle { fn raw_window_handle(&self) -> RawWindowHandle { if let Some(hwnd) = self.hwnd { - let mut handle = Win32Handle::empty(); + let mut handle = Win32WindowHandle::empty(); handle.hwnd = hwnd as *mut c_void; - RawWindowHandle::Win32(handle) + RawWindowHandle::Windows(handle) } else { - RawWindowHandle::Win32(Win32Handle::empty()) + RawWindowHandle::Windows(Win32WindowHandle::empty()) } } } +unsafe impl HasRawDisplayHandle for WindowHandle { + fn raw_display_handle(&self) -> RawDisplayHandle { + RawDisplayHandle::Windows(WindowsDisplayHandle::empty()) + } +} + struct ParentHandle { is_open: Rc>, } @@ -536,7 +545,7 @@ impl Window<'_> { B: Send + 'static, { let parent = match parent.raw_window_handle() { - RawWindowHandle::Win32(h) => h.hwnd as HWND, + RawWindowHandle::Windows(h) => h.hwnd as HWND, h => panic!("unsupported parent handle {:?}", h), }; @@ -644,9 +653,9 @@ impl Window<'_> { #[cfg(feature = "opengl")] let gl_context: Option = options.gl_config.map(|gl_config| { - let mut handle = Win32Handle::empty(); + let mut handle = Win32WindowHandle::empty(); handle.hwnd = hwnd as *mut c_void; - let handle = RawWindowHandleWrapper { handle: RawWindowHandle::Win32(handle) }; + let handle = RawWindowHandleWrapper { handle: RawWindowHandle::Windows(handle) }; GlContext::create(&handle, gl_config).expect("Could not create OpenGL context") }); @@ -757,10 +766,10 @@ impl Window<'_> { unsafe impl HasRawWindowHandle for Window<'_> { fn raw_window_handle(&self) -> RawWindowHandle { - let mut handle = Win32Handle::empty(); + let mut handle = Win32WindowHandle::empty(); handle.hwnd = self.state.hwnd as *mut c_void; - RawWindowHandle::Win32(handle) + RawWindowHandle::Windows(handle) } } diff --git a/src/x11/window.rs b/src/x11/window.rs index fcd9083..b6ba8b3 100644 --- a/src/x11/window.rs +++ b/src/x11/window.rs @@ -6,7 +6,10 @@ use std::sync::Arc; use std::thread; use std::time::*; -use raw_window_handle::{HasRawWindowHandle, RawWindowHandle, XlibHandle}; +use raw_window_handle::{ + HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle, RawWindowHandle, XlibDisplayHandle, + XlibWindowHandle, +}; use xcb::ffi::xcb_screen_t; use xcb::StructPtr; @@ -57,7 +60,13 @@ unsafe impl HasRawWindowHandle for WindowHandle { } } - RawWindowHandle::Xlib(XlibHandle::empty()) + RawWindowHandle::Xlib(XlibWindowHandle::empty()) + } +} + +unsafe impl HasRawDisplayHandle for WindowHandle { + fn raw_display_handle(&self) -> RawDisplayHandle { + RawDisplayHandle::Xlib(XlibDisplayHandle::empty()) } } @@ -323,7 +332,7 @@ impl Window { // compared to when raw-gl-context was a separate crate. #[cfg(feature = "opengl")] let gl_context = fb_config.map(|fb_config| { - let mut handle = XlibHandle::empty(); + let mut handle = XlibWindowHandle::empty(); handle.window = window_id as c_ulong; handle.display = xcb_connection.conn.get_raw_dpy() as *mut c_void; let handle = RawWindowHandleWrapper { handle: RawWindowHandle::Xlib(handle) }; @@ -686,7 +695,7 @@ impl Window { unsafe impl HasRawWindowHandle for Window { fn raw_window_handle(&self) -> RawWindowHandle { - let mut handle = XlibHandle::empty(); + let mut handle = XlibWindowHandle::empty(); handle.window = self.window_id as c_ulong; handle.display = self.xcb_connection.conn.get_raw_dpy() as *mut c_void;