[−][src]Crate wayland_server
Server-side Wayland connector
Overview
This crate provides the interfaces and machinery to safely create servers
for the Wayland protocol. It can be used as either a rust implementatin of the protocol,
or as a wrapper around the system-wide libwayland-server.so
if you need interoperability
with other libraries. This last case is activated by the use_system_lib
cargo feature.
The Wayland protocol revolves around the creation of various objects and the exchange
of messages associated to these objects. Whenever a client connects, a Display
object
is automatically created in their object space, which they use as a root to create new
objects and bootstrap their state.
Protocol and messages handling model
The protocol being bi-directional, you can send and receive messages. Sending messages is done via methods of Rust objects corresponding to the wayland protocol objects, receiving and handling them is done by providing callbacks.
Resources
The protocol and message model is very similar to the one of wayland-client
, with the
main difference being that the underlying handles to objects are represented by the Resource<I>
type, very similarly to proxies in wayland-client
.
These resources are used to send messages to the client (in the Wayland context,
these are called "events"). You usually don't use them directly, and instead call
methods on the Rust objects themselves, which invoke the appropriate Resource
methods.
It is also possible to directly use the Resource::<I>::send(..)
method.
There is not a 1 to 1 mapping between Rust object instances and protocol
objects. Rather, you can think of the Rust objects as Rc
-like handles to a
Wayland object. Multiple instances of a Rust object can exist referring to the same
protocol object.
Similarly, the lifetimes of the protocol objects and the Rust objects are
not tightly tied. As protocol objects are created and destroyed by protocol
messages, it can happen that an object gets destroyed while one or more
Rust objects still refer to it. In such case, these Rust objects will be disabled
and the alive()
method on the underlying Resource<I>
will start to return false
.
Events that are subsequently sent to them are ignored.
Filters
Your wayland objects can receive requests from the client, which need to be processed.
To do so, you can assign Filter
s to your object. These are specially wrapped closure
so that several objects can be assigned to the same Filter
, to ease state sharing
between the code handling different objects.
All objects must be assigned to a filter, even if it is for doing nothing.
Failure to do will cause a panic!()
if a request is dispatched to the faulty object.
A Rust object passed to your implementation is guaranteed to be alive (as it just received a request), unless the exact message received is a destructor (which is indicated in the API documentations).
General structure
The core of your server is the Display
object. It represent the ability of your program to
process Wayland messages. Once this object is created, you can configure it to listen on one
or more sockets for incoming client connections (see the Display
docs for details).
wayland-server
does not include an event loop, and you are expected to drive the wayland socket
yourself using the Display::flush_clients
and Display::dispatch
methods. The Display::get_poll_fd
methods provides you with a file descriptor that can be used in a polling structure to integrate
the wayland socket in an event loop.
Modules
protocol | Generated interfaces for the core wayland protocol |
sys | C-associated types |
Macros
request_enum | Generate an enum joining several objects requests |
Structs
AnonymousObject | Anonymous interface |
Client | A handle to a client connected to your server |
DispatchData | Holder of global dispatch-related data |
Display | The wayland display |
Filter | An event filter |
Global | A handle to a global object |
Main | A main handle to a proxy |
Resource | An handle to a wayland resource |
ResourceMap | A handle to the object map internal to the library state |
UserDataMap | A storage able to store several values of |
Enums
NoMessage | An empty enum representing a MessageGroup with no messages |
Traits
Interface | The description of a wayland interface |
MessageGroup | A group of messages |