The new display servers
Changing of the Guard
The X Window System, which dates to the 1980s, still forms the basis of Linux's graphical user interface, but it does cause some despair among developers with its legacy ballast and outmoded technology. Wayland and Mir are two promising candidates for the changing of the guard.
The good old X Window System consists of an X server that receives events from input devices and draws the graphics on the screen. On top of this system is a compositor, which records the positions of Windows and adds novel graphical effects as needed (Figure 1). Desktop environments add a window manager that decorates every window with a frame.
All of these components need to communicate through a time-consuming process. The cumbersome structure and outdated complexity of the X system bothered programmer Kristian H¯gsberg, so he designed an alternative back in 2008, which he dubbed Wayland [1]. H¯gsberg kept to the core functions that a display system currently needs to provide on Linux. He also set out to design Wayland so that it would avoid tearing, lag, flicker, and unnecessary redrawing of modified screen areas [2].
The result was a surprisingly sleek and efficient system. Media reports increasingly attracted the attention of supporters to H¯gsberg's new display server architecture.
One organization that jumped on board with the Wayland development effort was Ubuntu parent company Canonical, but after a couple years in the trenches, Canonical announced that it would instead build its own graphical system called Mir, thus launching another alternative for an X11 replacement.
So far, most Linux distros think of Wayland and Mir as experimental technologies, and few systems actually use them as the default, but most observers believe that the new graphics systems will one day see wide adoption. We decided it was time for a closer look at what Wayland and Mir really are, how they work, and how they differ from the venerable X Window System.
One for All
On a system with Wayland, the Wayland compositor runs in the background. When a user clicks on a window, the compositor receives a matching kernel event. The compositor then determines which window the user clicked on. Wayland receives the necessary information faster than the X server. In contrast to its ancestors, the Wayland compositor always knows where the windows are located and what transformations it has applied to the windows. After finding the right window, the compositor sends the event to the associated application (Figure 2).
Programs that run on Wayland are known as Wayland clients. Clients need to draw their window content themselves – either manually, or using libraries like GTK+, or using hardware-accelerated interfaces such as OpenGL. After doing so, the client notifies the compositor, which puts together the contents of the screen and triggers the display.
In the old X Window System, a window manager draws borders and other decorations around the individual windows. The Wayland specification does not clarify the responsibilities. Usually, the compositor decorates the windows with frames (server side decoration).
Name Confusion
The compositor and clients use a network protocol by the name of Wayland to talk to one another. In practice, developers also refer to the complete system of clients and the compositor as Wayland. The compositor and clients exchange their messages via Unix sockets. The name of the endpoint is found in the environment variable WAYLAND_DISPLAY
and is usually wayland 0
. Messages are always sent asynchronously, which translates to speed increases.
To make it easier for programmers to work on clients and the compositor, the Wayland developers provide the libwayland-client
and libwayland-server
C libraries (Figure 3). Confusingly, this reference implementation of the network protocol also goes by the name of Wayland. The source code of both libraries is available from the project page in the form of the wayland
package [1].
The package also includes an XML file by the name of wayland.xml
, which contains a formal definition of the permissible messages.
The Wayland scanner from the source package generates the two C libraries (semi-) automatically from the XML file. If you compile the libraries according to the guide, you remain blissfully ignorant of them.
Independent
Clients need to render their own window content. To do so, the client first requests a memory area from the compositor that both elements can access, which is known as a shared memory buffer (SMB). The client pushes the new window content into the SMB. It then tells the compositor that something has changed, which rectangular section is affected, and in which buffer the window content is located. The compositor then grabs the buffer and arranges the stored image material, along with the other windows, to create a work of art.
Although the client must request the buffer from the compositor, the client is responsible for managing the buffer. It can use a new buffer for each drawing operation or request multiple buffers in advance and then switch back and forth between them.
You can avoid the cumbersome task of working with buffers and the libwayland-client
library if you develop your programs with SDL, Clutter, Cairo, GTK+ 3, or Qt 5. These popular graphics libraries or GUI frameworks now support Wayland out of the box.
In the case of GTK+ 3 and Qt 5, the users can decide later on whether to use X11 or Wayland for the display. GTK+ 3 offers the environment variable GDK_BACKEND
[3] for this purpose; for QT 5, the environment variable goes by the name of QT_QPA_PLATFORM
. In addition, Qt programs support the platform
command-line parameter to enforce output via one of the two systems.
In addition to the listed options, clients can also hardware-accelerate the window output using OpenGL or OpenGL ES. The client first allocates a buffer directly on the video card using the EGL interface. Like OpenGL, EGL [4] comes from the Khronos group, and it mediates between the window system – in this case Wayland – and the OpenGL and OpenGL graphics libraries.
Once the client has drawn the contents of its window, it hands control over to the compositor. The compositor then composes the screen content with EGL, OpenGL, or the OpenGL successor Vulkan [5].
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Endless OS 6 has Arrived
After more than a year since the last update, the latest release of Endless OS is now available for general usage.
-
Fedora Asahi 40 Remix Available for Macs with Apple Silicon
If you've been anticipating KDE's Plasma 6 for your Apple Silicon-powered Mac, then you're in luck.
-
Red Hat Adds New Deployment Option for Enterprise Linux Platforms
Red Hat has re-imagined enterprise Linux for an AI future with Image Mode.
-
OSJH and LPI Release 2024 Open Source Pros Job Survey Results
See what open source professionals look for in a new role.
-
Proton 9.0-1 Released to Improve Gaming with Steam
The latest release of Proton 9 adds several improvements and fixes an issue that has been problematic for Linux users.
-
So Long Neofetch and Thanks for the Info
Today is a day that every Linux user who enjoys bragging about their system(s) will mourn, as Neofetch has come to an end.
-
Ubuntu 24.04 Comes with a “Flaw"
If you're thinking you might want to upgrade from your current Ubuntu release to the latest, there's something you might want to consider before doing so.
-
Canonical Releases Ubuntu 24.04
After a brief pause because of the XZ vulnerability, Ubuntu 24.04 is now available for install.
-
Linux Servers Targeted by Akira Ransomware
A group of bad actors who have already extorted $42 million have their sights set on the Linux platform.
-
TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.