wayland_sys/
client.rs

1//! Bindings to the client library `libwayland-client.so`
2//!
3//! The generated handle is named `wayland_client_handle()`
4
5#![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    // display creation and destruction
22        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    // display events handling
27        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    // error handling
34        fn wl_display_get_error(*mut wl_display) -> c_int,
35        fn wl_display_get_protocol_error(*mut wl_display, *mut *const wl_interface, *mut u32) -> u32,
36    // requests handling
37        fn wl_display_flush(*mut wl_display) -> c_int,
38
39    // event queues
40        fn wl_event_queue_destroy(*mut wl_event_queue) -> (),
41        fn wl_display_create_queue(*mut wl_display) -> *mut wl_event_queue,
42        fn wl_display_roundtrip_queue(*mut wl_display, *mut wl_event_queue) -> c_int,
43        fn wl_display_prepare_read_queue(*mut wl_display, *mut wl_event_queue) -> c_int,
44        fn wl_display_dispatch_queue(*mut wl_display, *mut wl_event_queue) -> c_int,
45        fn wl_display_dispatch_queue_pending(*mut wl_display, *mut wl_event_queue) -> c_int,
46
47    // proxys
48        fn wl_proxy_create(*mut wl_proxy, *const wl_interface) -> *mut wl_proxy,
49        fn wl_proxy_destroy(*mut wl_proxy) -> (),
50        fn wl_proxy_add_listener(*mut wl_proxy, *mut extern "C" fn(), *mut c_void) -> c_int,
51        fn wl_proxy_get_listener(*mut wl_proxy) -> *const c_void,
52        fn wl_proxy_add_dispatcher(*mut wl_proxy, wl_dispatcher_func_t, *const c_void, *mut c_void) -> c_int,
53        fn wl_proxy_marshal_array_constructor(*mut wl_proxy, u32, *mut wl_argument, *const wl_interface) -> *mut wl_proxy,
54        fn wl_proxy_marshal_array_constructor_versioned(*mut wl_proxy, u32, *mut wl_argument, *const wl_interface, u32) -> *mut wl_proxy,
55        fn wl_proxy_marshal_array(*mut wl_proxy, u32, *mut wl_argument ) -> (),
56        fn wl_proxy_set_user_data(*mut wl_proxy, *mut c_void) -> (),
57        fn wl_proxy_get_user_data(*mut wl_proxy) -> *mut c_void,
58        fn wl_proxy_get_id(*mut wl_proxy) -> u32,
59        fn wl_proxy_get_class(*mut wl_proxy) -> *const c_char,
60        fn wl_proxy_get_display(*mut wl_proxy) -> *mut wl_display,
61        fn wl_proxy_set_queue(*mut wl_proxy, *mut wl_event_queue) -> (),
62        fn wl_proxy_get_version(*mut wl_proxy) -> u32,
63        fn wl_proxy_create_wrapper(*mut wl_proxy) -> *mut wl_proxy,
64        fn wl_proxy_wrapper_destroy(*mut wl_proxy) -> (),
65
66    // log
67        fn wl_log_set_handler_client(wl_log_func_t) -> (),
68
69    // lists
70        fn wl_list_init(*mut wl_list) -> (),
71        fn wl_list_insert(*mut wl_list, *mut wl_list) -> (),
72        fn wl_list_remove(*mut wl_list) -> (),
73        fn wl_list_length(*const wl_list) -> c_int,
74        fn wl_list_empty(*const wl_list) -> c_int,
75        fn wl_list_insert_list(*mut wl_list,*mut wl_list) -> (),
76
77    // arrays
78        fn wl_array_init(*mut wl_array) -> (),
79        fn wl_array_release(*mut wl_array) -> (),
80        fn wl_array_add(*mut wl_array,usize) -> (),
81        fn wl_array_copy(*mut wl_array, *mut wl_array) -> (),
82
83    varargs:
84        fn wl_proxy_marshal_constructor(*mut wl_proxy, u32, *const wl_interface) -> *mut wl_proxy,
85        fn wl_proxy_marshal_constructor_versioned(*mut wl_proxy, u32, *const wl_interface, u32) -> *mut wl_proxy,
86        fn wl_proxy_marshal(*mut wl_proxy, u32) -> (),
87);
88
89#[cfg(all(feature = "client", feature = "dlopen"))]
90pub fn wayland_client_option() -> Option<&'static WaylandClient> {
91    static WAYLAND_CLIENT_OPTION: Lazy<Option<WaylandClient>> = Lazy::new(||{
92        let versions = ["libwayland-client.so.0", "libwayland-client.so"];
93        for ver in &versions {
94            match unsafe { WaylandClient::open(ver) } {
95                Ok(h) => return Some(h),
96                Err(::dlib::DlError::CantOpen(_)) => continue,
97                Err(::dlib::DlError::MissingSymbol(s)) => {
98                    log::error!("Found library {ver} cannot be used: symbol {s} is missing.");
99                    return None;
100                }
101            }
102        }
103        None
104    });
105
106    WAYLAND_CLIENT_OPTION.as_ref()
107}
108
109#[cfg(all(feature = "client", feature = "dlopen"))]
110pub fn wayland_client_handle() -> &'static WaylandClient {
111    static WAYLAND_CLIENT_HANDLE: Lazy<&'static WaylandClient> = Lazy::new(|| wayland_client_option().expect("Library libwayland-client.so could not be loaded."));
112
113    &WAYLAND_CLIENT_HANDLE
114}
115
116#[cfg(all(feature = "client", not(feature = "dlopen")))]
117pub fn is_lib_available() -> bool {
118    true
119}
120#[cfg(all(feature = "client", feature = "dlopen"))]
121pub fn is_lib_available() -> bool {
122    wayland_client_option().is_some()
123}