Struct wayland_client::conn::Connection
source · pub struct Connection {
pub(crate) backend: Backend,
}
Expand description
The Wayland connection
This is the main type representing your connection to the Wayland server, though most of the interaction
with the protocol are actually done using other types. The two main uses a simple app has for the
Connection
are:
- Obtaining the initial
WlDisplay
through thedisplay()
method. - Creating new
EventQueue
s with thenew_event_queue()
method.
It can be created through the connect_to_env()
method to follow the
configuration from the environment (which is what you’ll do most of the time), or using the
from_socket()
method if you retrieved your connected Wayland socket through
other means.
In case you need to plug yourself into an external Wayland connection that you don’t control, you’ll
likely get access to it as a Backend
, in which case you can create a Connection
from it using
the from_backend()
method.
Fields§
§backend: Backend
Implementations§
source§impl Connection
impl Connection
sourcepub fn connect_to_env() -> Result<Self, ConnectError>
pub fn connect_to_env() -> Result<Self, ConnectError>
Try to connect to the Wayland server following the environment
This is the standard way to initialize a Wayland connection.
sourcepub fn from_socket(stream: UnixStream) -> Result<Self, ConnectError>
pub fn from_socket(stream: UnixStream) -> Result<Self, ConnectError>
Initialize a Wayland connection from an already existing Unix stream
sourcepub fn new_event_queue<State>(&self) -> EventQueue<State>
pub fn new_event_queue<State>(&self) -> EventQueue<State>
Create a new event queue
sourcepub fn from_backend(backend: Backend) -> Self
pub fn from_backend(backend: Backend) -> Self
Wrap an existing Backend
into a Connection
sourcepub fn backend(&self) -> Backend
pub fn backend(&self) -> Backend
Get the Backend
underlying this Connection
sourcepub fn flush(&self) -> Result<(), WaylandError>
pub fn flush(&self) -> Result<(), WaylandError>
Flush pending outgoing events to the server
This needs to be done regularly to ensure the server receives all your requests, though several dispatching methods do it implicitly (this is stated in their documentation when they do).
sourcepub fn prepare_read(&self) -> Option<ReadEventsGuard>
pub fn prepare_read(&self) -> Option<ReadEventsGuard>
Start a synchronized read from the socket
This is needed if you plan to wait on readiness of the Wayland socket using an event loop. See
ReadEventsGuard
for details. Once the events are received, you’ll then need to dispatch them from
their event queues using EventQueue::dispatch_pending()
.
If you don’t need to manage multiple event sources, see
EventQueue::blocking_dispatch()
for a simpler mechanism.
sourcepub fn roundtrip(&self) -> Result<usize, WaylandError>
pub fn roundtrip(&self) -> Result<usize, WaylandError>
Do a roundtrip to the server
This method will block until the Wayland server has processed and answered all your preceding requests. This is notably useful during the initial setup of an app, to wait for the initial state from the server.
See EventQueue::roundtrip()
for a version that includes the dispatching of the event queue.
sourcepub fn protocol_error(&self) -> Option<ProtocolError>
pub fn protocol_error(&self) -> Option<ProtocolError>
Retrieve the protocol error that occured on the connection if any
If this method returns Some
, it means your Wayland connection is already dead.
sourcepub fn send_request<I: Proxy>(
&self,
proxy: &I,
request: I::Request<'_>,
data: Option<Arc<dyn ObjectData>>,
) -> Result<ObjectId, InvalidId>
pub fn send_request<I: Proxy>( &self, proxy: &I, request: I::Request<'_>, data: Option<Arc<dyn ObjectData>>, ) -> Result<ObjectId, InvalidId>
Send a request associated with the provided object
This is a low-level interface used by the code generated by wayland-scanner
, you will likely
instead use the methods of the types representing each interface, or the Proxy::send_request()
and
Proxy::send_constructor()
.
sourcepub fn object_info(&self, id: ObjectId) -> Result<ObjectInfo, InvalidId>
pub fn object_info(&self, id: ObjectId) -> Result<ObjectInfo, InvalidId>
Get the protocol information related to given object ID
sourcepub fn get_object_data(
&self,
id: ObjectId,
) -> Result<Arc<dyn ObjectData>, InvalidId>
pub fn get_object_data( &self, id: ObjectId, ) -> Result<Arc<dyn ObjectData>, InvalidId>
Get the object data for a given object ID
This is a low-level interface used by the code generated by wayland-scanner
, a higher-level
interface for manipulating the user-data assocated to Dispatch
implementations
is given as Proxy::data()
. Also see Proxy::object_data()
.
Trait Implementations§
source§impl AsFd for Connection
impl AsFd for Connection
source§fn as_fd(&self) -> BorrowedFd<'_>
fn as_fd(&self) -> BorrowedFd<'_>
Provides fd from Backend::poll_fd()
for polling.
source§impl Clone for Connection
impl Clone for Connection
source§fn clone(&self) -> Connection
fn clone(&self) -> Connection
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for Connection
impl Debug for Connection
source§impl PartialEq for Connection
impl PartialEq for Connection
source§fn eq(&self, other: &Connection) -> bool
fn eq(&self, other: &Connection) -> bool
self
and other
values to be equal, and is used
by ==
.impl Eq for Connection
impl StructuralPartialEq for Connection
Auto Trait Implementations§
impl Freeze for Connection
impl RefUnwindSafe for Connection
impl Send for Connection
impl Sync for Connection
impl Unpin for Connection
impl UnwindSafe for Connection
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.