Wayland (display server protocol)
Wayland is a communication protocol that specifies the communication between a display server and its clients, as well as a C library implementation of that protocol. A display server using the Wayland protocol is called a Wayland compositor, because it additionally performs the task of a compositing window manager.
Wayland is developed by a group of volunteers initially led by Kristian Høgsberg as a free and open-source community-driven project with the aim of replacing the X Window System with a modern, simpler windowing system in Linux and other Unix-like operating systems. The project's source code is published under the terms of the MIT License, a permissive free software licence.
As part of its efforts, the Wayland project also develops a reference implementation of a Wayland compositor called [|Weston].
Overview
Starting around 2010, Linux desktop graphics has moved from having "a pile of rendering interfaces... all talking to the X server, which is at the center of the universe" towards putting the Linux kernel and its components, Direct Rendering Manager ) "in the middle", with "window systems like X and Wayland... off in the corner". This will be "a much-simplified graphics system offering more flexibility and better performance".Kristian Høgsberg could have added an extension to X as many recent projects have done, but preferred to " X out of the hotpath between clients and the hardware" for reasons explained in the project's FAQ:
Wayland consists of a protocol and a reference implementation named Weston. The project is also developing versions of GTK and Qt that render to Wayland instead of to X. Most applications are expected to gain support for Wayland through one of these libraries without modification to the application.
Initial versions of Wayland have not provided network transparency, though Høgsberg noted in 2010 that network transparency is possible.
It was attempted as a Google Summer of Code project in 2011, but was not successful.
Adam Jackson has envisioned providing remote access to a Wayland application by either "pixel-scraping" or getting it to send a "rendering command stream" across the network. As of early 2013, Høgsberg is experimenting with network transparency using a proxy Wayland server which sends compressed images to the real compositor. In August 2017, GNOME saw the first such pixel-scraping VNC server implementation under Wayland.
Software architecture
Protocol architecture
Wayland protocol follows a client–server model in which clients are the graphical applications requesting the display of pixel buffers on the screen, and the server is the service provider controlling the display of these buffers.The Wayland reference implementation has been designed as a two-layer protocol:
- A low-level layer or wire protocol that handles the inter-process communication between the two involved processesclient and compositorand the marshalling of the data that they interchange. This layer is message-based and usually implemented using the kernel IPC services, specifically Unix domain sockets in the case of Linux and Unix-like operating systems.
- A high-level layer built upon it, that handles the information that client and compositor need to exchange to implement the basic features of a window system. This layer is implemented as "an asynchronous object-oriented protocol".
The reference implementation of Wayland protocol is split in two libraries: a library to be used by Wayland clients called
libwayland-client
and a library to be used by Wayland compositors called libwayland-server
.Protocol overview
The Wayland protocol is described as an "asynchronous object-oriented protocol". Object-oriented means that the services offered by the compositor are presented as a series of objects living on the same compositor. Each object implements an interface which has a name, a number of methods as well as several associated events. Every request and event has zero or more arguments, each one with a name and a data type. The protocol is asynchronous in the sense that requests do not have to wait for synchronized replies or ACKs, avoiding round-trip delay time and achieving improved performance.The Wayland clients can make a request on some object if the object's interface supports that request. The client must also supply the required data for the arguments of such request. This is the way the clients request services from the compositor. The compositor in turn sends information back to the client by causing the object to emit events. These events can be emitted by the compositor as a response to a certain request, or asynchronously, subject to the occurrence of internal events or state changes. The error conditions are also signaled as events by the compositor.
For a client to be able to make a request to an object, it first needs to tell the server the ID number it will use to identify that object. There are two types of objects in the compositor: global objects and non-global objects. Global objects are advertised by the compositor to the clients when they are created, while non-global objects are usually created by other objects that already exist as part of their functionality.
The interfaces and their requests and events are the core elements that define the Wayland protocol. Each version of the protocol includes a set of interfaces, along with their requests and events, which are expected to be in any Wayland compositor. Optionally, a Wayland compositor may define and implement its own interfaces that support new requests and events, thereby extending functionality beyond the core protocol. To facilitate changes to the protocol, each interface contains a "version number" attribute in addition to its name; this attribute allows for distinguishing variants of the same interface. Each Wayland compositor exposes not only what interfaces are available, but also the supported versions of those interfaces.
Wayland core interfaces
The interfaces of the current version of Wayland protocol are defined in the file protocol/wayland.xml of the Wayland source code. This is an XML file that lists the existing interfaces in the current version, along with their requests, events and other attributes. This set of interfaces is the minimum required to be implemented by any Wayland compositor.Some of the most basic interfaces of the Wayland protocol are:
- wl_display the core global object, a special object to encapsulate the Wayland protocol itself
- wl_registry the global registry object, in which the compositor registers all the global objects that it wants to be available to all clients
- wl_compositor an object that represents the compositor, and is in charge of combining the different surfaces into one output
- wl_surface an object representing a rectangular area on the screen, defined by a location, size and pixel content
- wl_buffer an object that, when attached to a wl_surface object, provides its displayable content
- wl_output an object representing the displayable area of a screen
- wl_pointer, wl_keyboard, wl_touch objects representing different input devices like pointers or keyboards
- wl_seat an object representing a seat in multiseat configurations
Wayland extension interfaces
A Wayland compositor can define and export its own additional interfaces. This feature is used to extend the protocol beyond the basic functionality provided by the core interfaces, and has become the standard way to implement Wayland protocol extensions. Certain compositors can choose to add custom interfaces to provide specialized or unique features. The Wayland reference compositor, Weston, used them to implement new experimental interfaces as a testbed for new concepts and ideas, some of which later became part of the core protocol.Extension protocols to the core protocol
XDG-Shell protocol
XDG-Shell protocol is an extended way to manage surfaces under Wayland compositors. The traditional way to manipulate surfaces is to use the wl_shell_* functions, which are part of the core Wayland protocol and live in libwayland-client. An implementation of the xdg-shell protocol, on the contrary, is supposed to be provided by the Wayland compositor. So you will find the xdg-shell-client-protocol.h header in the Weston source tree. Each Wayland compositor is supposed to provide its own implementation., XDG-Shell protocol was not versioned and still prone to changes.
xdg_shell is a protocol aimed to substitute wl_shell in the long term, but will not be part of the Wayland core protocol. It starts as a non-stable API, aimed to be used as a development place at first, and once features are defined as required by several desktop shells, it can be finally made stable. It provides mainly two new interfaces: xdg_surface and xdg_popup. The xdg_surface interface implements a desktop-style window that can be moved, resized, maximized, etc.; it provides a request for creating child/parent relationship. The xdg_popup interface implements a desktop-style popup/menu; an xdg_popup is always transient for another surface, and also has implicit grab.
IVI-Shell protocol
IVI-Shell is an extension to the Wayland core protocol, targeting in-vehicle infotainment devices.Rendering model
The Wayland protocol does not include a rendering API. Instead, Wayland follows a direct rendering model, in which the client must render the window contents to a buffer shareable with the compositor. For that purpose, the client can choose to do all the rendering by itself, use a rendering library like Cairo or OpenGL, or rely on the rendering engine of high-level widget libraries with Wayland support, such as Qt or GTK. The client can also optionally use other specialized libraries to perform specific tasks, such as Freetype for font rendering.The resulting buffer with the rendered window contents are stored in a wl_buffer object. The internal type of this object is implementation dependent. The only requirement is that the content data must be shareable between the client and the compositor. If the client uses a software renderer and the result is stored in the system memory, then client and compositor can use shared memory to implement the buffer communication without extra copies. The Wayland protocol already natively provides this kind of shared memory buffer through the wl_shm and wl_shm_pool interfaces. The drawback of this method is that the compositor may need to do additional work to display it, which leads to slower graphics performance.
The most typical case is for the client to render directly into a video memory buffer using a hardware accelerated API such as OpenGL, OpenGL ES or Vulkan. Client and compositor can share this GPU-space buffer using a special handler to reference it. This method allows the compositor to avoid additional copies of data to the GPU, resulting in faster graphics performance than using shm buffers, and is therefore the preferred one. The compositor can further optimize the composition of the final scene to be shown on the display by using the same hardware acceleration API as the client.
When rendering is completed in a shared buffer, the Wayland client should instruct the compositor to present the rendered contents of the buffer on the display. For this purpose, the client binds the buffer object that stores the rendered contents to the surface object, and sends a "commit" request to the surface, transferring the effective control of the buffer to the compositor. Then the client waits for the compositor to release the buffer if it wants to reuse the buffer to render another frame, or it can use another buffer to render the new frame, and, when the rendering is finished, bind this new buffer to the surface and commit its contents. The procedure used for rendering, including the number of buffers involved and their management, is entirely under the client control.
Comparison with other window systems
Differences between Wayland and X
There are several differences between Wayland and X in regards to performance, code maintainability, and security:; Architecture : The composition manager is a separate, additional feature in X, while Wayland merges display server and compositor as a single function. Also, it incorporates some of the tasks of the window manager, which in X is a separate client-side process.
; Compositing : Compositing is optional in X, but mandatory in Wayland. Compositing in X is "active"; that is, the compositor must fetch all pixel data, which introduces latency. In Wayland, compositing is "passive", which means the compositor receives pixel data directly from clients.
; Rendering : The X server itself is able to perform rendering, although it can also be instructed to display a rendered window sent by a client. In contrast, Wayland does not expose any API for rendering, but delegates to clients such tasks. Window decorations can be rendered on the client side or on the server side.
; Security : Wayland isolates the input and output of every window, achieving confidentiality, integrity and availability in both cases; the original X design lacks these important security features, although some extensions have been developed trying to mitigate it. Also, with the vast majority of the code running in the client, less code needs to run with root privileges, improving security, although multiple popular Linux distributions now allow X to be run without root privileges.
; Inter-process communication : The X server provides a basic communication method between X clients, later extended by ICCCM conventions. This X client-to-client communication is used by window managers and also to implement X sessions, selections and drag-and-drop, and other features. The Wayland core protocol does not support communication between wayland clients at all, and the corresponding functionality should be implemented by the desktop environments, or by a third party.
; Networking : The X Window System is an architecture that was designed at its core to run over a network. Wayland does not offer network transparency by itself; however, a compositor can implement any remote desktop protocol to achieve remote display. In addition, there is research into Wayland image streaming and compression that would provide remote frame buffer access similar to that of VNC.
Compatibility with X
is an X Server running as a Wayland client, and thus is capable of displaying native X11 client applications in a Wayland compositor environment. This is similar to the way XQuartz runs X applications in macOS’s native windowing system. The goal of XWayland is to facilitate the transition from X Window System to Wayland environments, providing a way to run unported applications in the meantime. XWayland was mainlined into X.Org Server version 1.16.Widget toolkits such as Qt5 and GTK3 can switch their graphical back-end at run time, allowing users to choose at load time whether they want to run the application over X or over Wayland. Qt 5 provides the command-line option to that effect, whereas GTK 3 lets users select the desired GDK back-end by setting the Unix environment variable.
Wayland compositors
s that implement the Wayland display server protocol are also called Wayland compositors because they additionally perform the task of a compositing window manager.- Weston the reference implementation of a Wayland compositor; Weston implements client side decorations
- Lipstick mobile graphical shell framework which implements Wayland compositor; it is used in Sailfish OS, Nemo Mobile and AsteroidOS
- Enlightenment claimed full Wayland support since version 0.20 but work is currently underway to land a complete Wayland compositor
- KWin has nearly complete Wayland support as of 2018
- Mutter maintains a separate branch for the integration of Wayland for GNOME 3.9
- Clayland – a simple example Wayland compositor using Clutter
- Westeros – a Wayland compositor library that allows applications to create their own Wayland displays, which allows nesting and embedding of third party applications
- wlroots – a modular Wayland implementation that functions as a base for other compositors, most notably Sway
- Sway – a tiling Wayland compositor and a drop-in replacement for the i3 window manager for X11
Weston
Weston supports High-bandwidth Digital Content Protection.
Weston relies on GEM to share application buffers between the compositor and applications. It contains a plug-in system of "shells" for common desktop features like docks and panels. Clients are responsible for the drawing of their window borders and their decorations. For rendering, Weston can use OpenGL ES or the pixman library to do software rendering. The full OpenGL implementation is not used, because on most current systems, installing the full OpenGL libraries would also install GLX and other X Window System support libraries as dependencies.
A remote access interface for Weston was proposed in October 2013 by a RealVNC employee.
Maynard
Maynard is a graphical shell and has been written as a plug-in for Weston, just as the GNOME Shell has been written as a plug-in to Mutter.libinput
The Weston code for handling input devices was split into its own separate library, called libinput, for which support was first merged in Weston 1.5.Libinput handles input devices for multiple Wayland compositors and also provides a generic X.Org Server input driver. It aims to provide one implementation for multiple Wayland compositors with a common way to handle input events while minimizing the amount of custom input code compositors need to include. libinput provides device detection, device handling, input device event processing and abstraction.
Version 1.0 of libinput followed version 0.21, and included support for tablets, button sets and touchpad gestures. This version will maintain stable API/ABI.
As GNOME/GTK and KDE Frameworks 5 have mainlined the required changes, Fedora 22 will replace X.Org's evdev and Synaptics drivers with libinput.
With version 1.16, the X.Org Server obtained support for the libinput library in form of a wrapper called xf86-input-libinput.
Wayland Security Module
Wayland Security Module is a proposition that resembles the Linux Security Module interface found in the Linux kernel.Some applications require privileged capabilities that should work across different Wayland compositors. Currently, applications under Wayland are generally unable to perform any sensitive tasks such as taking screenshots or injecting input events. Wayland developers are actively looking for feasible ways to handle privileged clients securely and then designing privileged interfaces for them.
Wayland Security Module is a way to delegate security decisions within the compositor to a centralized security decision engine.
Adoption
The Wayland protocol is designed to be simple so that additional protocols and interfaces need to be defined and implemented to achieve a holistic windowing system. As of July 2014 these additional interfaces were being worked on. So, while the toolkits already fully support Wayland, the developers of the graphical shells are cooperating with the Wayland developers creating the necessary additional interfaces.Desktop Linux distributions
In general, out-of-the-box support for a full desktop running Wayland in major Linux distributions is still in early stages. Most Linux distributions that ship version 3.20 or newer of the Gnome desktop environment support manually installing a Wayland session, and in case of Gnome 3.22 or newer might default to Wayland. Notable early adopters that provide Wayland out of the box are:- Fedora starting with version 25 uses Wayland for the default GNOME 3.22 desktop session, with X.Org as a fallback if the graphics driver cannot support Wayland.
- RebeccaBlackOS is a live USB Debian-based Linux distribution that allows a convenient way to try out a real Wayland desktop without having to make any modifications to the main operating system of the computer. It has been used since as early as 2012 to showcase Wayland.
- Ubuntu ships Wayland as default in Ubuntu 17.10. Ubuntu reverted to X.Org for Ubuntu 18.04 LTS, as Wayland still has issues with screen sharing and remote desktop applications, and does not recover as well from window manager crashes.
- Red Hat Enterprise Linux ships Wayland as the default session in version 8.
- Debian ships Wayland as the default session for GNOME since version 10.
- Slackware Linux included Wayland on Feb 20th, 2020 for the development version, -current, which will eventually become version 15.0.
- PureOS included Wayland on Feb 20th, 2020 for the development version, -current, which will eventually become version 15.0.
Toolkit support
- Clutter has complete Wayland support.
- EFL has complete Wayland support, except for selection.
- GTK 3.20 has complete Wayland support.
- Qt 5 has complete Wayland support, and can be used to write both Wayland compositors and Wayland clients.
- SDL support for Wayland debuted with the 2.0.2 release and was enabled by default since version 2.0.4.
- GLFW 3.2 has Wayland support.
- FreeGLUT has initial Wayland support.
Desktop environments
In November 2015, Enlightenment e20 was announced with full Wayland support. GNOME 3.20 was the first version to have a full Wayland session. GNOME 3.22 included much improved Wayland support across GTK, Mutter, and GNOME Shell. GNOME 3.24 shipped support for the proprietary NVidia drivers under Wayland.
Wayland support for KDE Plasma was delayed until the release of Plasma 5, though previously KWin 4.11 got an experimental Wayland support. The version 5.4 of Plasma was the first with a Wayland session.
Other software
Other software supporting Wayland includes the following:- Intelligent Input Bus is working on Wayland support, it could be ready for Fedora 22.
- RealVNC published a Wayland developer preview in July 2014.
- Maliit is an input method framework that runs under Wayland.
- kmscon supports Wayland with wlterm.
- Mesa has Wayland support integrated.
- Eclipse was made to run on Wayland during a GSoC-Project in 2014.
- The Vulkan WSI is a set of API calls serve a similar purpose as EGL does for OpenGL ES or GLX for OpenGL. Vulkan WSI includes support for Wayland from day one: VK_USE_PLATFORM_WAYLAND_KHR. Vulkan clients can run on unmodified Wayland servers, including Weston, GENIVI LayerManager, Mutter / GNOME Shell, Enlightenment, and more. The WSI allows applications to discover the different GPUs on the system, and display the results of GPU rendering to a window system.
- SPURV, a compatibility layer for Android applications to run on GNU/Linux distributions using Wayland
Mobile and embedded hardware
- GENIVI Alliance: The GENIVI automotive industry consortium for in-vehicle infotainment supports Wayland.
- Raspberry Pi: The Raspberry Pi Foundation in collaboration with Collabora released Maynard and work on improving performance and memory consumption, but do not expect to be able to replace X11 as the default display server until later.
- Jolla: Smartphones from Jolla use Wayland. It is also used as standard when Linux Sailfish OS is used with hardware from other vendors or when it is installed into Android devices by users.
- Tizen: Tizen up to 2.x supports Wayland in in-vehicle infotainment setups and from 3.0 onward defaults to Wayland.
History
In October 2010, Wayland became a freedesktop.org project. As part of the migration the prior Google Group was replaced by the wayland-devel mailing list as the project's central point of discussion and development.
The Wayland client and server libraries were initially released under the MIT License, while the reference compositor Weston and some example clients used the GNU General Public License version 2. Later all the GPL code was relicensed under the MIT license "to make it easier to move code between the reference implementation and the actual libraries". In 2015 it was discovered that the license text used by Wayland was a slightly different and older version of the MIT license, and the license text was updated to the current version used by the X.Org project.
Wayland works with all Mesa-compatible drivers with DRI2 support as well as Android drivers via the Hybris project.
The developers of Wayland are largely current X.Org Server developers.