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§

source

type ServerContext: Server<ClientContext = Self> + 'static

Server/compositor global context

source

type ObjectStore: Store<Self::Object>

The object store

source

type Connection: WriteMessage + Unpin + 'static

The connection to the client

source

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.

source

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.

source

type DispatchFut<'a, R>: Future<Output = bool> + 'a where Self: 'a, R: AsyncBufReadWithFd + 'a

Future returned by the dispatch method

Required Methods§

source

fn server_context(&self) -> &Self::ServerContext

Return a shared reference to the server context.

source

fn objects(&self) -> &Self::ObjectStore

Return a shared references to the object store

source

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.

source

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§

source

fn connection_mut(&mut self) -> &mut Self::Connection

Return a unique reference to the connection object

source

fn objects_mut(&mut self) -> &mut Self::ObjectStore

Return a unique reference to the object store

source

fn event_dispatcher_mut(&mut self) -> &mut Self::EventDispatcher

Return a unique reference to the event dispatcher

Implementors§