Available on crate feature
backend_x11 only.Expand description
Implementation of the backend types using X11.
This backend provides the appropriate backend implementations to run a Wayland compositor as an X11 client.
The backend is initialized using X11Backend::new.
§Example usage
use smithay::backend::allocator::dmabuf::DmabufAllocator;
use smithay::backend::allocator::gbm::{GbmAllocator, GbmDevice, GbmBufferFlags};
use smithay::backend::egl::{EGLDisplay, EGLContext};
use smithay::utils::DeviceFd;
use std::collections::HashSet;
fn init_x11_backend(
handle: calloop::LoopHandle<CompositorState>,
) -> Result<(), Box<dyn Error>> {
// Create the backend
let backend = X11Backend::new()?;
// Get a handle from the backend to interface with the X server
let x_handle = backend.handle();
// Create a window
let window = WindowBuilder::new()
.title("Wayland inside X11")
.build(&x_handle)
.expect("Could not create window");
// To render to a window, we need to create an X11 surface.
// Get the DRM node used by the X server for direct rendering.
let (_drm_node, fd) = x_handle.drm_node()?;
// Create the gbm device for allocating buffers
let device = GbmDevice::new(DeviceFd::from(fd))?;
// Initialize EGL to retrieve the support modifier list
let egl = unsafe { EGLDisplay::new(device.clone()).expect("Failed to create EGLDisplay") };
let context = EGLContext::new(&egl).expect("Failed to create EGLContext");
let modifiers = context.dmabuf_render_formats().iter().map(|format| format.modifier).collect::<HashSet<_>>();
// Finally create the X11 surface, you will use this to obtain buffers that will be presented to the
// window.
let surface = x_handle.create_surface(&window, DmabufAllocator(GbmAllocator::new(device, GbmBufferFlags::RENDERING)), modifiers.into_iter());
// Insert the backend into the event loop to receive events.
handle.insert_source(backend, |event, _window, state| {
// Process events from the X server that apply to the window.
})?;
Ok(())
}§EGL
When using EGL, an X11Surface may be used to create an EGLDisplay.
Structs§
- Window
- An X11 window.
- Window
Builder - Builder used to construct a window.
- X11Backend
- Represents an active connection to the X to manage events on the Window provided by the backend.
- X11Handle
- A handle to the X11 backend.
- X11Input
- Marker used to define the
InputBackendtypes for the X11 backend. - X11Keyboard
Input Event - X11-Backend internal event wrapping
X11’s types into aKeyboardKeyEvent. - X11Mouse
Input Event - X11-Backend internal event wrapping
X11’s types into aPointerButtonEvent - X11Mouse
Moved Event - X11-Backend internal event wrapping
X11’s types into aPointerMotionAbsoluteEvent - X11Mouse
Wheel Event - X11-Backend internal event wrapping
X11’s types into aPointerAxisEvent - X11Surface
- An X11 surface which uses GBM to allocate and present buffers.
- X11Virtual
Device - Virtual input device used by the backend to associate input events.
Enums§
- Allocate
Buffers Error - An error which may occur when allocating buffers for presentation to the window.
- Create
Window Error - An error which may occur when creating an X11 window.
- Missing
Extension Error - An error that occurs when a required X11 extension is not present.
- Present
Error - An error that may occur when presenting.
- X11Error
- An error emitted by the X11 backend during setup.
- X11Event
- An event emitted by the X11 backend.