wayland_backend::rs::client

Struct Backend

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

A Wayland client backend

This type hosts all the interface for interacting with the wayland protocol. It can be cloned, all clones refer to the same underlying connection.

Implementations§

source§

impl Backend

source

pub fn connect(stream: UnixStream) -> Result<Self, NoWaylandLib>

Try to initialize a Wayland backend on the provided unix stream

The provided stream should correspond to an already established unix connection with the Wayland server.

This method can only fail on the sys backend if the dlopen cargo feature was enabled and the system wayland library could not be found.

source

pub fn downgrade(&self) -> WeakBackend

Get a WeakBackend from this backend

source

pub fn flush(&self) -> Result<(), WaylandError>

Flush all pending outgoing requests to the server

Most errors on this method mean that the Wayland connection is no longer valid, the only exception being an IO WouldBlock error. In that case it means that you should try flushing again later.

You can however expect this method returning WouldBlock to be very rare: it can only occur if either your client sent a lot of big messages at once, or the server is very laggy.

source

pub fn poll_fd(&self) -> BorrowedFd<'_>

Access the Wayland socket FD for polling

source

pub fn display_id(&self) -> ObjectId

Get the object ID for the wl_display

source

pub fn last_error(&self) -> Option<WaylandError>

Get the last error that occurred on this backend

If this returns Some, your Wayland connection is already dead.

source

pub fn 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 send_request( &self, msg: Message<ObjectId, RawFd>, data: Option<Arc<dyn ObjectData>>, child_spec: Option<(&'static Interface, u32)>, ) -> Result<ObjectId, InvalidId>

Sends a request to the server

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

Panic:

Several 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
  • if the method creates a new object, a ObjectId::null() must be given in the argument list at the appropriate place, and a child_spec (interface and version) can be provided. If one is provided, it’ll be checked against the protocol spec. If the protocol specification does not define the interface of the created object (notable example is wl_registry.bind), the child_spec must be provided.
source

pub fn get_data(&self, id: ObjectId) -> Result<Arc<dyn ObjectData>, InvalidId>

Access the object data associated with a given object ID

Returns an error if the object ID is not longer valid or if it corresponds to a Wayland object that is not managed by this backend (when multiple libraries share the same Wayland socket via libwayland if using the system backend).

source

pub fn set_data( &self, id: ObjectId, data: Arc<dyn ObjectData>, ) -> Result<(), InvalidId>

Set the object data associated with a given object ID

Returns an error if the object ID is not longer valid or if it corresponds to a Wayland object that is not managed by this backend (when multiple libraries share the same Wayland socket via libwayland if using the system backend).

source

pub fn prepare_read(&self) -> Option<ReadEventsGuard>

Create a new reading guard

This is the first step for actually reading events from the Wayland socket. See ReadEventsGuard for how to use it.

This call will not block, but may return None if the inner queue of the backend needs to be dispatched. In which case you should invoke dispatch_inner_queue().

source

pub fn dispatch_inner_queue(&self) -> Result<usize, WaylandError>

Dispatches the inner queue of this backend if necessary

This function actually only does something when using the system backend. It dispaches an inner queue that the backend uses to wrap libwayland. While this dispatching is generally done in ReadEventsGuard::read(), if multiple threads are interacting with the Wayland socket it can happen that this queue was filled by another thread. In that case prepare_read() will return None, and you should invoke this function instead of using the ReadEventsGuard

Returns the number of messages that were dispatched to their ObjectData callbacks.

Trait Implementations§

source§

impl Clone for Backend

source§

fn clone(&self) -> Backend

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 Backend

source§

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

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

impl PartialEq for Backend

source§

fn eq(&self, other: &Backend) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Backend

source§

impl StructuralPartialEq for Backend

Auto Trait Implementations§

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.