wayland_server::backend

Struct Handle

source
pub struct Handle { /* private fields */ }
Expand description

Main handle of a backend to the Wayland protocol

This type hosts most of the protocol-related functionality of the backend, and is the main entry point for manipulating Wayland objects. It can be retrieved from the backend via Backend::handle() and cloned, and is given to you as argument in many callbacks.

Implementations§

source§

impl Handle

source

pub fn downgrade(&self) -> WeakHandle

Get a WeakHandle from this handle

source

pub fn object_info(&self, id: ObjectId) -> Result<ObjectInfo, InvalidId>

Get the detailed protocol information about a wayland object

Returns an error if the provided object ID is no longer valid.

source

pub fn insert_client( &mut self, stream: UnixStream, data: Arc<dyn ClientData>, ) -> Result<ClientId, Error>

Initializes a connection with a client.

The data parameter contains data that will be associated with the client.

source

pub fn get_client(&self, id: ObjectId) -> Result<ClientId, InvalidId>

Returns the id of the client which owns the object.

source

pub fn get_client_data( &self, id: ClientId, ) -> Result<Arc<dyn ClientData>, InvalidId>

Returns the data associated with a client.

source

pub fn get_client_credentials( &self, id: ClientId, ) -> Result<Credentials, InvalidId>

Retrive the Credentials of a client

source

pub fn with_all_clients(&self, f: impl FnMut(ClientId))

Invokes a closure for all clients connected to this server

Note that while this method is running, an internal lock of the backend is held, as a result invoking other methods of the Handle within the closure will deadlock. You should thus store the relevant ClientId in a container of your choice and process them after this method has returned.

source

pub fn with_all_objects_for( &self, client_id: ClientId, f: impl FnMut(ObjectId), ) -> Result<(), InvalidId>

Invokes a closure for all objects owned by a client.

Note that while this method is running, an internal lock of the backend is held, as a result invoking other methods of the Handle within the closure will deadlock. You should thus store the relevant ObjectId in a container of your choice and process them after this method has returned.

source

pub fn object_for_protocol_id( &self, client_id: ClientId, interface: &'static Interface, protocol_id: u32, ) -> Result<ObjectId, InvalidId>

Retrieve the ObjectId for a wayland object given its protocol numerical ID

source

pub fn create_object<D>( &self, client_id: ClientId, interface: &'static Interface, version: u32, data: Arc<dyn ObjectData<D>>, ) -> Result<ObjectId, InvalidId>
where D: 'static,

Create a new object for given client

To ensure state coherence of the protocol, the created object should be immediately sent as a “New ID” argument in an event to the client.

§Panics

This method will panic if the type parameter D is not same to the same type as the one the backend was initialized with.

source

pub fn send_event(&self, msg: Message<ObjectId, i32>) -> Result<(), InvalidId>

Send an event to the client

Returns an error if the sender ID of the provided message is no longer valid.

§Panics

Checks against the protocol specification are done, and this method will panic if they do not pass:

  • the message opcode must be valid for the sender interface
  • the argument list must match the prototype for the message associated with this opcode
source

pub fn get_object_data<D>( &self, id: ObjectId, ) -> Result<Arc<dyn ObjectData<D>>, InvalidId>
where D: 'static,

Returns the data associated with an object.

Panic: This method will panic if the type parameter D is not same to the same type as the one the backend was initialized with.

source

pub fn get_object_data_any( &self, id: ObjectId, ) -> Result<Arc<dyn Any + Sync + Send>, InvalidId>

Returns the data associated with an object as a dyn Any

source

pub fn set_object_data<D>( &self, id: ObjectId, data: Arc<dyn ObjectData<D>>, ) -> Result<(), InvalidId>
where D: 'static,

Sets the data associated with some object.

Panic: This method will panic if the type parameter D is not same to the same type as the one the backend was initialized with.

source

pub fn post_error(&self, object_id: ObjectId, error_code: u32, message: CString)

Posts a protocol error on an object. This will also disconnect the client which created the object.

source

pub fn kill_client(&self, client_id: ClientId, reason: DisconnectReason)

Kills the connection to a client.

The disconnection reason determines the error message that is sent to the client (if any).

source

pub fn create_global<D>( &self, interface: &'static Interface, version: u32, handler: Arc<dyn GlobalHandler<D>>, ) -> GlobalId
where D: 'static,

Creates a global of the specified interface and version and then advertises it to clients.

The clients which the global is advertised to is determined by the implementation of the GlobalHandler.

Panic: This method will panic if the type parameter D is not same to the same type as the one the backend was initialized with.

source

pub fn disable_global<D>(&self, id: GlobalId)
where D: 'static,

Disables a global object that is currently active.

The global removal will be signaled to all currently connected clients. New clients will not know of the global, but the associated state and callbacks will not be freed. As such, clients that still try to bind the global afterwards (because they have not yet realized it was removed) will succeed.

Invoking this method on an already disabled or removed global does nothing. It is not possible to re-enable a disabled global, this method is meant to be invoked some time before actually removing the global, to avoid killing clients because of a race.

Panic: This method will panic if the type parameter D is not same to the same type as the one the backend was initialized with.

source

pub fn remove_global<D>(&self, id: GlobalId)
where D: 'static,

Removes a global object and free its ressources.

The global object will no longer be considered valid by the server, clients trying to bind it will be killed, and the global ID is freed for re-use.

It is advised to first disable a global and wait some amount of time before removing it, to ensure all clients are correctly aware of its removal. Note that clients will generally not expect globals that represent a capability of the server to be removed, as opposed to globals representing peripherals (like wl_output or wl_seat).

This methods does nothing if the provided GlobalId corresponds to an already removed global.

Panic: This method will panic if the type parameter D is not same to the same type as the one the backend was initialized with.

source

pub fn global_info(&self, id: GlobalId) -> Result<GlobalInfo, InvalidId>

Returns information about a global.

source

pub fn get_global_handler<D>( &self, id: GlobalId, ) -> Result<Arc<dyn GlobalHandler<D>>, InvalidId>
where D: 'static,

Returns the handler which manages the visibility and notifies when a client has bound the global.

source

pub fn flush(&mut self, client: Option<ClientId>) -> Result<(), Error>

Flushes pending events destined for a client.

If no client is specified, all pending events are flushed to all clients.

Trait Implementations§

source§

impl Clone for Handle

source§

fn clone(&self) -> Handle

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Handle

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl From<Handle> for DisplayHandle

source§

fn from(handle: Handle) -> Self

Creates a DisplayHandle using a Handle from wayland-backend.

Auto Trait Implementations§

§

impl Freeze for Handle

§

impl RefUnwindSafe for Handle

§

impl Send for Handle

§

impl Sync for Handle

§

impl Unpin for Handle

§

impl UnwindSafe for Handle

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> Downcast for T
where T: Any,

source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.