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

Alleviate the need for ecosystem-wide upgrading to 0.4.1 #74

Merged
merged 2 commits into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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" }
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure if this, or by using extern crate raw_window_handle as new; is the most robust way to rename a crate?


[features]
nightly-docs = []
Expand Down
9 changes: 9 additions & 0 deletions src/android.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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()
}
}
}