Linux 黑话解释：什么是显示服务器，用来做什么？
显示服务器
![](/data/attachment/album/202009/06/213037z34ijwij9awa9a9w.png)


在 Linux 相关的文章、新闻和讨论中，你会经常遇到<ruby> 显示服务器 <rt>  display server </rt></ruby>、Xorg、Wayland 等名词。


在这篇解释文章中，我将讨论 Linux 中的显示服务器。


### 什么是显示服务器？


显示服务器是一个程序，它负责协调其客户端与操作系统的其他部分之间，以及硬件和操作系统之间的输入和输出。基本上，多亏了显示服务器，你才能以图形化的方式使用你的计算机（GUI）。如果没有显示服务器，你只能局限于命令行界面（TTY）。


显示服务器提供了一个图形环境的框架，使你可以使用鼠标和键盘与应用程序进行交互。


显示服务器通过[显示服务器协议](https://en.wikipedia.org/wiki/X_Window_System_core_protocol)（如 X11）与客户端进行通信。显示服务器是图形用户界面 —— 特别是窗口系统 —— 中的一个关键组件。


不要把显示服务器和[桌面环境](/article-12579-1.html)混淆。桌面环境的下层使用的是显示服务器。


听起来很熟悉，但又不完全清楚？让我来解释一下。


### Linux 上的显示服务器协议


Linux 中有三种显示服务器协议，分别是 X11、Wayland 和 Mir。下面我就给大家简单介绍一下这些显示服务器。


#### X11


X11（也称 X）是已经存在多年的传统显示服务器。它是 Linux 发行版中最常用的显示服务器。


![X 架构](/data/attachment/album/202009/06/213004juquhr5on5shqa99.png)


X11 通信协议，使用显示服务器 [X.org 服务器](https://en.wikipedia.org/wiki/X.Org_Server)。它接收来自[设备驱动程序](https://en.wikipedia.org/wiki/Device_driver)的输入事件，并将它们提供给它的一个客户端。


显示服务器也从客户端接收数据，它处理数据并进行合成，在 Linux 上，它将数据传递给三个内核组件之一：[DRM](https://en.wikipedia.org/wiki/Direct_Rendering_Manager)、[gem](https://en.wikipedia.org/wiki/Graphics_Execution_Manager) 或 [KMS 驱动](https://en.wikipedia.org/wiki/KMS_driver)。


[X.Org](http://X.Org) 服务器是一个显示服务器，它依靠第二个程序：[合成窗口管理器](https://en.wikipedia.org/wiki/Compositing_window_manager)，来进行合成。例如 [Mutter](https://en.wikipedia.org/wiki/Mutter_(window_manager)) 或 [KWin](https://en.wikipedia.org/wiki/KWin)。GNOME 使用的是 Mutter。


#### Wayland


按照其网站的说法，Wayland “旨在作为 X 的更简单的替代品，更容易开发和维护”。


而事实上 [Wayland](https://wayland.freedesktop.org/) 就是现代的显示服务器，它应该取代传统的 X 显示服务器。


对它的采用还在普及中。Ubuntu 曾试图在 17.10 版本中改用 Wayland 作为默认的显示服务器，但这个尝试遭到了负面反馈。


很多 GUI 应用程序及其框架都依赖于 X 服务器。这些应用程序在 Wayland 上无法正常工作。


这迫使 Ubuntu 继续使用 X 作为默认显示服务器。它仍然提供了使用 Wayland 的选项，但不再是默认的了。


即使在今天，绝大多数的发行版都默认使用 X 显示服务器。


![Wayland 架构](/data/attachment/album/202009/06/213004esi0seimli1mheo0.png)


实施 Wayland 显示服务器协议的显示服务器，被称为 [Wayland 合成器](https://en.wikipedia.org/wiki/Wayland_compositor)。和 X11 上的一样，Wayland 合成器负责处理其客户端的输入和输出，但同时也进行[合成](https://en.wikipedia.org/wiki/Compositing)，这与 X11 相反。


几个 Wayland 合成器是 [Weston](https://en.wikipedia.org/wiki/Weston_(software))、[Mutter](https://en.wikipedia.org/wiki/Mutter_(software))、[KWin](https://en.wikipedia.org/wiki/KWin) 或 [Enlightenment](https://en.wikipedia.org/wiki/Enlightenment_(software))。


#### Mir


[Mir 显示服务器](https://mir-server.io/)自带的 Mir 显示服务器协议，与 X11 和 Wayland 使用的协议不同。它是由 [Canonical](https://canonical.com/) 开发的，作为 Unity 开发的一部分，打算成为 [Ubuntu](https://itsfoss.com/install-ubuntu/) 的首选显示服务器。


但在 2017 年，它已经被 [Ubuntu] 桌面版的 Wayland 显示服务器所取代，不过 Mir 的开发还在继续，用于物联网（IoT）应用。


#### 为什么我们还在使用 Xorg？


Wayland 作为比较新的产品，相比 Xorg 来说，还不是很稳定。作为客户端的程序，必须知道如何与显示服务器进行通信。


因此，很多程序在使用 Wayland 时可能无法运行。Ubuntu 默认切换到 Wayland 的实验证实了这一点。


### 结束语


我希望你对 Linux 中的显示服务器概念有了更好的理解。我已经尽量不谈太多的技术细节，但我无法完全避免。


欢迎你的反馈和建议。




---


via: <https://itsfoss.com/display-server/>


作者：[Dimitrios Savvopoulos](https://itsfoss.com/author/dimitrios/) 选题：[lujun9972](https://github.com/lujun9972) 译者：[wxy](https://github.com/wxy) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
In Linux related articles, news and discussions, you’ll often come across the term display server, Xorg, Wayland etc.

In this explainer article, I’ll discuss display servers in Linux.

## What is display server in Linux?

A display server is a program which is responsible for the input and output coordination of its clients, to and from the rest of the operating system, and among the hardware and the operating system. Basically, thanks to a display server, you can use your computer graphically (GUI). Without the display server, you would only be restricted to a command line interface ([TTY](https://itsfoss.com/what-is-tty-in-linux/)).

The display server provides the framework for a graphical environment so that you can use mouse and keyboard to interact with applications.

The display server communicates with its clients over the [display server protocol](https://en.wikipedia.org/wiki/X_Window_System_core_protocol), like X11. The display server is a key component in any graphical user interface, specifically the windowing system.

Don’t confuse display server with [desktop environment](https://itsfoss.com/what-is-desktop-environment/). The desktop environment uses display server underneath it.

Sounds familiar but it is not fully clear? Let me explain.

## Display server communications protocols in Linux

![Display Server Linux](https://itsfoss.com/content/images/wordpress/2020/08/display-server-linux.png)

There are three display protocols available in Linux, the X11, Wayland and Mir. I’ll give you a brief introduction for these display servers.

### X11

The X11 (also refer as X) is the legacy display server that has been existed for years. It is the most common display server used in Linux distributions.

![X Architecture 1](https://itsfoss.com/content/images/wordpress/2020/08/x-architecture-1.png)

The X11 communication protocol, uses the [X.org Server](https://en.wikipedia.org/wiki/X.Org_Server) display server. It receives input events from [device drivers](https://en.wikipedia.org/wiki/Device_driver) and makes them available to one of its clients.

The display server also receives data from its clients, it processes the data and does the compositing and on Linux it passes the data to one of three kernel components – the [DRM](https://en.wikipedia.org/wiki/Direct_Rendering_Manager), [gem](https://en.wikipedia.org/wiki/Graphics_Execution_Manager) or [KMS driver](https://en.wikipedia.org/wiki/KMS_driver).

The X.Org Server is a display server that relies on a second program, the [compositing window manager](https://en.wikipedia.org/wiki/Compositing_window_manager), to do the compositing. Examples are [Mutter](https://en.wikipedia.org/wiki/Mutter_(window_manager)) or [KWin](https://en.wikipedia.org/wiki/KWin). GNOME uses Mutter.

### Wayland

As per its website, Wayland is “intended as a simpler replacement for X, easier to develop and maintain”.

And indeed [Wayland](https://wayland.freedesktop.org/) is the modern display server that is supposed to replace the legacy X display server.

Its adoption is still a work in progress. Ubuntu tried to switch to Wayland as the default display server with version 17.10 but the experiment met with negative feedback.

A lot of GUI applications and their frameworks depend on the X server. These applications didn’t work as intended on Wayland.

This forced Ubuntu to stay on X as default display server. It still provides the option to use Wayland but it is not default anymore.

An overwhelming majority of distributions use X display server by default even today.

![Wayland display server architecture](https://itsfoss.com/content/images/wordpress/2020/08/wayland-architecture-1.png)

Display servers that put into effect the Wayland display server protocol, are called [Wayland compositors](https://en.wikipedia.org/wiki/Wayland_compositor). Like any X11, a Wayland compositor is responsible for handling input and output for its clients but also does the [compositing](https://en.wikipedia.org/wiki/Compositing) – in contrast to X11.

A few Wayland compositors are [Weston](https://en.wikipedia.org/wiki/Weston_(software)), [Mutter](https://en.wikipedia.org/wiki/Mutter_(software)), [KWin](https://en.wikipedia.org/wiki/KWin) or [Enlightenment](https://en.wikipedia.org/wiki/Enlightenment_(software)).

### Mir

The [Mir display server](https://mir-server.io/) comes with its own Mir display server protocol which differs to those used by X11 and Wayland. It was developed by [Canonical](https://canonical.com/), as part of the development of Unity, and was intended to be the display server of choice for [Ubuntu](https://itsfoss.com/install-ubuntu/).

As of 2017, it has been replaced with the Wayland display server for desktop editions of Ubuntu, although Mir’s development continued for Internet of Things (IoT) applications.

### Why are we still using Xorg?

Wayland as it is relatively new, is not very stable yet, compared to Xorg. The programs, which act as clients, in order to communicate with a display server, must know how to do it.

For this reason, many programs might not run when using Wayland. Ubuntu’s experiment to switch to Wayland by default confirmed this.

### Conclusion

I hope you have a bit better understanding of display server concept in Linux. I have tried to not go into too much technical details but I could not avoid them altogether.

Your feedback and suggestion is welcome.