1 | //! Various types and functions that are used by both the client and the server |
2 | //! libraries. |
3 | |
4 | use std::os::unix::io::RawFd; |
5 | use std::{ |
6 | fmt, |
7 | os::raw::{c_char, c_int, c_void}, |
8 | }; |
9 | |
10 | #[repr (C)] |
11 | pub struct wl_message { |
12 | pub name: *const c_char, |
13 | pub signature: *const c_char, |
14 | pub types: *const *const wl_interface, |
15 | } |
16 | |
17 | #[repr (C)] |
18 | pub struct wl_interface { |
19 | pub name: *const c_char, |
20 | pub version: c_int, |
21 | pub request_count: c_int, |
22 | pub requests: *const wl_message, |
23 | pub event_count: c_int, |
24 | pub events: *const wl_message, |
25 | } |
26 | |
27 | impl fmt::Debug for wl_interface { |
28 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
29 | write!(f, "wl_interface@ {:p}" , self) |
30 | } |
31 | } |
32 | |
33 | unsafe impl Send for wl_interface {} |
34 | unsafe impl Sync for wl_interface {} |
35 | |
36 | #[repr (C)] |
37 | pub struct wl_list { |
38 | pub prev: *mut wl_list, |
39 | pub next: *mut wl_list, |
40 | } |
41 | |
42 | #[repr (C)] |
43 | pub struct wl_array { |
44 | pub size: usize, |
45 | pub alloc: usize, |
46 | pub data: *mut c_void, |
47 | } |
48 | |
49 | pub type wl_fixed_t = i32; |
50 | |
51 | pub fn wl_fixed_to_double(f: wl_fixed_t) -> f64 { |
52 | f64::from(f) / 256. |
53 | } |
54 | |
55 | pub fn wl_fixed_from_double(d: f64) -> wl_fixed_t { |
56 | (d * 256.) as i32 |
57 | } |
58 | |
59 | pub fn wl_fixed_to_int(f: wl_fixed_t) -> i32 { |
60 | f / 256 |
61 | } |
62 | |
63 | pub fn wl_fixed_from_int(i: i32) -> wl_fixed_t { |
64 | i * 256 |
65 | } |
66 | |
67 | // must be the appropriate size |
68 | // can contain i32, u32 and pointers |
69 | #[repr (C)] |
70 | pub union wl_argument { |
71 | pub i: i32, |
72 | pub u: u32, |
73 | pub f: wl_fixed_t, |
74 | pub s: *const c_char, |
75 | pub o: *const c_void, |
76 | pub n: u32, |
77 | pub a: *const wl_array, |
78 | pub h: RawFd, |
79 | } |
80 | |
81 | pub type wl_dispatcher_func_t = unsafe extern "C" fn( |
82 | *const c_void, |
83 | *mut c_void, |
84 | u32, |
85 | *const wl_message, |
86 | *const wl_argument, |
87 | ) -> c_int; |
88 | |
89 | pub type wl_log_func_t = unsafe extern "C" fn(*const c_char, *const c_void); |
90 | |