raw_window_handle/redox.rs
1use core::ffi::c_void;
2use core::ptr::NonNull;
3
4use super::DisplayHandle;
5
6/// Raw display handle for the Redox operating system.
7#[non_exhaustive]
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
9pub struct OrbitalDisplayHandle {}
10
11impl OrbitalDisplayHandle {
12 /// Create a new empty display handle.
13 ///
14 ///
15 /// # Example
16 ///
17 /// ```
18 /// # use raw_window_handle::OrbitalDisplayHandle;
19 /// let handle = OrbitalDisplayHandle::new();
20 /// ```
21 pub fn new() -> Self {
22 Self {}
23 }
24}
25
26impl DisplayHandle<'static> {
27 /// Create an Orbital-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::orbital();
38 /// do_something(handle);
39 /// ```
40 pub fn orbital() -> Self {
41 // SAFETY: No data is borrowed.
42 unsafe { Self::borrow_raw(OrbitalDisplayHandle::new().into()) }
43 }
44}
45
46/// Raw window handle for the Redox operating system.
47#[non_exhaustive]
48#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
49pub struct OrbitalWindowHandle {
50 /// A pointer to an orbclient window.
51 // TODO(madsmtm): I think this is a file descriptor, so perhaps it should
52 // actually use `std::os::fd::RawFd`, or some sort of integer instead?
53 pub window: NonNull<c_void>,
54}
55
56impl OrbitalWindowHandle {
57 /// Create a new handle to a window.
58 ///
59 ///
60 /// # Example
61 ///
62 /// ```
63 /// # use core::ptr::NonNull;
64 /// # use raw_window_handle::OrbitalWindowHandle;
65 /// # type Window = ();
66 /// #
67 /// let window: NonNull<Window>;
68 /// # window = NonNull::from(&());
69 /// let mut handle = OrbitalWindowHandle::new(window.cast());
70 /// ```
71 pub fn new(window: NonNull<c_void>) -> Self {
72 Self { window }
73 }
74}