Skip to main content

Module globals

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 GlobalList::init function. Given a reference to your Connection and a QueueHandle, 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::{Global, GlobalList, GlobalListHandler},
    protocol::{wl_registry, wl_compositor},
};

// You need to provide a GlobalListHandler impl for your app
impl GlobalListHandler for State {
    /* react to dynamic global events here */
}

let conn = unsafe { Connection::connect_to_env() }.unwrap();
let mut queue = conn.new_event_queue();
let globals = GlobalList::init(&conn, &queue.handle()).unwrap();

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

Structs§

Global
Description of a global.
GlobalList
A helper for global initialization.

Enums§

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

Traits§

GlobalListHandler
Handler for runtime global addition/removal in GlobalList created with GlobalList::init