1 //! FFI bindings to the wayland system libraries. 2 //! 3 //! The names exported by this crate should *not* be used directly, but through 4 //! the `ffi_dispatch` macro, like this: 5 //! 6 //! ```ignore 7 //! ffi_dispatch!(HANDLE_NAME, func_name, arg1, arg2, arg3); 8 //! ``` 9 //! 10 //! Where `HANDLE_NAME` is the name of the handle generated if the cargo feature `dlopen` is on. 11 //! 12 //! For this to work, you must ensure every needed symbol is in scope (aka the static handle 13 //! if `dlopen` is on, the extern function if not). The easiest way to do this is to glob import 14 //! the appropriate module. For example: 15 //! 16 //! ```ignore 17 //! #[macro_use] extern crate wayland_sys; 18 //! 19 //! use wayland_sys::client::*; 20 //! 21 //! fn main() { 22 //! let display_ptr = unsafe { 23 //! ffi_dispatch!(WAYLAND_CLIENT_HANDLE, wl_display_connect, ::std::ptr::null()) 24 //! }; 25 //! } 26 //! ``` 27 //! 28 //! Each module except `common` corresponds to a system library. They all define a function named 29 //! `is_lib_available()` which returns whether the library could be loaded. They always return true 30 //! if the feature `dlopen` is absent, as we link against the library directly in that case. 31 #![allow(non_camel_case_types)] 32 33 // If compiling with neither the `client` or `server` feature (non-sensical but 34 // it's what happens when running `cargo test --all` from the workspace root), 35 // dlib isn't actually used. This is not an issue, so don't warn about it. 36 #[allow(unused_imports)] 37 #[cfg(any(feature = "client", feature = "server"))] 38 #[macro_use] 39 extern crate dlib; 40 41 // Same as with dlib, only that it's a little harder to accidentally trigger 42 // (dlopen feature enabled, client and server features disabled) 43 #[allow(unused_imports)] 44 #[cfg(feature = "dlopen")] 45 #[macro_use] 46 extern crate lazy_static; 47 48 #[cfg(feature = "server")] 49 extern crate libc; 50 51 /// Magic static for wayland objects managed by wayland-client or wayland-server 52 /// 53 /// This static serves no purpose other than existing at a stable address. 54 /// 55 /// It is used internally by wayland-client, wayland-server and wayland-scanner to ensure safety 56 /// regarding wayland objects that are created by other libraries. 57 pub static RUST_MANAGED: u8 = 42; 58 59 pub mod common; 60 61 pub mod client; 62 63 pub mod server; 64 65 #[cfg(all(feature = "egl", feature = "client"))] 66 pub mod egl; 67 68 #[cfg(all(feature = "cursor", feature = "client"))] 69 pub mod cursor; 70 71 #[cfg(feature = "server")] 72 pub use libc::{gid_t, pid_t, uid_t}; 73 74 // Small hack while #[macro_reexport] is not stable 75 76 #[cfg(feature = "dlopen")] 77 #[macro_export] 78 macro_rules! ffi_dispatch( 79 ($handle: ident, $func: ident, $($arg: expr),*) => ( 80 ($handle.$func)($($arg),*) 81 ) 82 ); 83 84 #[cfg(not(feature = "dlopen"))] 85 #[macro_export] 86 macro_rules! ffi_dispatch( 87 ($handle: ident, $func: ident, $($arg: expr),*) => ( 88 $func($($arg),*) 89 ) 90 ); 91