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-egl provides a safe Rust wrapper around libwayland-egl’s wl_egl_window type. A WlEglSurface is the bridge between a Wayland wl_surface and an EGL or Vulkan rendering context. Once created, you pass its raw pointer to your graphics library (e.g. eglCreateWindowSurface) to obtain a renderable surface.
Version covered by this reference: 0.32.11. Full API documentation is available at docs.rs/wayland-egl.
Installation
wayland-egl requires libwayland-egl.so to be present on the target system and delegates to wayland-backend with the client_system feature for obtaining raw wl_proxy pointers. Both dependencies are pulled in automatically.
wayland-egl depends on wayland-backend with client_system, your project will link against libwayland-client.so and libwayland-egl.so at build time (unless dlopen is also enabled in wayland-backend).
Runtime availability check
Before creating any surface, verify thatlibwayland-egl.so is loadable:
WlEglSurface
WlEglSurface is a thin, safe wrapper around wl_egl_window. It is Send (can be moved to another thread) but not Sync (cannot be shared across threads without synchronization), matching the semantics of the underlying C type.
WlEglSurface implements Drop, which calls wl_egl_window_destroy automatically.
Constructor
| Parameter | Type | Description |
|---|---|---|
surface | ObjectId | The ObjectId of an active wl_surface. Must have interface name "wl_surface". |
width | i32 | Initial width of the EGL window in pixels. Must be > 0. |
height | i32 | Initial height of the EGL window in pixels. Must be > 0. |
Err(Error::InvalidId) if the ObjectId is expired or does not refer to a wl_surface, and Err(Error::InvalidSize) if either dimension is <= 0.
Advanced: raw pointer constructor
*mut wl_proxy. The caller must guarantee the pointer is a valid wl_surface from libwayland-client.
Methods
| Method | Return type | Description |
|---|---|---|
ptr() | *const c_void | The raw wl_egl_window* pointer cast to *const c_void. Pass this to eglCreateWindowSurface or vkCreateWaylandSurfaceKHR. |
resize(width, height, dx, dy) | () | Resize the EGL window. (dx, dy) is the displacement of the top-left corner, allowing directional control of resize operations (e.g. left-edge resize uses positive dx). |
get_size() | (i32, i32) | Fetch the currently attached size as (width, height). |
Error type
Error implements std::error::Error and Display.
How to use with EGL
Creating an EGL rendering surface for a Wayland client involves three layers:- Wayland surface — a
wl_surfaceprotocol object (managed bywayland-client). - EGL window — a
WlEglSurfacewrapping thatwl_surface(this crate). - EGL surface — created by your EGL library using the pointers from both.
eglGetDisplay using the wl_display* pointer (available via ObjectId::as_ptr() on the display ID in the system backend).
Complete usage example
The following example creates aWlEglSurface, hands it to a hypothetical EGL library for context setup, renders a frame, then resizes when the window changes dimensions.
WlEglSurface is Send — you can create it on one thread and move it to a render thread. It is not Sync, so simultaneous access from multiple threads requires external synchronization (e.g. a Mutex).