wayland-client 0.10.3

Bindings to the standard C implementation of the wayland protocol, client side.

Client-side Wayland connector


Connection to the Wayland compositor is achieved by the default_connect() function, which provides you with a WlDisplay and an EventQueue.

From the display, you'll retrieve the registry, from which you can instantiate the globals you need. This step being really similar in most cases, this crate contains an utility struct EnvHandler which can do this job for you. See its documentation for details.

You then register your handlers for events to the event queue, and integrate it in your main event loop.

Implementations and event queues

This crate mirrors the callback-oriented design of the Wayland C library by using implementation structs: each wayland type defines an Implementation struct in its module, with one function field for each possible event this object can receive.

When registering an object on an event queue, you need to provide an implementation for this object. You can also provide some "implementation data": a value that will be provided as second argument to all the callback methods of your implementation.

A typical use of implementation data is to store here one or more state tokens to access some part of the shared state from your callback.

Example of implementation

You can register your wayland objects to an event queue:

event_queue.register(&my_object, implementation, impl_data);

A given wayland object can only be registered to a event queue at a given time, re-registering it will overwrite the previous configuration.

Objects can be registered to event queues using the &EventQueueHandle argument, available from withing an event callback.

Event loop integration

Once this setup is done, you can integrate the event queue to the main event loop of your program:

loop {
    // flush events to the server
    // receive events from the server and dispatch them
    // to handlers (might block)

For more precise control of the flow of the event queue (and importantly non-blocking options), see EventQueue documentation.

Protocols integration

This crate provides the basic primitives as well as the core wayland protocol (in the protocol module), but other protocols can be integrated from XML descriptions.

The the crate wayland_scanner and its documentation for details about how to do so.