From 0cc2b848fee44f2cfdd53d975eb41ec152f1b47f Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Wed, 10 Aug 2022 19:31:43 +0200 Subject: [PATCH] Make implementors of HasRawWindowHandle v0.5 also implement v0.4's Similar approach as in https://github.com/rust-windowing/raw-window-handle/pull/74 --- CHANGELOG.md | 11 +++++++++++ Cargo.toml | 5 +++-- src/android.rs | 9 +++++++++ src/appkit.rs | 10 ++++++++++ src/haiku.rs | 10 ++++++++++ src/lib.rs | 45 +++++++++++++++++++++++++++++---------------- src/redox.rs | 9 +++++++++ src/uikit.rs | 11 +++++++++++ src/unix.rs | 32 ++++++++++++++++++++++++++++++++ src/web.rs | 9 +++++++++ src/windows.rs | 19 +++++++++++++++++++ 11 files changed, 152 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e426ae0..c94819e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # Changelog +## 0.4.4 (2022-08-10) + +* Add `HasRawWindowHandle` implementation for `HasRawWindowHandle` + + `HasRawDisplayHandle` in the newer version `0.5.0`. + + This allows "provider" crates that implement `HasRawWindowHandle` (like + `winit`, `sdl2`, `glfw`, `fltk`, ...) to upgrade to `v0.5.0` immediately. + + Afterwards "consumer" crates (like `gfx`, `wgpu`, `rfd`, ...) can start + upgrading with minimal breakage for their users. + ## 0.4.3 (2022-03-29) * [Add visual IDs to X11 handles](https://github.com/rust-windowing/raw-window-handle/pull/83) diff --git a/Cargo.toml b/Cargo.toml index 84fc9fc..78ff73b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "raw-window-handle" -version = "0.4.3" +version = "0.4.4" authors = ["Osspial "] edition = "2018" description = "Interoperability library for Rust Windowing applications." @@ -11,10 +11,11 @@ readme = "README.md" documentation = "https://docs.rs/raw-window-handle" [features] -alloc = [] +alloc = ["new/alloc"] [dependencies] cty = "0.2" +new = { version = "0.5.0", package = "raw-window-handle" } [badges] travis-ci = { repository = "rust-windowing/raw-window-handle" } diff --git a/src/android.rs b/src/android.rs index 48f69e9..14757bd 100644 --- a/src/android.rs +++ b/src/android.rs @@ -23,3 +23,12 @@ impl AndroidNdkHandle { } } } + +impl From for AndroidNdkHandle { + fn from(handle: new::AndroidNdkWindowHandle) -> Self { + Self { + a_native_window: handle.a_native_window, + ..Self::empty() + } + } +} diff --git a/src/appkit.rs b/src/appkit.rs index 27793be..7c8194b 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -27,3 +27,13 @@ impl AppKitHandle { } } } + +impl From for AppKitHandle { + fn from(handle: new::AppKitWindowHandle) -> Self { + Self { + ns_window: handle.ns_window, + ns_view: handle.ns_view, + ..Self::empty() + } + } +} diff --git a/src/haiku.rs b/src/haiku.rs index 38432fd..a0c7643 100644 --- a/src/haiku.rs +++ b/src/haiku.rs @@ -26,3 +26,13 @@ impl HaikuHandle { } } } + +impl From for HaikuHandle { + fn from(handle: new::HaikuWindowHandle) -> Self { + Self { + b_window: handle.b_window, + b_direct_window: handle.b_direct_window, + ..Self::empty() + } + } +} diff --git a/src/lib.rs b/src/lib.rs index 2235a2f..1b63da7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -58,23 +58,36 @@ pub unsafe trait HasRawWindowHandle { fn raw_window_handle(&self) -> RawWindowHandle; } -unsafe impl<'a, T: HasRawWindowHandle + ?Sized> HasRawWindowHandle for &'a T { +unsafe impl HasRawWindowHandle for T { fn raw_window_handle(&self) -> RawWindowHandle { - (*self).raw_window_handle() - } -} -#[cfg(feature = "alloc")] -#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] -unsafe impl HasRawWindowHandle for alloc::rc::Rc { - fn raw_window_handle(&self) -> RawWindowHandle { - (**self).raw_window_handle() - } -} -#[cfg(feature = "alloc")] -#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] -unsafe impl HasRawWindowHandle for alloc::sync::Arc { - fn raw_window_handle(&self) -> RawWindowHandle { - (**self).raw_window_handle() + match ( + new::HasRawWindowHandle::raw_window_handle(self), + new::HasRawDisplayHandle::raw_display_handle(self), + ) { + (new::RawWindowHandle::UiKit(handle), _) => RawWindowHandle::UiKit(handle.into()), + (new::RawWindowHandle::AppKit(handle), _) => RawWindowHandle::AppKit(handle.into()), + (new::RawWindowHandle::Orbital(handle), _) => RawWindowHandle::Orbital(handle.into()), + (new::RawWindowHandle::Xlib(handle), new::RawDisplayHandle::Xlib(display_handle)) => { + RawWindowHandle::Xlib((handle, display_handle).into()) + } + (new::RawWindowHandle::Xcb(handle), new::RawDisplayHandle::Xcb(display_handle)) => { + RawWindowHandle::Xcb((handle, display_handle).into()) + } + ( + new::RawWindowHandle::Wayland(handle), + new::RawDisplayHandle::Wayland(display_handle), + ) => RawWindowHandle::Wayland((handle, display_handle).into()), + (new::RawWindowHandle::Win32(handle), _) => RawWindowHandle::Win32(handle.into()), + (new::RawWindowHandle::WinRt(handle), _) => RawWindowHandle::WinRt(handle.into()), + (new::RawWindowHandle::Web(handle), _) => RawWindowHandle::Web(handle.into()), + (new::RawWindowHandle::AndroidNdk(handle), _) => { + RawWindowHandle::AndroidNdk(handle.into()) + } + (new::RawWindowHandle::Haiku(handle), _) => RawWindowHandle::Haiku(handle.into()), + _ => panic!( + "Invalid handle for this platform. Please update raw-window-handle to > 0.5.0!" + ), + } } } diff --git a/src/redox.rs b/src/redox.rs index da7880c..93d3eab 100644 --- a/src/redox.rs +++ b/src/redox.rs @@ -23,3 +23,12 @@ impl OrbitalHandle { } } } + +impl From for OrbitalHandle { + fn from(handle: new::OrbitalWindowHandle) -> Self { + Self { + window: handle.window, + ..Self::empty() + } + } +} diff --git a/src/uikit.rs b/src/uikit.rs index 412d107..02f6b76 100644 --- a/src/uikit.rs +++ b/src/uikit.rs @@ -29,3 +29,14 @@ impl UiKitHandle { } } } + +impl From for UiKitHandle { + fn from(handle: new::UiKitWindowHandle) -> Self { + Self { + ui_window: handle.ui_window, + ui_view: handle.ui_view, + ui_view_controller: handle.ui_view_controller, + ..Self::empty() + } + } +} diff --git a/src/unix.rs b/src/unix.rs index 1e7575b..5c7130c 100644 --- a/src/unix.rs +++ b/src/unix.rs @@ -86,3 +86,35 @@ impl WaylandHandle { } } } + +impl From<(new::XlibWindowHandle, new::XlibDisplayHandle)> for XlibHandle { + fn from(handle: (new::XlibWindowHandle, new::XlibDisplayHandle)) -> Self { + Self { + window: handle.0.window, + display: handle.1.display, + visual_id: handle.0.visual_id, + ..Self::empty() + } + } +} + +impl From<(new::XcbWindowHandle, new::XcbDisplayHandle)> for XcbHandle { + fn from(handle: (new::XcbWindowHandle, new::XcbDisplayHandle)) -> Self { + Self { + window: handle.0.window, + connection: handle.1.connection, + visual_id: handle.0.visual_id, + ..Self::empty() + } + } +} + +impl From<(new::WaylandWindowHandle, new::WaylandDisplayHandle)> for WaylandHandle { + fn from(handle: (new::WaylandWindowHandle, new::WaylandDisplayHandle)) -> Self { + Self { + surface: handle.0.surface, + display: handle.1.display, + ..Self::empty() + } + } +} diff --git a/src/web.rs b/src/web.rs index 632be63..6d2df39 100644 --- a/src/web.rs +++ b/src/web.rs @@ -25,3 +25,12 @@ impl WebHandle { Self { id: 0 } } } + +impl From for WebHandle { + fn from(handle: new::WebWindowHandle) -> Self { + Self { + id: handle.id, + ..Self::empty() + } + } +} diff --git a/src/windows.rs b/src/windows.rs index ab75635..00ef079 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -27,6 +27,16 @@ impl Win32Handle { } } +impl From for Win32Handle { + fn from(handle: new::Win32WindowHandle) -> Self { + Self { + hwnd: handle.hwnd, + hinstance: handle.hinstance, + ..Self::empty() + } + } +} + /// Raw window handle for WinRT. /// /// ## Construction @@ -49,3 +59,12 @@ impl WinRtHandle { } } } + +impl From for WinRtHandle { + fn from(handle: new::WinRtWindowHandle) -> Self { + Self { + core_window: handle.core_window, + ..Self::empty() + } + } +}