1#![cfg_attr(rustfmt, rustfmt_skip)]
6
7#[cfg(all(feature = "client", feature = "dlopen"))]
8use once_cell::sync::Lazy;
9#[cfg(feature = "client")]
10use super::common::*;
11#[cfg(feature = "client")]
12use std::os::raw::{c_char, c_int, c_void};
13
14pub enum wl_proxy {}
15pub enum wl_display {}
16pub enum wl_event_queue {}
17
18#[cfg(feature = "client")]
19external_library!(WaylandClient, "wayland-client",
20 functions:
21 fn wl_display_connect_to_fd(c_int) -> *mut wl_display,
23 fn wl_display_connect(*const c_char) -> *mut wl_display,
24 fn wl_display_disconnect(*mut wl_display) -> (),
25 fn wl_display_get_fd(*mut wl_display) -> c_int,
26 fn wl_display_roundtrip(*mut wl_display) -> c_int,
28 fn wl_display_read_events(*mut wl_display) -> c_int,
29 fn wl_display_prepare_read(*mut wl_display) -> c_int,
30 fn wl_display_cancel_read(*mut wl_display) -> (),
31 fn wl_display_dispatch(*mut wl_display) -> c_int,
32 fn wl_display_dispatch_pending(*mut wl_display) -> c_int,
33 #[cfg(feature = "libwayland_client_1_23")]
34 fn wl_display_set_max_buffer_size(*mut wl_display, usize) -> (),
35 fn wl_display_get_error(*mut wl_display) -> c_int,
37 fn wl_display_get_protocol_error(*mut wl_display, *mut *const wl_interface, *mut u32) -> u32,
38 fn wl_display_flush(*mut wl_display) -> c_int,
40
41 fn wl_event_queue_destroy(*mut wl_event_queue) -> (),
43 fn wl_display_create_queue(*mut wl_display) -> *mut wl_event_queue,
44 fn wl_display_roundtrip_queue(*mut wl_display, *mut wl_event_queue) -> c_int,
45 fn wl_display_prepare_read_queue(*mut wl_display, *mut wl_event_queue) -> c_int,
46 fn wl_display_dispatch_queue(*mut wl_display, *mut wl_event_queue) -> c_int,
47 fn wl_display_dispatch_queue_pending(*mut wl_display, *mut wl_event_queue) -> c_int,
48
49 fn wl_proxy_create(*mut wl_proxy, *const wl_interface) -> *mut wl_proxy,
51 fn wl_proxy_destroy(*mut wl_proxy) -> (),
52 fn wl_proxy_add_listener(*mut wl_proxy, *mut extern "C" fn(), *mut c_void) -> c_int,
53 fn wl_proxy_get_listener(*mut wl_proxy) -> *const c_void,
54 fn wl_proxy_add_dispatcher(*mut wl_proxy, wl_dispatcher_func_t, *const c_void, *mut c_void) -> c_int,
55 fn wl_proxy_marshal_array_constructor(*mut wl_proxy, u32, *mut wl_argument, *const wl_interface) -> *mut wl_proxy,
56 fn wl_proxy_marshal_array_constructor_versioned(*mut wl_proxy, u32, *mut wl_argument, *const wl_interface, u32) -> *mut wl_proxy,
57 fn wl_proxy_marshal_array(*mut wl_proxy, u32, *mut wl_argument ) -> (),
58 fn wl_proxy_set_user_data(*mut wl_proxy, *mut c_void) -> (),
59 fn wl_proxy_get_user_data(*mut wl_proxy) -> *mut c_void,
60 fn wl_proxy_get_id(*mut wl_proxy) -> u32,
61 fn wl_proxy_get_class(*mut wl_proxy) -> *const c_char,
62 #[cfg(feature = "libwayland_client_1_23")]
63 fn wl_proxy_get_display(*mut wl_proxy) -> *mut wl_display,
64 fn wl_proxy_set_queue(*mut wl_proxy, *mut wl_event_queue) -> (),
65 fn wl_proxy_get_version(*mut wl_proxy) -> u32,
66 fn wl_proxy_create_wrapper(*mut wl_proxy) -> *mut wl_proxy,
67 fn wl_proxy_wrapper_destroy(*mut wl_proxy) -> (),
68
69 fn wl_log_set_handler_client(wl_log_func_t) -> (),
71
72 fn wl_list_init(*mut wl_list) -> (),
74 fn wl_list_insert(*mut wl_list, *mut wl_list) -> (),
75 fn wl_list_remove(*mut wl_list) -> (),
76 fn wl_list_length(*const wl_list) -> c_int,
77 fn wl_list_empty(*const wl_list) -> c_int,
78 fn wl_list_insert_list(*mut wl_list,*mut wl_list) -> (),
79
80 fn wl_array_init(*mut wl_array) -> (),
82 fn wl_array_release(*mut wl_array) -> (),
83 fn wl_array_add(*mut wl_array,usize) -> (),
84 fn wl_array_copy(*mut wl_array, *mut wl_array) -> (),
85
86 varargs:
87 fn wl_proxy_marshal_constructor(*mut wl_proxy, u32, *const wl_interface) -> *mut wl_proxy,
88 fn wl_proxy_marshal_constructor_versioned(*mut wl_proxy, u32, *const wl_interface, u32) -> *mut wl_proxy,
89 fn wl_proxy_marshal(*mut wl_proxy, u32) -> (),
90);
91
92#[cfg(all(feature = "client", feature = "dlopen"))]
93pub fn wayland_client_option() -> Option<&'static WaylandClient> {
94 static WAYLAND_CLIENT_OPTION: Lazy<Option<WaylandClient>> = Lazy::new(||{
95 let versions = ["libwayland-client.so.0", "libwayland-client.so"];
96 for ver in &versions {
97 match unsafe { WaylandClient::open(ver) } {
98 Ok(h) => return Some(h),
99 Err(::dlib::DlError::CantOpen(_)) => continue,
100 Err(::dlib::DlError::MissingSymbol(s)) => {
101 log::error!("Found library {ver} cannot be used: symbol {s} is missing.");
102 return None;
103 }
104 }
105 }
106 None
107 });
108
109 WAYLAND_CLIENT_OPTION.as_ref()
110}
111
112#[cfg(all(feature = "client", feature = "dlopen"))]
113pub fn wayland_client_handle() -> &'static WaylandClient {
114 static WAYLAND_CLIENT_HANDLE: Lazy<&'static WaylandClient> = Lazy::new(|| wayland_client_option().expect("Library libwayland-client.so could not be loaded."));
115
116 &WAYLAND_CLIENT_HANDLE
117}
118
119#[cfg(all(feature = "client", not(feature = "dlopen")))]
120pub fn is_lib_available() -> bool {
121 true
122}
123#[cfg(all(feature = "client", feature = "dlopen"))]
124pub fn is_lib_available() -> bool {
125 wayland_client_option().is_some()
126}