Struct wayland_client::backend::Backend
source · pub struct Backend {
pub(crate) backend: InnerBackend,
}
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.
Fields§
§backend: InnerBackend
Implementations§
source§impl Backend
impl Backend
sourcepub fn connect(stream: UnixStream) -> Result<Backend, NoWaylandLib>
pub fn connect(stream: UnixStream) -> Result<Backend, 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.
sourcepub fn downgrade(&self) -> WeakBackend
pub fn downgrade(&self) -> WeakBackend
Get a WeakBackend
from this backend
sourcepub fn flush(&self) -> Result<(), WaylandError>
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.
sourcepub fn poll_fd(&self) -> BorrowedFd<'_>
pub fn poll_fd(&self) -> BorrowedFd<'_>
Access the Wayland socket FD for polling
sourcepub fn display_id(&self) -> ObjectId
pub fn display_id(&self) -> ObjectId
Get the object ID for the wl_display
sourcepub fn last_error(&self) -> Option<WaylandError>
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.
sourcepub fn info(&self, id: ObjectId) -> Result<ObjectInfo, InvalidId>
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.
sourcepub fn send_request(
&self,
msg: Message<ObjectId, i32>,
data: Option<Arc<dyn ObjectData>>,
child_spec: Option<(&'static Interface, u32)>,
) -> Result<ObjectId, InvalidId>
pub fn send_request( &self, msg: Message<ObjectId, i32>, 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 achild_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 iswl_registry.bind
), thechild_spec
must be provided.
sourcepub fn get_data(&self, id: ObjectId) -> Result<Arc<dyn ObjectData>, InvalidId>
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).
sourcepub fn set_data(
&self,
id: ObjectId,
data: Arc<dyn ObjectData>,
) -> Result<(), InvalidId>
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).
sourcepub fn prepare_read(&self) -> Option<ReadEventsGuard>
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()
.
sourcepub fn dispatch_inner_queue(&self) -> Result<usize, WaylandError>
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.
source§impl Backend
impl Backend
sourcepub unsafe fn from_foreign_display(display: *mut wl_display) -> Backend
pub unsafe fn from_foreign_display(display: *mut wl_display) -> Backend
Creates a Backend from a foreign *mut wl_display
.
This is useful if you are writing a library that is expected to plug itself into an existing Wayland connection.
This will initialize the Backend
in “guest” mode, meaning it will not close the
connection on drop. After the Backend
is dropped, if the server sends an event
to an object that was created from it, that event will be silently discarded. This may lead to
protocol errors if the server expects an answer to that event, as such you should make sure to
cleanup your Wayland state before dropping the Backend
.
§Safety
You need to ensure the *mut wl_display
remains live as long as the Backend
(or its clones) exist.
sourcepub fn display_ptr(&self) -> *mut wl_display
pub fn display_ptr(&self) -> *mut wl_display
Returns the underlying wl_display
pointer to this backend.
This pointer is needed to interface with EGL, Vulkan and other C libraries.
This pointer is only valid for the lifetime of the backend.
sourcepub unsafe fn manage_object(
&self,
interface: &'static Interface,
proxy: *mut wl_proxy,
data: Arc<dyn ObjectData>,
) -> ObjectId
pub unsafe fn manage_object( &self, interface: &'static Interface, proxy: *mut wl_proxy, data: Arc<dyn ObjectData>, ) -> ObjectId
Take over handling for a proxy created by a third party.
§Safety
There must never be more than one party managing an object. This is only safe to call when a third party gave you ownership of an unmanaged proxy.
The caller is also responsible for making sure the passed interface matches the proxy.
Trait Implementations§
source§impl PartialEq for Backend
impl PartialEq for Backend
impl Eq for Backend
impl StructuralPartialEq for Backend
Auto Trait Implementations§
impl Freeze for Backend
impl RefUnwindSafe for Backend
impl Send for Backend
impl Sync for Backend
impl Unpin for Backend
impl UnwindSafe for Backend
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.