Debian Codegraph @

third_party/rust/raw-window-handle/src/haiku.rs

raw
1 use core::ffi::c_void;
2 use core::ptr::NonNull;
3
4 use super::DisplayHandle;
5
6 /// Raw display handle for Haiku.
7 #[non_exhaustive]
8 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
9 pub struct HaikuDisplayHandle {}
10
11 impl HaikuDisplayHandle {
12 /// Create a new empty display handle.
13 ///
14 ///
15 /// # Example
16 ///
17 /// ```
18 /// # use raw_window_handle::HaikuDisplayHandle;
19 /// let handle = HaikuDisplayHandle::new();
20 /// ```
21 pub fn new() -> Self {
22 Self {}
23 }
24 }
25
26 impl DisplayHandle<'static> {
27 /// Create an Haiku-based display handle.
28 ///
29 /// As no data is borrowed by this handle, it is completely safe to create. This function
30 /// may be useful to windowing framework implementations that want to avoid unsafe code.
31 ///
32 /// # Example
33 ///
34 /// ```
35 /// # use raw_window_handle::{DisplayHandle, HasDisplayHandle};
36 /// # fn do_something(rwh: impl HasDisplayHandle) { let _ = rwh; }
37 /// let handle = DisplayHandle::haiku();
38 /// do_something(handle);
39 /// ```
40 pub fn haiku() -> Self {
41 // SAFETY: No data is borrowed.
42 unsafe { Self::borrow_raw(HaikuDisplayHandle::new().into()) }
43 }
44 }
45
46 /// Raw window handle for Haiku.
47 #[non_exhaustive]
48 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
49 pub struct HaikuWindowHandle {
50 /// A pointer to a BWindow object
51 pub b_window: NonNull<c_void>,
52 /// A pointer to a BDirectWindow object that might be null
53 pub b_direct_window: Option<NonNull<c_void>>,
54 }
55
56 impl HaikuWindowHandle {
57 /// Create a new handle to a window.
58 ///
59 ///
60 /// # Example
61 ///
62 /// ```
63 /// # use core::ptr::NonNull;
64 /// # use raw_window_handle::HaikuWindowHandle;
65 /// # type BWindow = ();
66 /// #
67 /// let b_window: NonNull<BWindow>;
68 /// # b_window = NonNull::from(&());
69 /// let mut handle = HaikuWindowHandle::new(b_window.cast());
70 /// // Optionally set `b_direct_window`.
71 /// handle.b_direct_window = None;
72 /// ```
73 pub fn new(b_window: NonNull<c_void>) -> Self {
74 Self {
75 b_window,
76 b_direct_window: None,
77 }
78 }
79 }