Trait runa_core::client::traits::EventHandler
source · pub trait EventHandler<Ctx: Client>: 'static {
type Message;
type Future<'ctx>: Future<Output = Result<EventHandlerAction, Box<dyn Error + Send + Sync + 'static>>> + 'ctx;
// Required method
fn handle_event<'ctx>(
&'ctx mut self,
objects: &'ctx mut Ctx::ObjectStore,
connection: &'ctx mut Ctx::Connection,
server_context: &'ctx Ctx::ServerContext,
message: &'ctx mut Self::Message
) -> Self::Future<'ctx>;
}
Expand description
An event handler.
Occasionally, wayland object implementations need to handle events that arise from the compositor. For example, when user moves the pointer, the wl_surface objects maybe need to send motion events to the client.
This can be achieved by implement this trait, and call
Client::add_event_handler
to register event handlers. Event handlers
have an associated event source. Whenever a new event is received,
the event source will be polled, and the event handler will be
called with the received event.
Required Associated Types§
sourcetype Future<'ctx>: Future<Output = Result<EventHandlerAction, Box<dyn Error + Send + Sync + 'static>>> + 'ctx
type Future<'ctx>: Future<Output = Result<EventHandlerAction, Box<dyn Error + Send + Sync + 'static>>> + 'ctx
Type of future returned by handle_event
.
Required Methods§
sourcefn handle_event<'ctx>(
&'ctx mut self,
objects: &'ctx mut Ctx::ObjectStore,
connection: &'ctx mut Ctx::Connection,
server_context: &'ctx Ctx::ServerContext,
message: &'ctx mut Self::Message
) -> Self::Future<'ctx>
fn handle_event<'ctx>( &'ctx mut self, objects: &'ctx mut Ctx::ObjectStore, connection: &'ctx mut Ctx::Connection, server_context: &'ctx Ctx::ServerContext, message: &'ctx mut Self::Message ) -> Self::Future<'ctx>
Handle an event. Every time an event is received, this will be called, and the returned future will be driven to completion. The returned value indicates whether this event handler should be removed. Event handler is also removed if the event stream has terminated.
This function is not passed a &mut Ctx
, because handling events
requires exclusive access to the set of event handlers (i.e. the event
dispatcher). So we split a Ctx
apart, remove the access to the
event dispatcher, and only pass the remaining parts.
If an error is returned, the client connection should be closed with an error.