Struct wayland_client::EnvHandler [] [src]

pub struct EnvHandler<H: EnvHandlerInner> { /* fields omitted */ }

Utility type to handle the registry and global objects

This struct provides you with a generic handler for the wl_registry and the instanciation of global objects.

To use it, you need to declare your globals of interest using the wayland_env!(..) macro. Then, insert this handler in your event loop and register your registry to it.

Once this handler is fully initialized (and all globals have been instanciated), it makes them usable via deref-ing towards the struct previously declared by the wayland_env!(...) macro.

The globals() method also give you a list of all globals declared by the server, had them been instanciated or not. It is perfectly safe to instanciate again a global that have already been instanciated.

This list is updated whenever the server declares or removes a global object, (as long as you don't change the handler associated to your registry).

If you want to manage all you globals manually, but still want to use this utility to maintain the list of evailable globals, you can simply create an empty env type using the macro, like this : wayland_env!(WaylandEnv). No global will be automatically instanciated for you, but you still can use this globals() method.

example of use

// Declare your globals of interest using the macro.
// This creates a struct named WaylandEnv (but you can change it).
wayland_env!(WaylandEnv, compositor: wl_compositor::WlCompositor);

let registry = display.get_registry();
let env_id = eventqueue.add_handler(EnvHandler::<WaylandEnv>::new());
eventqueue.register::<_, EnvHandler<WaylandEnv>>(&registry, env_id);
// a roundtrip sync will dispatch all event declaring globals to the handler
eventqueue.sync_roundtrip().unwrap();
// then, we can access them via the state of the event queue:
let state = eventqueue.state();
let env = state.get_handler::<EnvHandler<WaylandEnv>>(env_id);
// We can now access the globals as fields of env.
// Note that is some globals were missing, this acces (via Deref)
// will panic!
let compositor = env.compositor;

Methods

impl<H: EnvHandlerInner> EnvHandler<H>
[src]

Create a new EnvHandler

This handler will need to be given to an event queue and a WlRegistry be registered to it.

Is the handler ready

Returns true if all required globals have been created.

If this method returns false, trying to access a global field will panic.

List of advertized globals

Returns a list of all globals that have been advertized by the server.

The type format of each tuple is: (global_id, interface_name, global_version).

Trait Implementations

impl<H: EnvHandlerInner> Deref for EnvHandler<H>
[src]

The resulting type after dereferencing

The method called to dereference a value

impl<H: EnvHandlerInner> Handler for EnvHandler<H>
[src]

announce global object Read more

announce removal of global object Read more

impl<H: EnvHandlerInner> Handler<WlRegistry> for EnvHandler<H>
[src]

Dispatch a message.