TheDocumentation 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 crate provides the thin bridge between a Wayland wl_surface and the EGL windowing system. OpenGL and Vulkan drivers do not understand Wayland surfaces directly — they need a wl_egl_window handle, a C struct allocated by libwayland-egl that the driver can use to present rendered frames. wayland-egl exposes this as [WlEglSurface]: a safe Rust type that creates and destroys the wl_egl_window, provides its raw pointer for passing to EGL initialization routines, and supports runtime resize operations.
Adding the dependency
Becausewayland-egl delegates object-ID tracking to wayland-backend with the client_system feature, you only need one line in Cargo.toml:
wayland-backend with client_system and wayland-sys with the egl feature are pulled in automatically as transitive dependencies.
The
dlopen feature on wayland-backend (and therefore wayland-sys) makes the system libraries load at runtime rather than being linked at compile time. You can combine this with wayland-egl if you want the EGL surface path to fail gracefully when libwayland-egl.so is absent — call wayland_egl::is_available() to check.Checking library availability
When thedlopen feature is active, the EGL library is loaded lazily. Call is_available() before creating any surface:
dlopen is not active, is_available() always returns true because the library is linked directly.
Creating a WlEglSurface
[WlEglSurface::new()] accepts an [ObjectId] obtained from a WlSurface, plus the initial pixel dimensions. It returns an error if the ObjectId does not correspond to a live wl_surface or if the dimensions are non-positive.
You must always destroy the
WlEglSurface before the underlying wl_surface protocol object is destroyed. Dropping WlEglSurface calls wl_egl_window_destroy automatically via its Drop implementation.Getting the raw pointer for EGL initialization
Most OpenGL/EGL binding crates (glutin, khronos-egl, raw EGL) need two pointers at context creation time:EGLDisplay— obtained from the rawwl_displaypointer viaBackend::display_ptr()EGLSurface/ native window — obtained fromWlEglSurface::ptr()
Resizing the surface
When the compositor sends awl_surface.configure event with new dimensions, call [WlEglSurface::resize()]. The last two arguments, dx and dy, shift the top-left corner of the surface and can be set to 0 in the common case.
WlEglSurface::get_size()]:
raw-window-handle integration
wayland-backend implements [HasDisplayHandle][rwh_06::HasDisplayHandle] for client::Backend when both the rwh_06 and client_system features are enabled on wayland-backend (not on wayland-egl). This lets you pass the display handle to crates such as wgpu or winit through the standard raw-window-handle API.
To obtain a RawWindowHandle for the surface side you construct a WaylandWindowHandle from the wl_egl_window pointer. Add wayland-backend with rwh_06 explicitly:
Combining with raw EGL calls
- Raw EGL (khronos-egl)
- glutin
Thread safety
WlEglSurface implements Send — it can be moved to another thread after creation, which is useful when rendering on a dedicated thread. It is not Sync because the underlying wl_egl_window* pointer performs no internal synchronization. Do not share a reference to WlEglSurface across threads concurrently.
Error handling
[WlEglSurface::new()] returns a Result<WlEglSurface, wayland_egl::Error>:
| Variant | Cause |
|---|---|
Error::InvalidId | The ObjectId is not a live wl_surface |
Error::InvalidSize | width or height is ≤ 0 |
API summary
| Method | Description |
|---|---|
is_available() | Check whether libwayland-egl.so could be loaded |
WlEglSurface::new(id, width, height) | Create an EGL window from a wl_surface ObjectId |
WlEglSurface::ptr() | Raw *const c_void for eglCreateWindowSurface |
WlEglSurface::resize(w, h, dx, dy) | Update the surface dimensions |
WlEglSurface::get_size() | Query the current (width, height) |
Backend::display_ptr() | Raw *mut wl_display for eglGetDisplay (system backend only) |