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>>(®istry, 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]
fn new() -> EnvHandler<H>
Create a new EnvHandler
This handler will need to be given to an event queue
and a WlRegistry
be registered to it.
fn ready(&self) -> bool
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.
fn globals(&self) -> &[(u32, String, u32)]
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]
type Target = H
The resulting type after dereferencing
fn deref(&self) -> &H
The method called to dereference a value
impl<H: EnvHandlerInner> Handler for EnvHandler<H>
[src]
fn global(&mut self,
_: &mut EventQueueHandle,
registry: &WlRegistry,
name: u32,
interface: String,
version: u32)
_: &mut EventQueueHandle,
registry: &WlRegistry,
name: u32,
interface: String,
version: u32)
announce global object Read more
fn global_remove(&mut self, _: &mut EventQueueHandle, _: &WlRegistry, name: u32)
announce removal of global object Read more
impl<H: EnvHandlerInner> Handler<WlRegistry> for EnvHandler<H>
[src]
unsafe fn message(&mut self,
evq: &mut EventQueueHandle,
proxy: &WlRegistry,
opcode: u32,
args: *const wl_argument)
-> Result<(), ()>
evq: &mut EventQueueHandle,
proxy: &WlRegistry,
opcode: u32,
args: *const wl_argument)
-> Result<(), ()>
Dispatch a message.