Documentation Index
Fetch the complete documentation index at: https://mintlify.com/smithay/wayland-rs/llms.txt
Use this file to discover all available pages before exploring further.
wayland-sys provides raw, unsafe FFI bindings to the system Wayland shared libraries: libwayland-client, libwayland-server, libwayland-cursor, and libwayland-egl. It is a foundational crate used internally by wayland-backend, wayland-cursor, and wayland-egl — but almost all application and library authors should use those higher-level crates instead of wayland-sys directly.
Version covered by this reference: 0.31.11. Full API documentation is available at docs.rs/wayland-sys.
Installation and features
wayland-sys consists entirely of FFI bindings, you must enable the features corresponding to the libraries you want to bind:
| Feature | System library | Description |
|---|---|---|
client | libwayland-client.so | Raw bindings to the client-side Wayland library. Required by cursor and egl. |
server | libwayland-server.so | Raw bindings to the server-side Wayland library. |
cursor | libwayland-cursor.so | Raw bindings to cursor theme loading. Implies client. |
egl | libwayland-egl.so | Raw bindings to EGL window creation. Implies client. |
dlopen | (runtime) | Load libraries at runtime with dlopen instead of link-time. Allows graceful fallback when a library is absent. |
libwayland_client_1_23 | — | Enable symbols present only in libwayland-client ≥ 1.23. |
libwayland_server_1_22 | — | Enable symbols present only in libwayland-server ≥ 1.22. |
libwayland_server_1_23 | — | Enable symbols present only in libwayland-server ≥ 1.23. Implies libwayland_server_1_22. |
Module structure
Each feature maps to a module containing all associated FFI types and function bindings:| Module | Feature | Contents |
|---|---|---|
wayland_sys::common | (always available) | Core types shared by client and server: wl_interface, wl_message, wl_array, wl_argument, wl_fixed_t. |
wayland_sys::client | client | wl_display_*, wl_proxy_*, and all client-side C functions and types. |
wayland_sys::server | server | wl_display_*, wl_resource_*, wl_global_*, and all server-side C functions and types. |
wayland_sys::cursor | cursor + client | wl_cursor_theme_*, wl_cursor_*, wl_cursor_image. |
wayland_sys::egl | egl + client | wl_egl_window_* and the wl_egl_window type. |
The ffi_dispatch! macro
All FFI calls must go through the ffi_dispatch! macro, which abstracts over the two linking modes (link-time vs. dlopen):
- With
dlopenfeature:($handle.$func)($($arg),*)— calls through a handle struct loaded at runtime. - Without
dlopenfeature:$func($($arg),*)— calls the linked C function directly.
use wayland_sys::client::*) to bring all required symbols and the handle into scope.
The dlopen feature: runtime library loading
Without dlopen, wayland-sys links against the Wayland libraries at build time. The binary will fail to start if the libraries are not installed.
With dlopen, the libraries are loaded the first time a handle is accessed. Each module exposes an is_lib_available() function that returns true if the library was loaded successfully:
What wayland-sys provides
wayland-sys exposes the C ABI as closely as possible, including:
- Type definitions —
wl_display,wl_proxy,wl_resource,wl_interface,wl_message,wl_array,wl_fixed_t,wl_argument,wl_egl_window, and more. - C function bindings — every public function from the targeted Wayland headers (e.g.
wl_display_connect,wl_proxy_marshal_flags,wl_resource_post_error). - Constants — protocol error codes and other
#definevalues fromwayland-client.handwayland-server.h.
unsafe and require the caller to uphold C API contracts (valid pointers, correct object lifetimes, single-threaded access per the libwayland threading model).
When to use wayland-sys directly
- Use wayland-sys when…
- Use wayland-backend instead when…
- You are writing a new backend for
wayland-backendor a similar low-level crate. - You need to interoperate with an existing C library that takes
wl_display*orwl_proxy*pointers. - You are implementing deep FFI bridging between Rust and a C compositor or toolkit.
- You need access to symbols not yet exposed by the higher-level crates.
Build requirements
wayland-sys uses pkg-config to locate the system Wayland development headers and libraries:
| Library feature | Required pkg-config package |
|---|---|
client | wayland-client |
server | wayland-server |
cursor | wayland-cursor |
egl | wayland-egl |
When the
dlopen feature is enabled, pkg-config is still used at build time to verify the headers exist, but the .so files are not linked into the binary — they are loaded at runtime. The development headers are still required to compile the crate.Raw usage example
The following example demonstrates the low-level pattern for connecting to a Wayland display usingwayland-sys directly. In practice, use wayland-client instead.