Skip to content
Open
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
27 changes: 20 additions & 7 deletions src/android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ use core::ptr::NonNull;
use super::DisplayHandle;

/// Raw display handle for Android.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct AndroidDisplayHandle {}
pub struct AndroidDisplayHandle(());

impl AndroidDisplayHandle {
/// Create a new empty display handle.
Expand All @@ -19,7 +18,7 @@ impl AndroidDisplayHandle {
/// let handle = AndroidDisplayHandle::new();
/// ```
pub fn new() -> Self {
Self {}
Self(())
}
}

Expand All @@ -44,17 +43,14 @@ impl DisplayHandle<'static> {
}

/// Raw window handle for Android NDK.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct AndroidNdkWindowHandle {
/// A pointer to an `ANativeWindow`.
pub a_native_window: NonNull<c_void>,
a_native_window: NonNull<c_void>,
}

impl AndroidNdkWindowHandle {
/// Create a new handle to an `ANativeWindow`.
///
///
/// # Example
///
/// ```
Expand All @@ -69,4 +65,21 @@ impl AndroidNdkWindowHandle {
pub fn new(a_native_window: NonNull<c_void>) -> Self {
Self { a_native_window }
}

/// A pointer to an `ANativeWindow`.
///
/// # Example
///
/// ```
/// # use core::ptr::NonNull;
/// # use raw_window_handle::AndroidNdkWindowHandle;
/// # type ANativeWindow = ();
/// #
/// # let handle = AndroidNdkWindowHandle::new(NonNull::dangling());
/// let ptr = handle.a_native_window();
/// let ptr = ptr.cast::<ANativeWindow>();
/// ```
pub fn a_native_window(&self) -> NonNull<c_void> {
self.a_native_window
}
}
16 changes: 9 additions & 7 deletions src/appkit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ use core::ptr::NonNull;
use super::DisplayHandle;

/// Raw display handle for AppKit.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct AppKitDisplayHandle {}
pub struct AppKitDisplayHandle(());

impl AppKitDisplayHandle {
/// Create a new empty display handle.
Expand All @@ -19,7 +18,7 @@ impl AppKitDisplayHandle {
/// let handle = AppKitDisplayHandle::new();
/// ```
pub fn new() -> Self {
Self {}
Self(())
}
}

Expand Down Expand Up @@ -70,7 +69,7 @@ impl DisplayHandle<'static> {
/// # #[cfg(requires_objc2)]
/// RawWindowHandle::AppKit(handle) => {
/// assert!(MainThreadMarker::new().is_some(), "can only access AppKit handles on the main thread");
/// let ns_view = handle.ns_view.as_ptr();
/// let ns_view = handle.ns_view().as_ptr();
/// // SAFETY: The pointer came from `WindowHandle`, which ensures
/// // that the `AppKitWindowHandle` contains a valid pointer to an
/// // `NSView`.
Expand All @@ -83,11 +82,9 @@ impl DisplayHandle<'static> {
/// }
/// # }
/// ```
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct AppKitWindowHandle {
/// A pointer to an `NSView` object.
pub ns_view: NonNull<c_void>,
ns_view: NonNull<c_void>,
}

impl AppKitWindowHandle {
Expand All @@ -112,4 +109,9 @@ impl AppKitWindowHandle {
pub fn new(ns_view: NonNull<c_void>) -> Self {
Self { ns_view }
}

/// A pointer to an `NSView` object.
pub fn ns_view(&self) -> NonNull<c_void> {
self.ns_view
}
}
18 changes: 12 additions & 6 deletions src/drm.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/// Raw display handle for the Linux Kernel Mode Set/Direct Rendering Manager.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct DrmDisplayHandle {
/// The drm file descriptor.
// TODO: Use `std::os::fd::RawFd`?
pub fd: i32,
fd: i32,
}

impl DrmDisplayHandle {
Expand All @@ -23,14 +21,17 @@ impl DrmDisplayHandle {
pub fn new(fd: i32) -> Self {
Self { fd }
}

/// The drm file descriptor.
pub fn fd(&self) -> i32 {
self.fd
}
}

/// Raw window handle for the Linux Kernel Mode Set/Direct Rendering Manager.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct DrmWindowHandle {
/// The primary drm plane handle.
pub plane: u32,
plane: u32,
}

impl DrmWindowHandle {
Expand All @@ -49,4 +50,9 @@ impl DrmWindowHandle {
pub fn new(plane: u32) -> Self {
Self { plane }
}

/// The primary drm plane handle.
pub fn plane(&self) -> u32 {
self.plane
}
}
18 changes: 12 additions & 6 deletions src/gbm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ use core::ffi::c_void;
use core::ptr::NonNull;

/// Raw display handle for the Linux Generic Buffer Manager.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct GbmDisplayHandle {
/// The gbm device.
pub gbm_device: NonNull<c_void>,
gbm_device: NonNull<c_void>,
}

impl GbmDisplayHandle {
Expand All @@ -27,14 +25,17 @@ impl GbmDisplayHandle {
pub fn new(gbm_device: NonNull<c_void>) -> Self {
Self { gbm_device }
}

/// The gbm device.
pub fn gbm_device(&self) -> NonNull<c_void> {
self.gbm_device
}
}

/// Raw window handle for the Linux Generic Buffer Manager.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct GbmWindowHandle {
/// The gbm surface.
pub gbm_surface: NonNull<c_void>,
gbm_surface: NonNull<c_void>,
}

impl GbmWindowHandle {
Expand All @@ -55,4 +56,9 @@ impl GbmWindowHandle {
pub fn new(gbm_surface: NonNull<c_void>) -> Self {
Self { gbm_surface }
}

/// The gbm surface.
pub fn gbm_surface(&self) -> NonNull<c_void> {
self.gbm_surface
}
}
50 changes: 38 additions & 12 deletions src/haiku.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ use core::ptr::NonNull;
use super::DisplayHandle;

/// Raw display handle for Haiku.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct HaikuDisplayHandle {}
pub struct HaikuDisplayHandle(());

impl HaikuDisplayHandle {
/// Create a new empty display handle.
Expand All @@ -19,7 +18,7 @@ impl HaikuDisplayHandle {
/// let handle = HaikuDisplayHandle::new();
/// ```
pub fn new() -> Self {
Self {}
Self(())
}
}

Expand All @@ -44,19 +43,15 @@ impl DisplayHandle<'static> {
}

/// Raw window handle for Haiku.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct HaikuWindowHandle {
/// A pointer to a BWindow object
pub b_window: NonNull<c_void>,
/// A pointer to a BDirectWindow object that might be null
pub b_direct_window: Option<NonNull<c_void>>,
b_window: NonNull<c_void>,
b_direct_window: Option<NonNull<c_void>>,
}

impl HaikuWindowHandle {
/// Create a new handle to a window.
///
///
/// # Example
///
/// ```
Expand All @@ -66,14 +61,45 @@ impl HaikuWindowHandle {
/// #
/// let b_window: NonNull<BWindow>;
/// # b_window = NonNull::from(&());
/// let mut handle = HaikuWindowHandle::new(b_window.cast());
/// // Optionally set `b_direct_window`.
/// handle.b_direct_window = None;
/// let handle = HaikuWindowHandle::new(b_window.cast());
/// ```
pub fn new(b_window: NonNull<c_void>) -> Self {
Self {
b_window,
b_direct_window: None,
}
}

/// Create a new window handle together with a `BDirectWindow`.
///
/// # Example
///
/// ```
/// # use core::ptr::NonNull;
/// # use raw_window_handle::HaikuWindowHandle;
/// # type BWindow = ();
/// # type BDirectWindow = ();
/// #
/// let b_window: NonNull<BWindow>;
/// let b_direct_window: NonNull<BDirectWindow>;
/// # b_window = NonNull::dangling();
/// # b_direct_window = NonNull::dangling();
/// let handle = HaikuWindowHandle::with_window(b_window.cast(), b_direct_window.cast());
/// ```
pub fn with_window(b_window: NonNull<c_void>, b_direct_window: NonNull<c_void>) -> Self {
Self {
b_window,
b_direct_window: Some(b_direct_window),
}
}

/// A pointer to a BWindow object.
pub fn b_window(&self) -> NonNull<c_void> {
self.b_window
}

/// A pointer to a BDirectWindow object that might be null.
pub fn b_direct_window(&self) -> Option<NonNull<c_void>> {
self.b_direct_window
}
}
13 changes: 8 additions & 5 deletions src/ohos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ use core::ptr::NonNull;
use super::DisplayHandle;

/// Raw display handle for OpenHarmony.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct OhosDisplayHandle {}
pub struct OhosDisplayHandle(());

impl OhosDisplayHandle {
/// Create a new empty display handle.
Expand All @@ -35,7 +34,7 @@ impl OhosDisplayHandle {
/// let handle = OhosDisplayHandle::new();
/// ```
pub fn new() -> Self {
Self {}
Self(())
}
}

Expand All @@ -60,10 +59,9 @@ impl DisplayHandle<'static> {
}

/// Raw window handle for Ohos NDK.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct OhosNdkWindowHandle {
pub native_window: NonNull<c_void>,
native_window: NonNull<c_void>,
}

impl OhosNdkWindowHandle {
Expand Down Expand Up @@ -95,4 +93,9 @@ impl OhosNdkWindowHandle {
pub fn new(native_window: NonNull<c_void>) -> Self {
Self { native_window }
}

/// Get the handle to `OHNativeWindow`.
pub fn native_window(&self) -> NonNull<c_void> {
self.native_window
}
}
14 changes: 8 additions & 6 deletions src/redox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ use core::ptr::NonNull;
use super::DisplayHandle;

/// Raw display handle for the Redox operating system.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct OrbitalDisplayHandle {}
pub struct OrbitalDisplayHandle(());

impl OrbitalDisplayHandle {
/// Create a new empty display handle.
Expand All @@ -19,7 +18,7 @@ impl OrbitalDisplayHandle {
/// let handle = OrbitalDisplayHandle::new();
/// ```
pub fn new() -> Self {
Self {}
Self(())
}
}

Expand All @@ -44,13 +43,11 @@ impl DisplayHandle<'static> {
}

/// Raw window handle for the Redox operating system.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct OrbitalWindowHandle {
/// A pointer to an orbclient window.
// TODO(madsmtm): I think this is a file descriptor, so perhaps it should
// actually use `std::os::fd::RawFd`, or some sort of integer instead?
pub window: NonNull<c_void>,
window: NonNull<c_void>,
}

impl OrbitalWindowHandle {
Expand All @@ -71,4 +68,9 @@ impl OrbitalWindowHandle {
pub fn new(window: NonNull<c_void>) -> Self {
Self { window }
}

/// A pointer to an orbclient window.
pub fn window(&self) -> NonNull<c_void> {
self.window
}
}
Loading