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

wayland-backend: raw-window-handle 0.6 #707

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions wayland-backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ log = { version = "0.4", optional = true }
scoped-tls = "1.0"
downcast-rs = "1.2"
raw-window-handle = { version = "0.5.0", optional = true }
rwh_06 = { package = "raw-window-handle", version = "0.6.0", optional = true }

[dependencies.smallvec]
version = "1.9"
Expand Down
8 changes: 6 additions & 2 deletions wayland-backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@
//!
//! ## raw-window-handle integration
//!
//! This crate can implement [`HasRawWindowHandle`](raw_window_handle::HasRawWindowHandle) for the client
//! module [`Backend`](client::Backend) type if you activate the `raw-window-handle` feature.
//! The `rwh_06` feature activates the [`HasDisplayHandle`](raw_window_handle::HasDisplayHandle) implementation
//! for the client module [`Backend`](client::Backend).
//!
//! ### Deprecated raw-window-handle versions
//!
//! While raw-window-handle 0.5 is supported via the `raw-window-handle` feature, it is deprecated and will be removed in the future.
//!
//! Note that the `client_system` feature must also be enabled for the implementation to be activated.

Expand Down
22 changes: 22 additions & 0 deletions wayland-backend/src/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,28 @@ unsafe impl raw_window_handle::HasRawDisplayHandle for client::Backend {
}
}

#[cfg(all(feature = "rwh_06", feature = "client_system"))]
impl rwh_06::HasDisplayHandle for client::Backend {
fn display_handle(&self) -> Result<rwh_06::DisplayHandle<'_>, rwh_06::HandleError> {
use std::ptr::NonNull;

// SAFETY:
// - The display_ptr will be valid, either because we have created the pointer or the caller which created the
// backend has ensured the pointer is valid when `Backend::from_foreign_display` was called.
let ptr = unsafe { NonNull::new_unchecked(self.display_ptr().cast()) };
let handle = rwh_06::WaylandDisplayHandle::new(ptr);
let raw = rwh_06::RawDisplayHandle::Wayland(handle);

// SAFETY:
// - The display_ptr will be valid, either because we have created the pointer or the caller which created the
// backend has ensured the pointer is valid when `Backend::from_foreign_display` was called.
// - The lifetime assigned to the DisplayHandle borrows the Backend, ensuring the display pointer
// is valid..
// - The display_ptr will not change for the lifetime of the backend.
Ok(unsafe { rwh_06::DisplayHandle::borrow_raw(raw) })
}
}

/// Server-side implementation of a Wayland protocol backend using `libwayland`
///
/// The main entrypoint is the [`Backend::new`](server::Backend::new) method.
Expand Down
Loading