Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make implementors of HasRawWindowHandle v0.5 also implement v0.4's #97

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions 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)
Expand Down
5 changes: 3 additions & 2 deletions Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "raw-window-handle"
version = "0.4.3"
version = "0.4.4"
authors = ["Osspial <osspial@gmail.com>"]
edition = "2018"
description = "Interoperability library for Rust Windowing applications."
Expand All @@ -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" }
Expand Down
9 changes: 9 additions & 0 deletions src/android.rs
Expand Up @@ -23,3 +23,12 @@ impl AndroidNdkHandle {
}
}
}

impl From<new::AndroidNdkWindowHandle> for AndroidNdkHandle {
fn from(handle: new::AndroidNdkWindowHandle) -> Self {
Self {
a_native_window: handle.a_native_window,
..Self::empty()
}
}
}
10 changes: 10 additions & 0 deletions src/appkit.rs
Expand Up @@ -27,3 +27,13 @@ impl AppKitHandle {
}
}
}

impl From<new::AppKitWindowHandle> for AppKitHandle {
fn from(handle: new::AppKitWindowHandle) -> Self {
Self {
ns_window: handle.ns_window,
ns_view: handle.ns_view,
..Self::empty()
}
}
}
10 changes: 10 additions & 0 deletions src/haiku.rs
Expand Up @@ -26,3 +26,13 @@ impl HaikuHandle {
}
}
}

impl From<new::HaikuWindowHandle> for HaikuHandle {
fn from(handle: new::HaikuWindowHandle) -> Self {
Self {
b_window: handle.b_window,
b_direct_window: handle.b_direct_window,
..Self::empty()
}
}
}
45 changes: 29 additions & 16 deletions src/lib.rs
Expand Up @@ -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<T: new::HasRawWindowHandle + new::HasRawDisplayHandle> 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<T: HasRawWindowHandle + ?Sized> HasRawWindowHandle for alloc::rc::Rc<T> {
fn raw_window_handle(&self) -> RawWindowHandle {
(**self).raw_window_handle()
}
}
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
unsafe impl<T: HasRawWindowHandle + ?Sized> HasRawWindowHandle for alloc::sync::Arc<T> {
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!"
),
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/redox.rs
Expand Up @@ -23,3 +23,12 @@ impl OrbitalHandle {
}
}
}

impl From<new::OrbitalWindowHandle> for OrbitalHandle {
fn from(handle: new::OrbitalWindowHandle) -> Self {
Self {
window: handle.window,
..Self::empty()
}
}
}
11 changes: 11 additions & 0 deletions src/uikit.rs
Expand Up @@ -29,3 +29,14 @@ impl UiKitHandle {
}
}
}

impl From<new::UiKitWindowHandle> 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()
}
}
}
32 changes: 32 additions & 0 deletions src/unix.rs
Expand Up @@ -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()
}
}
}
9 changes: 9 additions & 0 deletions src/web.rs
Expand Up @@ -25,3 +25,12 @@ impl WebHandle {
Self { id: 0 }
}
}

impl From<new::WebWindowHandle> for WebHandle {
fn from(handle: new::WebWindowHandle) -> Self {
Self {
id: handle.id,
..Self::empty()
}
}
}
19 changes: 19 additions & 0 deletions src/windows.rs
Expand Up @@ -27,6 +27,16 @@ impl Win32Handle {
}
}

impl From<new::Win32WindowHandle> for Win32Handle {
fn from(handle: new::Win32WindowHandle) -> Self {
Self {
hwnd: handle.hwnd,
hinstance: handle.hinstance,
..Self::empty()
}
}
}

/// Raw window handle for WinRT.
///
/// ## Construction
Expand All @@ -49,3 +59,12 @@ impl WinRtHandle {
}
}
}

impl From<new::WinRtWindowHandle> for WinRtHandle {
fn from(handle: new::WinRtWindowHandle) -> Self {
Self {
core_window: handle.core_window,
..Self::empty()
}
}
}