pub trait Client: Sized + 'static {
type ServerContext: Server<ClientContext = Self> + 'static;
type ObjectStore: Store<Self::Object>;
type Connection: WriteMessage + Unpin + 'static;
type Object: Object<Self> + AnyObject + Debug;
type EventDispatcher: EventDispatcher<Self> + 'static;
type DispatchFut<'a, R>: Future<Output = bool> + 'a
where Self: 'a,
R: AsyncBufReadWithFd + 'a;
// Required methods
fn server_context(&self) -> &Self::ServerContext;
fn objects(&self) -> &Self::ObjectStore;
fn as_mut_parts(&mut self) -> ClientParts<'_, Self>;
fn dispatch<'a, R>(
&'a mut self,
reader: Pin<&'a mut R>
) -> Self::DispatchFut<'a, R>
where R: AsyncBufReadWithFd;
// Provided methods
fn connection_mut(&mut self) -> &mut Self::Connection { ... }
fn objects_mut(&mut self) -> &mut Self::ObjectStore { ... }
fn event_dispatcher_mut(&mut self) -> &mut Self::EventDispatcher { ... }
}
Expand description
A per-client context
A connection with a wayland client has a set of states associated with it.
Most prominently, is the set of objects that are bound to the client. This
is represented by the ObjectStore
associated type.
For these objects to implement the wayland protocol, some of them would need
to access a server global context. For example, input devices, like the
mouse and keyboard; output devices, like a monitor, etc. These are stored in
the ServerContext
associated type.
Some objects might also define events to be sent to the client. For that, we
need a connection to the client for sending data. That is represented by the
Connection
associated type.
Those events are not always triggered in response to a client request. For
example, the wl_pointer.motion
event is sent when the user moves the
mouse. The mouse is a server global resource, so there needs to be a
mechanism to notify the per-client context from the global context.
The notification mechanism is documented better in
events
. Once notified, the object implementations need to
schedule work in response to the notification, that is
supported by the EventDispatcher
associated type.
Required Associated Types§
sourcetype ServerContext: Server<ClientContext = Self> + 'static
type ServerContext: Server<ClientContext = Self> + 'static
Server/compositor global context
sourcetype ObjectStore: Store<Self::Object>
type ObjectStore: Store<Self::Object>
The object store
sourcetype Connection: WriteMessage + Unpin + 'static
type Connection: WriteMessage + Unpin + 'static
The connection to the client
sourcetype Object: Object<Self> + AnyObject + Debug
type Object: Object<Self> + AnyObject + Debug
The object type. This is typically an enum
of all the object types
used by your compositor, with a #[derive(Object)]
to implement the
required Object
trait.
sourcetype EventDispatcher: EventDispatcher<Self> + 'static
type EventDispatcher: EventDispatcher<Self> + 'static
The event dispatcher. Object implementations can register event handler
with the event dispatcher. See the trait and events
for a more detailed explanation.
sourcetype DispatchFut<'a, R>: Future<Output = bool> + 'a
where
Self: 'a,
R: AsyncBufReadWithFd + 'a
type DispatchFut<'a, R>: Future<Output = bool> + 'a where Self: 'a, R: AsyncBufReadWithFd + 'a
Future returned by the dispatch
method
Required Methods§
sourcefn server_context(&self) -> &Self::ServerContext
fn server_context(&self) -> &Self::ServerContext
Return a shared reference to the server context.
sourcefn objects(&self) -> &Self::ObjectStore
fn objects(&self) -> &Self::ObjectStore
Return a shared references to the object store
sourcefn as_mut_parts(&mut self) -> ClientParts<'_, Self>
fn as_mut_parts(&mut self) -> ClientParts<'_, Self>
Get unique access to all members of the client context. This is for accessing all members of the client context at the same time. Otherwise accessing one of these members will exclusively borrow the whole client context, preventing access to the other members.
sourcefn dispatch<'a, R>(
&'a mut self,
reader: Pin<&'a mut R>
) -> Self::DispatchFut<'a, R>where
R: AsyncBufReadWithFd,
fn dispatch<'a, R>( &'a mut self, reader: Pin<&'a mut R> ) -> Self::DispatchFut<'a, R>where R: AsyncBufReadWithFd,
Read a message from reader
, deserialize it then dispatch it to the
appropriate object in the object store. The return future should resolve
to a boolean which, if true, should cause the client to be
disconnected. Typically indicates the client has made a protocol error.
A default implementations is provided at super::dispatch_to
.
Provided Methods§
sourcefn connection_mut(&mut self) -> &mut Self::Connection
fn connection_mut(&mut self) -> &mut Self::Connection
Return a unique reference to the connection object
sourcefn objects_mut(&mut self) -> &mut Self::ObjectStore
fn objects_mut(&mut self) -> &mut Self::ObjectStore
Return a unique reference to the object store
sourcefn event_dispatcher_mut(&mut self) -> &mut Self::EventDispatcher
fn event_dispatcher_mut(&mut self) -> &mut Self::EventDispatcher
Return a unique reference to the event dispatcher