1. Overview
In this tutorial, we’ll discuss the X Window System (X11). First, we’ll look at the history of why X11 was created and how the graphics under Linux work. Then, we’ll cover how X11 is designed.
Lastly, we’ll touch upon the current state of X11 and why it will be replaced in the future.
2. The X Window System Project
The X Window System is a windowing system used in most Linux distributions.
The implementation of the project first began in 1984, with the primary objective being a platform-independent graphics system. For that reason, the original developers designed a client-server-based graphics system that communicates through the X protocol.
Currently, the project is led by the X.Org Foundation under the permissive MIT License.
2.1. Graphics Under Linux
Fundamentally, Linux is just a kernel that provides an interface between the hardware and software applications. So, most distributions come with preinstalled packages and related utilities set up around the Linux kernel.
Therefore, to achieve complex graphics such as windows, decoration, visual effects, and event handling, we’d need a complete graphics stack of necessary packages. One of these packages is the X.Org Server.
Every graphics toolkit, such as QT and GTK, communicates with the X.Org Server behind the scenes. So, we can say that the X.Org Server is the crucial piece of the puzzle responsible for drawing graphics to the screen and handling user interactions.
3. X11 Architecture
As we saw above, the X Window system is based on the network-transparent client-server architecture. This means that if our client – the application window – is on one machine and our server is on another, the client will still be interactive as long as both machines are connected.
The X protocol is responsible for the delivery of messages between a client and a server — either locally or remotely:
3.1. The X Client
The X Client is the front-end of a software window, which is completely isolated from the server. When we start an X Client, it connects to the X Server, which manages the client.
The X Client can draw primitive shapes like rectangles and text to the screen. However, it doesn’t have the ability to draw complex widgets like buttons and drop-downs*,* which we can achieve using a GUI toolkit.
Xlib (X Library) is the client-side implementation, which is used by GUI toolkits like GTK to present an enhanced front-end for the graphical applications.
Apart from Xlib, there is the lower-level XCB library. Xlib also uses XCB for some of its features.
3.2. The X Server
The X Server or X.Org or simply X is the most popular server-side implementation of the X Window System.
X is responsible for access to the graphics card, display screen, and I/O. Events generated by the X clients are handled, and the result is communicated back to its respective clients by X.
The X Server is usually started by a display manager such as GDM.
3.3. The X Protocol and X11
X11 is the protocol that’s responsible for delivering payloads between an X Client and an X Server. Fundamentally, X is a family of protocols, whereas X11 is the 11th version of the X protocol.
X11 is an extensible protocol. Therefore, we can easily add additional features to the protocol without breaking the existing clients.
By design, X11 is network-transparent. This allows the possibility of running the client and the server either on the same machine or different ones. A client and a server can also communicate over the Internet through an encrypted network session.
On the same host, these messages are delivered through UNIX sockets for efficient communication.
3.4. Compositors
Compositors provide an off-screen buffer for each X Client, which goes by the name Compositor Overlay Window (COW). It contains the styling and geometry information for its respective client.
Although it’s not mandatory to have a compositor, it provides additional styling for the X Clients. The compositor retrieves each frame from each running window, applies styles, and renders it onto the screen.
4. Current State and the Future of X
The latest version of the X11 specification was developed in 2012. There have been no additional changes to the protocol as it’s pretty stable at this point.
However, there are some security issues. By default, X doesn’t encrypt the messages between the X Client and the X Server. Therefore, one can easily intercept those network packets. Additionally, there are also latency issues due to the round-trip delay time between a client and a server over a network.
For that reason, Wayland is the prospective replacement for X in the future. Recently, most major distributions like Ubuntu, OpenSUSE, and RedHat have adopted Wayland. Although it’s not free of issues, it’s actively developed and tested.
5. Conclusion
In this article, we covered the X Window System architecture. More specifically, we differentiated between the different terminologies used in the X Window System.
Lastly, we also covered the limitations of X and why Wayland will replace it in the future.