wayland_client

Module globals

source
Expand description

Helpers for handling the initialization of an app

At the startup of your Wayland app, the initial step is generally to retrieve the list of globals advertized by the compositor from the registry. Using the Dispatch mechanism for this task can be very unpractical, this is why this module provides a special helper for handling the registry.

The entry point of this helper is the registry_queue_init function. Given a reference to your Connection it will create an EventQueue, retrieve the initial list of globals, and register a handler using your provided Dispatch<WlRegistry,_> implementation for handling dynamic registry events.

§Example

use wayland_client::{
    Connection, Dispatch, QueueHandle,
    globals::{registry_queue_init, Global, GlobalListContents},
    protocol::{wl_registry, wl_compositor},
};

// You need to provide a Dispatch<WlRegistry, GlobalListContents> impl for your app
impl wayland_client::Dispatch<wl_registry::WlRegistry, GlobalListContents> for State {
    fn event(
        state: &mut State,
        proxy: &wl_registry::WlRegistry,
        event: wl_registry::Event,
        // This mutex contains an up-to-date list of the currently known globals
        // including the one that was just added or destroyed
        data: &GlobalListContents,
        conn: &Connection,
        qhandle: &QueueHandle<State>,
    ) {
        /* react to dynamic global events here */
    }
}

let conn = Connection::connect_to_env().unwrap();
let (globals, queue) = registry_queue_init::<State>(&conn).unwrap();

// now you can bind the globals you need for your app
let compositor: wl_compositor::WlCompositor = globals.bind(&queue.handle(), 4..=5, ()).unwrap();

Structs§

Enums§

  • An error that occurs when a binding a global fails.
  • An error that may occur when initializing the global list.

Functions§

  • Initialize a new event queue with its associated registry and retrieve the initial list of globals