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_set_queue(*mut wl_proxy, *mut wl_event_queue) -> (),
61        fn wl_proxy_get_version(*mut wl_proxy) -> u32,
62        fn wl_proxy_create_wrapper(*mut wl_proxy) -> *mut wl_proxy,
63        fn wl_proxy_wrapper_destroy(*mut wl_proxy) -> (),
64
65    // log
66        fn wl_log_set_handler_client(wl_log_func_t) -> (),
67
68    // lists
69        fn wl_list_init(*mut wl_list) -> (),
70        fn wl_list_insert(*mut wl_list, *mut wl_list) -> (),
71        fn wl_list_remove(*mut wl_list) -> (),
72        fn wl_list_length(*const wl_list) -> c_int,
73        fn wl_list_empty(*const wl_list) -> c_int,
74        fn wl_list_insert_list(*mut wl_list,*mut wl_list) -> (),
75
76    // arrays
77        fn wl_array_init(*mut wl_array) -> (),
78        fn wl_array_release(*mut wl_array) -> (),
79        fn wl_array_add(*mut wl_array,usize) -> (),
80        fn wl_array_copy(*mut wl_array, *mut wl_array) -> (),
81
82    varargs:
83        fn wl_proxy_marshal_constructor(*mut wl_proxy, u32, *const wl_interface) -> *mut wl_proxy,
84        fn wl_proxy_marshal_constructor_versioned(*mut wl_proxy, u32, *const wl_interface, u32) -> *mut wl_proxy,
85        fn wl_proxy_marshal(*mut wl_proxy, u32) -> (),
86);
87
88#[cfg(all(feature = "client", feature = "dlopen"))]
89pub fn wayland_client_option() -> Option<&'static WaylandClient> {
90    static WAYLAND_CLIENT_OPTION: Lazy<Option<WaylandClient>> = Lazy::new(||{
91        let versions = ["libwayland-client.so.0", "libwayland-client.so"];
92        for ver in &versions {
93            match unsafe { WaylandClient::open(ver) } {
94                Ok(h) => return Some(h),
95                Err(::dlib::DlError::CantOpen(_)) => continue,
96                Err(::dlib::DlError::MissingSymbol(s)) => {
97                    log::error!("Found library {} cannot be used: symbol {} is missing.", ver, s);
98                    return None;
99                }
100            }
101        }
102        None
103    });
104
105    WAYLAND_CLIENT_OPTION.as_ref()
106}
107
108#[cfg(all(feature = "client", feature = "dlopen"))]
109pub fn wayland_client_handle() -> &'static WaylandClient {
110    static WAYLAND_CLIENT_HANDLE: Lazy<&'static WaylandClient> = Lazy::new(|| wayland_client_option().expect("Library libwayland-client.so could not be loaded."));
111
112    &WAYLAND_CLIENT_HANDLE
113}
114
115#[cfg(all(feature = "client", not(feature = "dlopen")))]
116pub fn is_lib_available() -> bool {
117    true
118}
119#[cfg(all(feature = "client", feature = "dlopen"))]
120pub fn is_lib_available() -> bool {
121    wayland_client_option().is_some()
122}