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-scanner is a procedural macro crate that reads Wayland XML protocol specification files and generates the corresponding Rust types, trait implementations, and interface metadata. It is the standard code-generation tool for custom Wayland protocol extensions in the wayland-rs ecosystem, producing code that integrates directly with wayland-client, wayland-server, and wayland-backend.
Version covered by this reference: 0.31.10. Full API documentation is available at docs.rs/wayland-scanner.
Before writing a custom protocol integration, check whether wayland-protocols already exposes the extension you need. It covers many standard protocol extensions such as
xdg-shell, wlr-layer-shell, and more.Installation
wayland-scanner is a proc-macro crate and must be added as a regular dependency (not a [build-dependencies] entry). The proc-macros expand at compile time when invoked inside your source files.
The three proc-macros
generate_interfaces!(path)
Generates the low-level C-compatible interface structs (wl_interface, wl_message) for all protocol objects defined in the XML file. These structs are required by the *_system backends in wayland-backend for FFI interoperability with libwayland.
| Parameter | Type | Description |
|---|---|---|
path | string literal | Path to the Wayland XML file, relative to CARGO_MANIFEST_DIR. |
static items named after each interface in the XML (e.g. WL_MY_OBJECT_INTERFACE). This macro is intended to be called inside a module named __interfaces (see the module pattern below).
generate_client_code!(path)
Generates the complete client-side Rust API for all protocol objects in the XML file. This includes proxy types, request methods, event enums, and all trait implementations required by wayland-client.
| Parameter | Type | Description |
|---|---|---|
path | string literal | Path to the Wayland XML file, relative to CARGO_MANIFEST_DIR. |
Event enum describing the events it can receive.
generate_server_code!(path)
Generates the complete server-side Rust API for all protocol objects in the XML file. This includes resource types, event-sending methods, and request enums, for use with wayland-server.
| Parameter | Type | Description |
|---|---|---|
path | string literal | Path to the Wayland XML file, relative to CARGO_MANIFEST_DIR. |
Request enum describing the requests the server can receive from clients.
The __interfaces module pattern
The generate_interfaces! macro must be called in a submodule named __interfaces. The generated client or server code refers to this module by that exact name to access the low-level interface structs.
Complete client-side module template
The following template is the canonical way to expose a custom Wayland protocol client-side. The path to the XML file is always relative to the crate root (CARGO_MANIFEST_DIR).
my_object defined in the XML becomes accessible as my_protocol::my_object::MyObject (a proxy type), with request methods on the proxy and an Event enum for dispatch.
Complete server-side module template
The server-side pattern is identical — replaceclient with server and generate_client_code! with generate_server_code!.
Path resolution
All three macros resolve paths relative to theCARGO_MANIFEST_DIR environment variable, which Cargo sets to the directory containing the Cargo.toml of the crate being compiled. This means a path like "./protocols/my-extension.xml" resolves to <crate-root>/protocols/my-extension.xml.
Protocol XML format
The Wayland protocol XML format is defined by the Wayland project. Each file contains a<protocol> root element with one or more <interface> elements, each describing requests (client → server) and events (server → client).
Key XML elements:
| Element | Description |
|---|---|
<protocol name="..."> | Root element; the protocol name. |
<interface name="..." version="..."> | Defines one Wayland object type. |
<request name="..."> | A method the client may invoke on the object. |
<event name="..."> | A notification the server sends to the client. |
<arg name="..." type="..."> | An argument; types include int, uint, fixed, string, object, new_id, array, fd. |
<enum name="..."> | A named set of uint constants. |