1 | use core::ffi::{c_int, c_ulong, c_void}; |
2 | use core::ptr; |
3 | |
4 | /// Raw display handle for Xlib. |
5 | /// |
6 | /// ## Construction |
7 | /// ``` |
8 | /// # use raw_window_handle::XlibDisplayHandle; |
9 | /// let display_handle = XlibDisplayHandle::empty(); |
10 | /// /* set fields */ |
11 | /// ``` |
12 | #[non_exhaustive ] |
13 | #[derive (Debug, Clone, Copy, PartialEq, Eq, Hash)] |
14 | pub struct XlibDisplayHandle { |
15 | /// A pointer to an Xlib `Display`. |
16 | pub display: *mut c_void, |
17 | |
18 | /// An X11 screen to use with this display handle. |
19 | /// |
20 | /// Note, that X11 could have multiple screens, however |
21 | /// graphics APIs could work only with one screen at the time, |
22 | /// given that multiple screens usually reside on different GPUs. |
23 | pub screen: c_int, |
24 | } |
25 | |
26 | /// Raw window handle for Xlib. |
27 | /// |
28 | /// ## Construction |
29 | /// ``` |
30 | /// # use raw_window_handle::XlibWindowHandle; |
31 | /// let window_handle = XlibWindowHandle::empty(); |
32 | /// /* set fields */ |
33 | /// ``` |
34 | #[non_exhaustive ] |
35 | #[derive (Debug, Clone, Copy, PartialEq, Eq, Hash)] |
36 | pub struct XlibWindowHandle { |
37 | /// An Xlib `Window`. |
38 | pub window: c_ulong, |
39 | /// An Xlib visual ID, or 0 if unknown. |
40 | pub visual_id: c_ulong, |
41 | } |
42 | |
43 | /// Raw display handle for Xcb. |
44 | /// |
45 | /// ## Construction |
46 | /// ``` |
47 | /// # use raw_window_handle::XcbDisplayHandle; |
48 | /// let display_handle = XcbDisplayHandle::empty(); |
49 | /// /* set fields */ |
50 | /// ``` |
51 | #[non_exhaustive ] |
52 | #[derive (Debug, Clone, Copy, PartialEq, Eq, Hash)] |
53 | pub struct XcbDisplayHandle { |
54 | /// A pointer to an X server `xcb_connection_t`. |
55 | pub connection: *mut c_void, |
56 | |
57 | /// An X11 screen to use with this display handle. |
58 | /// |
59 | /// Note, that X11 could have multiple screens, however |
60 | /// graphics APIs could work only with one screen at the time, |
61 | /// given that multiple screens usually reside on different GPUs. |
62 | pub screen: c_int, |
63 | } |
64 | |
65 | /// Raw window handle for Xcb. |
66 | /// |
67 | /// ## Construction |
68 | /// ``` |
69 | /// # use raw_window_handle::XcbWindowHandle; |
70 | /// let window_handle = XcbWindowHandle::empty(); |
71 | /// /* set fields */ |
72 | /// ``` |
73 | #[non_exhaustive ] |
74 | #[derive (Debug, Clone, Copy, PartialEq, Eq, Hash)] |
75 | pub struct XcbWindowHandle { |
76 | /// An X11 `xcb_window_t`. |
77 | pub window: u32, // Based on xproto.h |
78 | /// An X11 `xcb_visualid_t`, or 0 if unknown. |
79 | pub visual_id: u32, |
80 | } |
81 | |
82 | /// Raw display handle for Wayland. |
83 | /// |
84 | /// ## Construction |
85 | /// ``` |
86 | /// # use raw_window_handle::WaylandDisplayHandle; |
87 | /// let display_handle = WaylandDisplayHandle::empty(); |
88 | /// /* set fields */ |
89 | /// ``` |
90 | #[non_exhaustive ] |
91 | #[derive (Debug, Clone, Copy, PartialEq, Eq, Hash)] |
92 | pub struct WaylandDisplayHandle { |
93 | /// A pointer to a `wl_display`. |
94 | pub display: *mut c_void, |
95 | } |
96 | |
97 | /// Raw window handle for Wayland. |
98 | /// |
99 | /// ## Construction |
100 | /// ``` |
101 | /// # use raw_window_handle::WaylandWindowHandle; |
102 | /// let window_handle = WaylandWindowHandle::empty(); |
103 | /// /* set fields */ |
104 | /// ``` |
105 | #[non_exhaustive ] |
106 | #[derive (Debug, Clone, Copy, PartialEq, Eq, Hash)] |
107 | pub struct WaylandWindowHandle { |
108 | /// A pointer to a `wl_surface`. |
109 | pub surface: *mut c_void, |
110 | } |
111 | |
112 | /// Raw display handle for the Linux Kernel Mode Set/Direct Rendering Manager. |
113 | /// |
114 | /// ## Construction |
115 | /// ``` |
116 | /// # use raw_window_handle::DrmDisplayHandle; |
117 | /// let display_handle = DrmDisplayHandle::empty(); |
118 | /// /* set fields */ |
119 | /// ``` |
120 | #[non_exhaustive ] |
121 | #[derive (Debug, Clone, Copy, PartialEq, Eq, Hash)] |
122 | pub struct DrmDisplayHandle { |
123 | /// The drm file descriptor. |
124 | pub fd: i32, |
125 | } |
126 | |
127 | /// Raw window handle for the Linux Kernel Mode Set/Direct Rendering Manager. |
128 | /// |
129 | /// ## Construction |
130 | /// ``` |
131 | /// # use raw_window_handle::DrmWindowHandle; |
132 | /// let handle = DrmWindowHandle::empty(); |
133 | /// /* set fields */ |
134 | /// ``` |
135 | #[non_exhaustive ] |
136 | #[derive (Debug, Clone, Copy, PartialEq, Eq, Hash)] |
137 | pub struct DrmWindowHandle { |
138 | /// The primary drm plane handle. |
139 | pub plane: u32, |
140 | } |
141 | |
142 | /// Raw display handle for the Linux Generic Buffer Manager. |
143 | /// |
144 | /// ## Construction |
145 | /// ``` |
146 | /// # use raw_window_handle::GbmDisplayHandle; |
147 | /// let display_handle = GbmDisplayHandle::empty(); |
148 | /// /* set fields */ |
149 | /// ``` |
150 | #[non_exhaustive ] |
151 | #[derive (Debug, Clone, Copy, PartialEq, Eq, Hash)] |
152 | pub struct GbmDisplayHandle { |
153 | /// The gbm device. |
154 | pub gbm_device: *mut c_void, |
155 | } |
156 | |
157 | /// Raw window handle for the Linux Generic Buffer Manager. |
158 | /// |
159 | /// ## Construction |
160 | /// ``` |
161 | /// # use raw_window_handle::GbmWindowHandle; |
162 | /// let handle = GbmWindowHandle::empty(); |
163 | /// /* set fields */ |
164 | /// ``` |
165 | #[non_exhaustive ] |
166 | #[derive (Debug, Clone, Copy, PartialEq, Eq, Hash)] |
167 | pub struct GbmWindowHandle { |
168 | /// The gbm surface. |
169 | pub gbm_surface: *mut c_void, |
170 | } |
171 | |
172 | impl XlibDisplayHandle { |
173 | pub fn empty() -> Self { |
174 | Self { |
175 | display: ptr::null_mut(), |
176 | screen: 0, |
177 | } |
178 | } |
179 | } |
180 | |
181 | impl XlibWindowHandle { |
182 | pub fn empty() -> Self { |
183 | Self { |
184 | window: 0, |
185 | visual_id: 0, |
186 | } |
187 | } |
188 | } |
189 | |
190 | impl XcbDisplayHandle { |
191 | pub fn empty() -> Self { |
192 | Self { |
193 | connection: ptr::null_mut(), |
194 | screen: 0, |
195 | } |
196 | } |
197 | } |
198 | |
199 | impl XcbWindowHandle { |
200 | pub fn empty() -> Self { |
201 | Self { |
202 | window: 0, |
203 | visual_id: 0, |
204 | } |
205 | } |
206 | } |
207 | |
208 | impl WaylandDisplayHandle { |
209 | pub fn empty() -> Self { |
210 | Self { |
211 | display: ptr::null_mut(), |
212 | } |
213 | } |
214 | } |
215 | |
216 | impl WaylandWindowHandle { |
217 | pub fn empty() -> Self { |
218 | Self { |
219 | surface: ptr::null_mut(), |
220 | } |
221 | } |
222 | } |
223 | |
224 | impl DrmDisplayHandle { |
225 | pub fn empty() -> Self { |
226 | Self { fd: 0 } |
227 | } |
228 | } |
229 | |
230 | impl DrmWindowHandle { |
231 | pub fn empty() -> Self { |
232 | Self { plane: 0 } |
233 | } |
234 | } |
235 | |
236 | impl GbmDisplayHandle { |
237 | pub fn empty() -> Self { |
238 | Self { |
239 | gbm_device: ptr::null_mut(), |
240 | } |
241 | } |
242 | } |
243 | |
244 | impl GbmWindowHandle { |
245 | pub fn empty() -> Self { |
246 | Self { |
247 | gbm_surface: ptr::null_mut(), |
248 | } |
249 | } |
250 | } |
251 | |