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
instantiated), 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 instantiated or not. It is perfectly safe
to instantiate again a global that have already been instantiated.
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 instantiated 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_token = EnvHandler::<WaylandEnv>::init(&mut event_queue, ®istry); // 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(&env_token); // 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 + 'static> EnvHandler<H>
[src]
fn init(
evqh: &mut EventQueueHandle,
registry: &WlRegistry
) -> StateToken<EnvHandler<H>>
[src]
evqh: &mut EventQueueHandle,
registry: &WlRegistry
) -> StateToken<EnvHandler<H>>
Insert a new EnvHandler in this event queue and register the registry to it
fn init_with_notify<ID: 'static>(
evqh: &mut EventQueueHandle,
registry: &WlRegistry,
notify: EnvNotify<ID>,
idata: ID
) -> StateToken<EnvHandler<H>>
[src]
evqh: &mut EventQueueHandle,
registry: &WlRegistry,
notify: EnvNotify<ID>,
idata: ID
) -> StateToken<EnvHandler<H>>
Insert a new EnvHandler in this event queue with a notify implementation
Does the same as EnvHandler::init(..)
, but you additionnaly supply an implementation
struct that the EnvHandler will use to notify you of events:
- events of creation/deletion of a global are forwarded
- event of readiness of this EnvHandler (when all the necessary globals could be bound)
fn ready(&self) -> bool
[src]
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)]
[src]
List of advertised globals
Returns a list of all globals that have been advertised by the server.
The type format of each tuple is: (global_id, interface_name, global_version)
.
fn clone_inner(&self) -> Option<H>
[src]
Retrieve an owned copy of the environment
This clones the inner env so that you can have access to the clobals without borrowing the event queue