1 //! Bindings to the `wayland-cursor.so` library
2 //!
3 //! The created handle is named `WAYLAND_CURSOR_HANDLE`.
4
5 use crate::client::wl_proxy;
6 use std::os::raw::{c_char, c_int, c_uint};
7
8 pub enum wl_cursor_theme {}
9
10 #[repr(C)]
11 pub struct wl_cursor_image {
12 /// actual width
13 pub width: u32,
14 /// actual height
15 pub height: u32,
16 /// hot spot x (must be inside image)
17 pub hotspot_x: u32,
18 /// hot spot y (must be inside image)
19 pub hotspot_y: u32,
20 /// animation delay to next frame
21 pub delay: u32,
22 }
23
24 #[repr(C)]
25 pub struct wl_cursor {
26 pub image_count: c_uint,
27 pub images: *mut *mut wl_cursor_image,
28 pub name: *mut c_char,
29 }
30
31 external_library!(WaylandCursor, "wayland-cursor",
32 functions:
33 fn wl_cursor_theme_load(*const c_char, c_int, *mut wl_proxy) -> *mut wl_cursor_theme,
34 fn wl_cursor_theme_destroy(*mut wl_cursor_theme) -> (),
35 fn wl_cursor_theme_get_cursor(*mut wl_cursor_theme, *const c_char) -> *mut wl_cursor,
36 fn wl_cursor_image_get_buffer(*mut wl_cursor_image) -> *mut wl_proxy,
37 fn wl_cursor_frame(*mut wl_cursor, u32) -> c_int,
38 fn wl_cursor_frame_and_duration(*mut wl_cursor, u32, *mut u32) -> c_int,
39 );
40
41 #[cfg(feature = "dlopen")]
42 lazy_static::lazy_static!(
43 pub static ref WAYLAND_CURSOR_OPTION: Option<WaylandCursor> = {
44 // This is a workaround for Ubuntu 17.04, which doesn't have a bare symlink
45 // for libwayland-client.so but does have it with the version numbers for
46 // whatever reason.
47 //
48 // We could do some trickery with str slices but that is more trouble
49 // than its worth
50 let versions = ["libwayland-cursor.so",
51 "libwayland-cursor.so.0"];
52
53 for ver in &versions {
54 match WaylandCursor::open(ver) {
55 Ok(h) => return Some(h),
56 Err(::dlib::DlError::NotFound) => continue,
57 Err(::dlib::DlError::MissingSymbol(s)) => {
58 if ::std::env::var_os("WAYLAND_RS_DEBUG").is_some() {
59 // only print debug messages if WAYLAND_RS_DEBUG is set
60 eprintln!("[wayland-client] Found library {} cannot be used: symbol {} is missing.", ver, s);
61 }
62 return None;
63 }
64 }
65 }
66 None
67 };
68 pub static ref WAYLAND_CURSOR_HANDLE: &'static WaylandCursor = {
69 WAYLAND_CURSOR_OPTION.as_ref().expect("Library libwayland-cursor.so could not be loaded.")
70 };
71 );
72
73 #[cfg(not(feature = "dlopen"))]
is_lib_available() -> bool74 pub fn is_lib_available() -> bool {
75 true
76 }
77 #[cfg(feature = "dlopen")]
is_lib_available() -> bool78 pub fn is_lib_available() -> bool {
79 WAYLAND_CURSOR_OPTION.is_some()
80 }
81