Skip to content

Commit

Permalink
Alleviate the need for ecosystem-wide upgrading to 0.4.1 (#74)
Browse files Browse the repository at this point in the history
* Make implementors of HasRawWindowHandle v0.4.1 also implement v0.3's

Uses the semver trick, see https://github.com/dtolnay/semver-trick

The idea is that this will allow crates whose purpose is to provide an `HasRawWindowHandle` implementation to upgrade first (e.g. `winit`, `sdl2`, `glfw`, `fltk`, ...). When a sufficient amount of "provider" crates have upgraded, "consumer" crates (e.g. `gfx`, `wgpu`, `rfd`, ...) can safely start upgrading without breaking for downstream users.

* Add changelog entry
  • Loading branch information
madsmtm committed Nov 23, 2021
1 parent 5207e99 commit 71f428d
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 0 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,15 @@
# Unreleased

* Add `HasRawWindowHandle` implementation for `HasRawWindowHandle` in the newer
version `0.4.1`.

This allows "provider" crates that implement `HasRawWindowHandle` (like
`winit`, `sdl2`, `glfw`, `fltk`, ...) to upgrade to `v0.4.1` without a
breaking change.

Afterwards "consumer" crates (like `gfx`, `wgpu`, `rfd`, ...) can start
upgrading with minimal breakage for their users.

# 0.3.3 (2019-12-1)

* Add missing `Hash` implementation for `AndroidHandle`.
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -16,6 +16,7 @@ appveyor = { repository = "rust-windowing/raw-window-handle" }

[dependencies]
libc = {version="0.2", features=[]}
new = { version = "0.4.1", package = "raw-window-handle" }

[features]
nightly-docs = []
Expand Down
9 changes: 9 additions & 0 deletions src/android.rs
Expand Up @@ -29,3 +29,12 @@ impl AndroidHandle {
}
}
}

impl From<new::AndroidNdkHandle> for AndroidHandle {
fn from(handle: new::AndroidNdkHandle) -> Self {
Self {
a_native_window: handle.a_native_window,
..Self::empty()
}
}
}
11 changes: 11 additions & 0 deletions src/ios.rs
Expand Up @@ -32,3 +32,14 @@ impl IOSHandle {
}
}
}

impl From<new::UiKitHandle> for IOSHandle {
fn from(handle: new::UiKitHandle) -> Self {
Self {
ui_window: handle.ui_window,
ui_view: handle.ui_view,
ui_view_controller: handle.ui_view_controller,
..Self::empty()
}
}
}
59 changes: 59 additions & 0 deletions src/lib.rs
Expand Up @@ -95,6 +95,65 @@ pub unsafe trait HasRawWindowHandle {
fn raw_window_handle(&self) -> RawWindowHandle;
}

unsafe impl<T: new::HasRawWindowHandle> HasRawWindowHandle for T {
fn raw_window_handle(&self) -> RawWindowHandle {
match new::HasRawWindowHandle::raw_window_handle(self) {
#[cfg(target_os = "ios")]
new::RawWindowHandle::UiKit(handle) => {
RawWindowHandle::IOS(handle.into())
}
#[cfg(target_os = "macos")]
new::RawWindowHandle::AppKit(handle) => {
RawWindowHandle::MacOS(handle.into())
}
#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
))]
new::RawWindowHandle::Xlib(handle) => {
RawWindowHandle::Xlib(handle.into())
}
#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
))]
new::RawWindowHandle::Xcb(handle) => {
RawWindowHandle::Xcb(handle.into())
}
#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
))]
new::RawWindowHandle::Wayland(handle) => {
RawWindowHandle::Wayland(handle.into())
}
#[cfg(target_os = "windows")]
new::RawWindowHandle::Win32(handle) => {
RawWindowHandle::Windows(handle.into())
}
#[cfg(target_arch = "wasm32")]
new::RawWindowHandle::Web(handle) => {
RawWindowHandle::Web(handle.into())
}
#[cfg(target_os = "android")]
new::RawWindowHandle::AndroidNdk(handle) => {
RawWindowHandle::Android(handle.into())
}
_ => panic!("Invalid handle for this platform. Please update raw-window-handle to > 0.4.1!")
}
}
}


#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum RawWindowHandle {
#[cfg_attr(feature = "nightly-docs", doc(cfg(target_os = "ios")))]
Expand Down
10 changes: 10 additions & 0 deletions src/macos.rs
Expand Up @@ -31,3 +31,13 @@ impl MacOSHandle {
}
}
}

impl From<new::AppKitHandle> for MacOSHandle {
fn from(handle: new::AppKitHandle) -> Self {
Self {
ns_window: handle.ns_window,
ns_view: handle.ns_view,
..Self::empty()
}
}
}
30 changes: 30 additions & 0 deletions src/unix.rs
Expand Up @@ -96,3 +96,33 @@ impl WaylandHandle {
}
}
}

impl From<new::XlibHandle> for XlibHandle {
fn from(handle: new::XlibHandle) -> Self {
Self {
window: handle.window,
display: handle.display,
..Self::empty()
}
}
}

impl From<new::XcbHandle> for XcbHandle {
fn from(handle: new::XcbHandle) -> Self {
Self {
window: handle.window,
connection: handle.connection,
..Self::empty()
}
}
}

impl From<new::WaylandHandle> for WaylandHandle {
fn from(handle: new::WaylandHandle) -> Self {
Self {
surface: handle.surface,
display: handle.display,
..Self::empty()
}
}
}
9 changes: 9 additions & 0 deletions src/web.rs
Expand Up @@ -31,3 +31,12 @@ impl WebHandle {
}
}
}

impl From<new::WebHandle> for WebHandle {
fn from(handle: new::WebHandle) -> Self {
Self {
id: handle.id,
..Self::empty()
}
}
}
10 changes: 10 additions & 0 deletions src/windows.rs
Expand Up @@ -32,3 +32,13 @@ impl WindowsHandle {
}
}
}

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

0 comments on commit 71f428d

Please sign in to comment.