Chapter 14. A Brief Survey of the Linux Desktop(Linux 桌面简介)
This chapter is a quick introduction to the components found in a typical Linux desktop system. Of all of the different kinds of software that you can find on Linux systems, the desktop arena is one of the wildest and most colorful because there are so many environments and applications to choose from, and most distributions make it relatively easy for you to try them out.
本章是对典型Linux桌面系统中的组件进行快速介绍。
在Linux系统中,桌面领域是最为丰富多样的,因为有很多不同的环境和应用程序可供选择,并且大多数发行版都相对容易让您尝试它们。
Unlike other parts of a Linux system, such as storage and networking, there isn’t much of a hierarchy of layers involved in creating a desktop structure. Instead, each component performs a specific task, communicating with other components as necessary. Some components do share common building blocks (in particular, libraries for graphical toolkits), and these can be thought of as simple abstraction layers, but that’s about as deep as it goes.
与Linux系统的其他部分(如存储和网络)不同,创建桌面结构并没有涉及太多层次的层次结构。
相反,每个组件都执行特定的任务,并在必要时与其他组件进行通信。
一些组件确实共享共同的构建模块(特别是用于图形工具包的库),可以将其视为简单的抽象层,但仅限于此。
This chapter offers a high-level discussion of desktop components in general, but we’ll look at two pieces in a little more detail: the X Window System, which is the core infrastructure behind most desktops, and D-Bus, an interprocess communication service used in many parts of the system. We’ll limit the hands-on discussion and examples to a few diagnostic utilities that, while not terribly useful day-to-day (most GUIs don’t require you to enter shell commands in order to interact with them), will help you understand the underlying mechanics of the system and perhaps provide some entertainment along the way. We’ll also take a quick look at printing.
本章对桌面组件进行了高层次的讨论,但我们将更详细地研究两个组件:X Window System(大多数桌面背后的核心基础设施)和D-Bus(系统中许多部分使用的进程间通信服务)。
我们将限制实践讨论和示例,仅介绍一些诊断实用工具,虽然这些工具在日常使用中并不是非常有用(大多数图形界面不需要您输入shell命令来与它们交互),但它们将帮助您了解系统的基本原理,并提供一些娱乐。
我们还会简要介绍打印功能。
14.1 Desktop Components(桌面组件)
Linux desktop configurations offer a great deal of flexibility. Most of what the Linux user experiences (the “look and feel” of the desktop) comes from applications or building blocks of applications. If you don’t like a particular application, you can usually find an alternative. And if what you’re looking for doesn’t exist, you can write it yourself. Linux developers tend to have a wide variety of preferences for how a desktop should act, which makes for a lot of choices.
Linux桌面配置提供了很大的灵活性。
Linux用户所体验到的大部分内容(即桌面的“外观和感觉”)来自应用程序或应用程序的构建模块。
如果您不喜欢某个特定的应用程序,通常可以找到替代品。
而且,如果您所需要的东西不存在,您可以自己编写。
Linux开发人员对于桌面应该如何运作有各种各样的偏好,这就带来了很多选择。
In order to work together, all applications need to have something in common, and at the core of nearly everything on most Linux desktops is the X (X Window System) server. Think of X as sort of the “kernel” of the desktop that manages everything from rendering windows to configuring displays to handling input from devices such as keyboards and mice. The X server is also the one component that you won’t easily find a replacement for (see 14.4 The Future of X).
为了能够协同工作,所有应用程序都需要有一些共同点,而在大多数Linux桌面上的几乎所有东西的核心是X(X Window System)服务器。
可以将X视为桌面的“内核”,它负责管理从渲染窗口到配置显示器再到处理键盘和鼠标等设备输入的所有内容。
X服务器也是您不容易找到替代品的一个组件(参见14.4节《X的未来》)。
The X server is just a server and does not dictate the way anything should act or appear. Instead, X client programs handle the user interface. Basic X client applications, such as terminal windows and web browsers, make connections to the X server and ask to draw windows. In response, the X server figures out where to place the windows and renders them. The X server also channels input back to the client when appropriate.
X服务器只是一个服务器,不会规定任何东西的行为或外观。
相反,X客户端程序处理用户界面。基本的X客户端应用程序,例如终端窗口和Web浏览器,会连接到X服务器并请求绘制窗口。
作为响应,X服务器会确定窗口的放置位置并对其进行渲染。
当适当时,X服务器还会将输入传递回客户端。
14.1.1 Window Managers(Win 管理器)
X clients don’t have to act like windowed user applications; they can act as services for other clients or provide other interface functions. A window manager is perhaps the most important client service application because it figures out how to arrange windows on screen and provides interactive decorations like title bars that allow the user to move and minimize windows. These elements are central to the user experience.
X客户端不必像窗口化的用户应用程序那样行动;它们可以作为其他客户端的服务或提供其他接口功能。
窗口管理器可能是最重要的客户端服务应用程序,因为它能够确定如何在屏幕上排列窗口,并提供交互装饰,如标题栏,允许用户移动和最小化窗口。
这些元素对用户体验至关重要。
There are many window manager implementations. Examples such as Mutter/GNOME Shell and Compiz are meant to be more or less standalone, while others are built into environments such as Xfce. Most window managers included in the standard Linux distributions strive for maximum user comfort, but others provide specific visual effects or take a minimalist approach. There’s not likely to ever be a standard Linux window manager because user tastes and requirements are diverse and constantly changing; as a result, new window managers appear all the time.
有许多窗口管理器的实现。像Mutter/GNOME Shell和Compiz这样的例子,意味着它们更或多或少是独立的,而其他一些则内置于环境中,如Xfce。
大多数包含在标准Linux发行版中的窗口管理器都力求为用户提供最大的舒适性,但其他一些则提供特定的视觉效果或采取极简主义的方法。
不太可能会有一个标准的Linux窗口管理器,因为用户的口味和需求是多样化且不断变化的;因此,新的窗口管理器一直在不断出现。
14.1.2 Toolkits(工具包)
Desktop applications include certain common elements, such as buttons and menus, called widgets. To speed up development and provide a common look, programmers use graphical toolkits to provide these elements. On operating systems such as Windows or Mac OS X, the vendor provides a common toolkit, and most programmers use that. On Linux, the GTK toolkit is one of the most common, but you’ll also frequently see widgets built on the Qt framework and others. Toolkits usually consist of shared libraries and support files such as images and theme information.
桌面应用程序包括一些常见的元素,如按钮和菜单,称为小部件。
为了加快开发速度并提供统一的外观,程序员使用图形工具包来提供这些元素。
在诸如Windows或Mac OS X等操作系统上,供应商提供了一个常用的工具包,大多数程序员使用它。
在Linux上,GTK 工具包是最常见的之一,但你也经常会看到基于Qt框架和其他工具包构建的小部件。
工具包通常由共享库和支持文件(如图像和主题信息)组成。
14.1.3 Desktop Environments(桌面环境)
Although toolkits provide the user with a uniform outward appearance, some details of a desktop require a degree of cooperation between different applications. For example, one application may wish to share data with another or update a common notification bar on a desktop. To provide for these needs, toolkits and other libraries are bundled into larger packages called desktop environments. GNOME, KDE, Unity, and Xfce are some common Linux desktop environments.
尽管工具包为用户提供了统一的外观,但桌面的一些细节需要不同应用程序之间的合作。
例如,一个应用程序可能希望与另一个应用程序共享数据,或者更新桌面上的公共通知栏。
为了满足这些需求,工具包和其他库被捆绑到称为桌面环境的更大的软件包中。
GNOME、KDE、Unity和Xfce是一些常见的Linux桌面环境。
Toolkits are at the core of most desktop environments, but to create a unified desktop, environments must also include numerous support files, such as icons and configurations, that make up themes. All of this is bound together with documents that describe design conventions, such as how application menus and titles should appear and how applications should react to certain system events.
工具包是大多数桌面环境的核心,但为了创建一个统一的桌面,环境还必须包括许多支持文件,如图标和配置文件,这些文件组成了主题。
所有这些都与描述设计约定的文档绑定在一起,例如应用程序菜单和标题的外观以及应用程序对某些系统事件的反应方式。
14.1.4 Applications(应用程序)
At the top of the desktop are applications, such as web browsers and the terminal window. X applications can range from crude (such as the ancient xclock program) to complex (such as the Chrome web browser and LibreOffice suite). These applications normally stand alone, but they often use interprocess communication to become aware of pertinent events. For example, an application can express interest when you attach a new storage device or when you receive new email or an instant message. This communication usually occurs over D-Bus, described in 14.5 D-Bus
在桌面的顶部有应用程序,如网络浏览器和终端窗口。
X应用程序的范围可以从简单粗糙(如古老的xclock程序)到复杂(如Chrome网络浏览器和LibreOffice套件)。
这些应用程序通常是独立的,但它们经常使用进程间通信来了解相关事件。
例如,当您连接新的存储设备或收到新的电子邮件或即时消息时,应用程序可以表达兴趣。
这种通信通常是通过D-Bus进行的,详见14.5 D-Bus。
14.2 A Closer Look at the X Window System(近距离观察 X 窗口系统)
The X Window System (http://www.x.org/) has historically been very large, with the base distribution including the X server, client support libraries, and clients. Due to the emergence of desktop environments such as GNOME and KDE, the role of the X distribution has changed over time, with the focus now more on the core server that manages rendering and input devices, as well as a simplified client library.
X Window系统(http://www.x.org/)一直以来都非常庞大,基本发行版包括X服务器、客户端支持库和客户端。
由于出现了GNOME和KDE等桌面环境,X发行版的角色随着时间的推移发生了变化,现在更加关注管理渲染和输入设备的核心服务器,以及一个简化的客户端库。
The X server is easy to identify on your system. It’s called X. Check for it in a process listing; you’ll usually see it running with a number of options like this:
代码语言:javascript复制/usr/bin/X :0 -auth /var/run/lightdm/root/:0 -nolisten tcp vt7 -
novtswitch
The :0 shown here is called the display, an identifier representing one or more monitors that you access with a common keyboard and/or mouse. Usually, the display just corresponds to the single monitor you attach to your computer, but you can put multiple monitors under the same display. When using an X session, the DISPLAY environment variable is set to the display identifier.
这里显示的:0被称为显示器,它是一个表示一个或多个监视器的标识符,您可以通过共同的键盘和/或鼠标访问它们。
通常,显示器只对应您连接到计算机上的单个监视器,但您也可以将多个监视器放在同一个显示器下。
在使用X会话时,DISPLAY环境变量被设置为显示器标识符。
NOTE Displays can be further subdivided into screens, such as :0.0 and :0.1, but this has become increasingly rare because X extensions, such as RandR, can combine multiple monitors into one larger virtual screen. 注意 显示器可以进一步细分为屏幕,例如:0.0和:0.1,但这种情况越来越少见,因为X扩展(如RandR)可以将多个监视器组合成一个更大的虚拟屏幕。
On Linux, an X server runs on a virtual terminal. In this example, the vt7 argument tells us that it’s been told to run on /dev/tty7 (normally, the server starts on the first virtual terminal available). You can run more than one X server at a time on Linux by running them on separate virtual terminals, but if you do, each server needs a unique display identifier. You can switch between the servers with the CTRL-ALT-FN keys or the chvt command.
在Linux上,X服务器在虚拟终端上运行。在这个例子中,vt7参数告诉我们它被告知在/dev/tty7上运行(通常,服务器会在可用的第一个虚拟终端上启动)。
您可以通过在不同的虚拟终端上运行它们来同时运行多个X服务器,但如果这样做,每个服务器都需要一个唯一的显示器标识符。
您可以使用CTRL-ALT-FN键或chvt命令在服务器之间切换。
在您的系统上很容易识别X服务器。它被称为X。在进程列表中查找它;通常您会看到它以如下所示的一些选项运行:
代码语言:javascript复制/usr/bin/X :0 -auth /var/run/lightdm/root/:0 -nolisten tcp vt7 -
novtswitch
14.2.1 Display Managers(显示管理人员)
You normally don’t start the X server with a command line because starting the server doesn’t define any clients that are supposed to run on the server. If you start the server by itself, you’ll just get a blank screen. Instead, the most common way to start an X server is with a display manager, a program that starts the server and puts a login box on the screen. When you log in, the display manager starts a set of clients, such as a window manager and file manager, so that you can start to use the machine.
通常情况下,你不会通过命令行来启动X服务器,因为仅仅启动服务器并不会定义任何应该在服务器上运行的客户端。
如果仅仅启动服务器,你将只会看到一个空白屏幕。
相反,最常见的启动X服务器的方式是使用显示管理器,它是一个程序,用于启动服务器并在屏幕上显示登录框。
当你登录时,显示管理器会启动一组客户端,例如窗口管理器和文件管理器,以便你开始使用计算机。
There are many different display managers, such as gdm (for GNOME) and kdm (for KDE). The lightdm in the argument list for the X server invocation above is a cross-platform display manager meant to be able to start GNOME or KDE sessions.
To start an X session from a virtual console instead of using a display manager, you can run the startx or xinit command. However, the session you get will likely be a very simple one that looks completely unlike that of a display manager, because the mechanics and startup files are different.
有许多不同的显示管理器,例如gdm(用于GNOME)和kdm(用于KDE)。
上述X服务器调用的参数列表中的lightdm是一个跨平台的显示管理器,旨在能够启动GNOME或KDE会话。
如果你想从虚拟控制台而不是使用显示管理器启动X会话,可以运行startx或xinit命令。
然而,你得到的会话可能会非常简单,完全不像显示管理器的外观,因为机制和启动文件是不同的。
14.2.2 Network Transparency(网络透明性)
One feature of X is network transparency. Because clients talk to the server using a protocol, it’s possible to run clients across a network to a server running on a different machine directly over the network, with the X server listening for TCP connections on port 6000. Clients connecting to that port could authenticate, then send windows to the server.
X 的一个特性是网络透明性。
因为客户端使用协议与服务器通信,所以可以通过网络在不同机器上直接运行客户端到运行在另一台机器上的服务器,X 服务器监听端口 6000 上的 TCP 连接。
连接到该端口的客户端可以进行身份验证,然后将窗口发送到服务器。
Unfortunately, this method does not normally offer any encryption and is insecure as a result. To close this hole, most distributions now disable the X server’s network listener (with the -nolisten tcp option to the server, as seen in Note). However, you can still run X clients from a remote machine with SSH tunneling, as described in Chapter 10, by connecting the X server’s Unix domain socket to a socket on the remote machine.
不幸的是,这种方法通常不提供任何加密,因此是不安全的。
为了关闭这个漏洞,大多数发行版现在会禁用 X 服务器的网络监听器(通过向服务器添加 -nolisten tcp 选项,如注释中所示)。
然而,您仍然可以通过 SSH 隧道运行来自远程机器的 X 客户端,方法在第 10 章中有描述,通过将 X 服务器的 Unix 域套接字连接到远程机器上的套接字。
14.3 Exploring X Clients(探索 X Clients)
Although one doesn’t normally think of working with a graphical user interface from the command line, there are several utilities that allow you to explore the parts of the X Window System. In particular, you can inspect clients as they run.
尽管人们通常不会考虑从命令行与图形用户界面进行交互,但有几个实用程序可以让您探索 X 窗口系统的各个部分。特别是,您可以在运行时检查客户端。
One of the simplest tools is xwininfo. When run without any arguments, it asks you to click on a window:
其中一个最简单的工具是 xwininfo。当没有任何参数运行时,它会要求您点击一个窗口:
代码语言:javascript复制$ xwininfo
xwininfo: Please select the window about which you
would like information by clicking the
mouse in that window.
After you click, it prints a list of information about the window, such as its location and size:
xwininfo: Window id: 0x5400024 "xterm"
Absolute upper-left X: 1075
Absolute upper-left Y: 594
--snip--
Notice the window ID here—the X server and window managers use this identifier to keep track of windows. To get a list of all window IDs and clients, use the xlsclients -l command.
请注意这里的窗口 ID —— X 服务器和窗口管理器使用此标识符来跟踪窗口。要获取所有窗口 ID 和客户端的列表,请使用命令 xlsclients -l。
NOTE There is a special window called the root window; it’s the background on the display. However, you may never see this window (see Desktop Background). 注意:有一个特殊的窗口称为根窗口;它是显示器上的背景。但是,您可能永远看不到这个窗口(请参见桌面背景)。
14.3.1 X Events(X 事件)
X clients get their input and other information about the state of the server through a system of events. X events work like other asynchronous interprocess communication events such as udev events and D-Bus events: The X server receives information from a source such as an input device, then redistributes that input as an event to any interested X client.
X 客户端通过一种事件系统获取关于服务器状态的输入和其他信息。
X 事件的工作方式类似于其他异步进程间通信事件,比如 udev 事件和 D-Bus 事件:X 服务器从诸如输入设备之类的源接收信息,然后将该输入作为事件重新分发给任何感兴趣的 X 客户端。
You can experiment with events with the xev command. Running it opens a new window that you can mouse into, click, and type. As you do so, xev generates output describing the X events that it receives from the server. For example, here’s sample output for mouse movement:
您可以使用 xev 命令来尝试事件。运行该命令会打开一个新窗口,您可以将鼠标移动到其中,点击和输入。
在此过程中,xev 会生成描述其从服务器接收的 X 事件的输出。例如,这是鼠标移动的示例输出:
代码语言:javascript复制$ xev
--snip--
MotionNotify event, serial 36, synthetic NO, window 0x6800001,
root 0xbb, subw 0x0, time 43937883, (47,174), root:(1692,486),
state 0x0, is_hint 0, same_screen YES
MotionNotify event, serial 36, synthetic NO, window 0x6800001,
root 0xbb, subw 0x0, time 43937891, (43,177), root:(1688,489),
state 0x0, is_hint 0, same_screen YES
Notice the coordinates in parentheses. The first pair represents the x-and y-coordinates of the mouse pointer inside the window, and the second (root:) is the location of the pointer on the entire display.
注意括号中的坐标。第一对表示窗口内鼠标指针的 x 和 y 坐标,第二对 (根:) 是指针在整个显示器上的位置。
Other low-level events include key presses and button clicks, but a few more advanced ones indicate whether the mouse has entered or exited the window, or if the window has gained or lost focus from the window manager. For example, here are corresponding exit and unfocus events:
其他低级事件包括按键和按钮点击,但还有一些更高级的事件指示鼠标是否进入或离开窗口,或者窗口是否从窗口管理器获得或失去焦点。
例如,这里是相应的退出和失焦事件:
代码语言:javascript复制LeaveNotify event, serial 36, synthetic NO, window 0x6800001,
root 0xbb, subw 0x0, time 44348653, (55,185), root:(1679,420),
mode NotifyNormal, detail NotifyNonlinear, same_screen YES,
focus YES, state 0
FocusOut event, serial 36, synthetic NO, window 0x6800001,
mode NotifyNormal, detail NotifyNonlinear
One common use of xev is to extract keycodes and key symbols for different keyboards when remapping the keyboard. Here’s the output from pressing the L key; the keycode here is 46:
xev 的一个常见用途是在重新映射键盘时提取不同键盘的键码和键符号。
这是按下 L 键时的输出;这里的键码是 46:
代码语言:javascript复制KeyPress event, serial 32, synthetic NO, window 0x4c00001,
root 0xbb, subw 0x0, time 2084270084, (131,120), root:(197,172),
state 0x0, keycode 46 (keysym 0x6c, l), same_screen YES,
XLookupString gives 1 bytes: (6c) "l"
XmbLookupString gives 1 bytes: (6c) "l"
XFilterEvent returns: False
You can also attach xev to an existing window ID with the -id id option. (Use the ID that you get from xwininfo as id) or monitor the root window with -root.)
您还可以使用 -id id
选项将 xev 附加到现有窗口 ID(使用从 xwininfo 获取的 ID 作为 id)或使用 -root
监视根窗口。
14.3.2 Understanding X Input and Preference Settings(了解 X 输入和首选项设置)
One of the most potentially baffling characteristics of X is that there’s often more than one way to set preferences, and some methods may not work. For example, one common keyboard preference on Linux systems is to remap the Caps Lock key to a Control key. There are a number of ways to do this, from making small adjustments with the old xmodmap command to providing an entirely new keyboard map with the setxkbmap utility. How do you know which ones (if any) to use? It’s a matter of knowing which pieces of the system have responsibility, but determining this can be difficult. Keep in mind that a desktop environment may provide its own settings and overrides.
X 最具潜在困扰性的特征之一是通常有多种设置偏好的方式,而其中一些方法可能不起作用。
例如,在 Linux 系统上,一种常见的键盘偏好是将 Caps Lock 键重新映射为 Control 键。
有许多方法可以实现这一点,从使用旧的 xmodmap 命令进行小的调整到使用 setxkbmap 实用程序提供全新的键盘映射。
你如何知道应该使用哪种(如果有)?
这取决于了解系统的哪些部分负责,但确定这一点可能会很困难。
请记住,桌面环境可能提供自己的设置和覆盖。
With this said, here are a few pointers on the underlying infrastructure
说到这里,以下是关于基础设施的一些要点
Input Devices (General)
The X server uses the X Input Extension to manage input from many different devices. There are two basic types of input device—keyboard and pointer (mouse)—and you can attach as many devices as you like. In order to use more than one of the same type of device simultaneously, the X Input Extension creates a “virtual core” device that funnels device input to the X server. The core device is called the master; the physical devices that you plug in to the machine become slaves.
X 服务器使用 X 输入扩展来管理来自许多不同设备的输入。
有两种基本类型的输入设备——键盘和指针(鼠标)——你可以连接任意多个设备。
为了同时使用多个相同类型的设备,X 输入扩展会创建一个“虚拟核心”设备,将设备输入引导到 X 服务器。
核心设备被称为主设备;你插入机器的物理设备则成为从设备。
To see the device configuration on your machine, try running the xinput --list command:
要查看你的机器上的设备配置,请尝试运行 xinput --list 命令:
代码语言:javascript复制$ xinput --list
Virtual core pointer id=2 [master pointer (3)]
Virtual core XTEST pointer id=4 [slave pointer (2)]
Logitech Unifying Device id=8 [slave pointer (2)]
Virtual core keyboard id=3 [master keyboard (2)]
Virtual core XTEST keyboard id=5 [slave keyboard (3)]
Power Button id=6 [slave keyboard (3)]
Power Button id=7 [slave keyboard (3)]
Cypress USB Keyboard id=9 [slave keyboard (3)]
Each device has an associated ID that you can use with xinput and other commands. In this output, IDs 2 and 3 are the core devices, and IDs 8 and 9 are the real devices. Notice that the power buttons on the machine are also treated as X input devices.
每个设备都有一个相关联的ID,你可以在xinput和其他命令中使用。
在这个输出中,ID 2和3是核心设备,ID 8和9是真实设备。请注意,机器上的电源按钮也被视为X输入设备。
Most X clients listen for input from the core devices, because there is no reason for them to be concerned about which particular device originates an event. In fact, most clients know nothing about the X Input Extension. However, a client can use the extension to single out a particular device.
Each device has a set of associated properties. To view the properties, use xinput with the device number, as in this example:
大多数X客户端都监听来自核心设备的输入,因为它们不需要关心事件的具体来源设备。
事实上,大多数客户端对X输入扩展一无所知。然而,客户端可以使用该扩展来单独识别特定设备。
每个设备都有一组相关联的属性。要查看属性,请使用设备编号运行xinput,就像这个例子中那样。
代码语言:javascript复制$ xinput --list-props 8
Device 'Logitech Unifying Device. Wireless PID:4026':
Device Enabled (126): 1
Coordinate Transformation Matrix (128): 1.000000, 0.000000,
0.000000,
0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
Device Accel Profile (256): 0
Device Accel Constant Deceleration (257): 1.000000
Device Accel Adaptive Deceleration (258): 1.000000
Device Accel Velocity Scaling (259): 10.000000
--snip--
As you can see, there are a number of very interesting properties that you can change with the --set-prop option (See the xinput(1) manual page for more information.)
正如您所看到的,您可以使用--set-prop选项更改许多非常有趣的属性(有关更多信息,请参阅xinput(1)手册页。)
Mouse(鼠标)
You can manipulate device-related settings with the xinput command, and many of the most useful pertain to the mouse (pointer). You can change many settings directly as properties, but it’s usually easier with the specialized --set-ptr-feedback and --set-button-map options to xinput. For example, if you have a three-button mouse at dev on which you’d like to reverse the order of buttons (this is handy for lefthanded users), try this:
您可以使用xinput命令操纵与设备相关的设置,其中许多最有用的设置与鼠标(指针)有关。
您可以直接将许多设置更改为属性,但通常使用专门的--set-ptr-feedback和--set-button-map选项更容易。
例如,如果您有一个三按钮鼠标设备,在该设备上您想要颠倒按钮的顺序(这对左撇子用户很方便),请尝试以下操作:
代码语言:javascript复制$ xinput --set-button-map dev 3 2 1
Keyboard(键盘)
The many different keyboard layouts available internationally present particular difficulties for integration into any windowing system. X has always had an internal keyboard-mapping capability in its core protocol that you can manipulate with the xmodmap command, but any reasonably modern system uses the XKB (the X keyboard extension) to gain finer control.
国际上提供的许多不同键盘布局在集成到任何窗口系统中都会带来特定的困难。
X一直在其核心协议中具有内部键盘映射功能,您可以使用xmodmap命令进行操作,但是任何相当现代的系统都使用XKB(X键盘扩展)来获得更精细的控制。
XKB is complicated, so much so that many people still use xmodmap when they need to make quick changes. The basic idea behind XKB is that you can define a keyboard map and compile it with the xkbcomp command, then load and activate that map in the X server with the setxkbmap command. Two especially interesting features of the system are these:
XKB非常复杂,以至于许多人在需要快速更改时仍然使用xmodmap。
XKB背后的基本思想是,您可以定义一个键盘映射,然后使用xkbcomp命令编译它,最后使用setxkbmap命令在X服务器中加载和激活该映射。
系统中两个特别有趣的特性是:
o You can define partial maps to supplement existing maps. This is especially handy for tasks such as changing your Caps Lock key into a Control key, and it is used by many graphical keyboard preference utilities in desktop environments. o You can define individual maps for each attached keyboard
- 您可以定义部分映射以补充现有映射。这对于诸如将大写锁定键更改为控制键之类的任务特别方便,并且被许多桌面环境中的图形键盘首选项实用程序使用。
- 您可以为每个连接的键盘定义单独的映射。
Desktop Background(桌面背景)
The old X command xsetroot allows you to set the background color and other characteristics of the root window, but it produces no effect on most machines because the root window is never visible. Instead, most desktop environments place a big window in the back of all of your other windows in order to enable features such as “active wallpaper” and desktop file browsing. There are ways to change the background from the command line (for example, with the gsettings command in some GNOME installations), but if you actually want to do this, you probably have too much time on your hands.
旧的 X 命令 xsetroot 允许你设置根窗口的背景颜色和其他特性,但在大多数机器上却没有任何效果,因为根窗口从未可见。
相反,大多数桌面环境会在所有其他窗口的后面放置一个大窗口,以启用诸如“活动壁纸”和桌面文件浏览等功能。
有一些方法可以通过命令行更改背景(例如,在某些 GNOME 安装中使用 gsettings 命令),但如果你真的想这样做,那你可能有太多的空闲时间了。
xset
Probably the oldest preference command is xset. It’s not used much anymore, but you can run a quick xset q to get the status of a few features. Perhaps the most useful are the screensaver and Display Power Management Signaling (DPMS) settings.
可能是最古老的偏好命令是 xset。
它现在用得不多了,但你可以运行快速的 xset q 来获取一些功能的状态。
也许最有用的是屏幕保护程序和显示电源管理信号(DPMS)设置。
14.4 The Future of X(X的未来)
As you were reading the preceding discussion, you may have gotten the feeling that X is a really old system that’s been poked at a lot in order to get it to do new tricks. You wouldn’t be far off. The X Window System was first developed in the 1980s. Although its evolution over the years has been significant (flexibility was an important part of its original design), you can push the original architecture only so far
当您阅读前面的讨论时,您可能会觉得X是一个非常古老的系统,经过了很多改动才能做出新的功能。您的想法并没有错。
X Window 系统最初是在1980年代开发的。
尽管多年来它的发展是显著的(灵活性是其原始设计的重要部分),但您只能让原始架构走得这么远。
One sign of the age of the X Window System is that the server itself supports an extremely large number of libraries, many for backward compatibility. But perhaps more significantly, the idea of having a server manage clients, their windows, and act as an intermediary for the window memory has become a burden on performance. It’s much faster to allow applications to render the contents of their windows directly in the display memory, with a lighter-weight window manager, called a compositing window manager, to arrange the windows and do minimal management of the display memory.
X Window 系统年代久远的一个迹象是服务器本身支持数量极多的库,其中很多是为了向后兼容。
但更重要的是,让服务器管理客户端、它们的窗口,并作为窗口内存的中介已经成为性能的负担。
让应用程序直接在显示内存中呈现窗口内容,辅以轻量级窗口管理器(称为合成窗口管理器)来排列窗口并最小化显示内存的管理,会更快速。
A new standard based on this idea, Wayland, has started to gain traction. The most significant piece of Wayland is a protocol that defines how clients talk to the compositing window manager. Other pieces include input device management and an X-compatibility system. As a protocol, Wayland also maintains the idea of network transparency. Many pieces of the Linux desktop now support Wayland, such as GNOME and KDE.
基于这个想法的一个新标准,Wayland,已经开始受到关注。
Wayland最重要的部分是定义客户端如何与合成窗口管理器交流的协议。
其他部分包括输入设备管理和一个X兼容系统。
作为一个协议,Wayland也保持了网络透明性的概念。
许多Linux桌面的部分现在支持Wayland,比如GNOME和KDE。
But Wayland isn’t the only alternative to X. As of this writing, another project, Mir, has similar goals, though its architecture takes a somewhat different approach. At some point, there will be widespread adoption of at least one system, which may or may not be one of these.
但Wayland并不是X的唯一替代方案。
截至目前,另一个项目Mir也有类似的目标,尽管其架构采取了稍有不同的方式。
在某个时候,至少会有一种系统被广泛采用,可能是这些系统之一,也可能不是。
These new developments are significant because they won’t be limited to the Linux desktop. Due to its poor performance and gigantic footprint, the X Window System is not suitable for environments such as tablets and smartphones, so manufacturers have so far used alternative systems to drive embedded Linux displays. However, standardized direct rendering can make for a more cost-effective way to support these displays.
这些新发展是重要的,因为它们不会仅限于Linux桌面。
由于X Window系统性能差且占用空间巨大,不适合平板电脑和智能手机等环境,因此制造商迄今为止一直使用替代系统来驱动嵌入式Linux显示器。
然而,标准化的直接渲染可以提供更具成本效益的方式来支持这些显示器。
14.5 D-Bus
One of the most important developments to come out of the Linux desktop is the Desktop Bus (D-Bus), a message-passing system. D-Bus is important because it serves as an interprocess communication mechanism that allows desktop applications to talk to each other, and because most Linux systems use it to notify processes of system events, such as inserting a USB drive.
Linux 桌面环境中最重要的发展之一是桌面总线(D-Bus),一个消息传递系统。
D-Bus 很重要,因为它作为一个进程间通信机制,允许桌面应用程序相互通信,并且因为大多数 Linux 系统使用它来通知进程系统事件,比如插入 USB 驱动器。
D-Bus itself consists of a library that standardizes interprocess communication with a protocol and supporting functions for any two processes to talk to each other. By itself, this library doesn’t offer much more than a fancy version of normal IPC facilities such as Unix domain sockets. What makes D-Bus useful is a central “hub” called dbus-daemon. Processes that need to react to events can connect to dbus-daemon and register to receive certain kinds of events. Processes also create the events. For example, the process udisksdaemon listens to ubus for disk events and sends them to dbus-daemon, which then retransmits the events to applications interested in disk events.
D-Bus 本身包括一个库,标准化了进程间通信的协议和支持函数,使得任意两个进程可以相互通信。
单独来看,这个库并没有提供比普通 IPC 设施(比如 Unix 域套接字)更多的功能。
使 D-Bus 有用的是一个称为 dbus-daemon 的中央“枢纽”。需要对事件做出反应的进程可以连接到 dbus-daemon 并注册以接收某种类型的事件。进程也会创建事件。例如,进程 udisks-daemon 监听 ubus 的磁盘事件并将其发送到 dbus-daemon,后者然后将事件转发给对磁盘事件感兴趣的应用程序。
14.5.1 System and Session Instances(系统和会话实例)
D-Bus has become a more integral part of the Linux system, and it now goes beyond the desktop. For example, both systemd and Upstart have D-Bus channels of communication. However, adding dependencies to desktop tools inside the core system goes against a core design rule of Linux.
D-Bus 已经成为 Linux 系统更为重要的一部分,现在已经超越了桌面。例如,systemd 和 Upstart 都有 D-Bus 通信渠道。
然而,在核心系统中添加桌面工具的依赖关系违反了 Linux 的核心设计原则。
To address this problem, there are actually two kinds of dbus-daemon instances (processes) that can run. The first is the system instance, which is started by init at boot time with the --system option. The system instance usually runs as a D-Bus user, and its configuration file is /etc/dbus-1/system.conf (though you probably shouldn’t change the configuration). Processes can connect to the system instance through the /var/run/dbus/system_bus_socket Unix domain socket.
为了解决这个问题,实际上有两种可以运行的 dbus-daemon 实例(进程)。
第一种是系统实例,它由 init 在启动时使用 --system 选项启动。
系统实例通常以 D-Bus 用户身份运行,其配置文件是 /etc/dbus-1/system.conf(尽管您可能不应更改配置)。
进程可以通过 /var/run/dbus/system_bus_socket Unix 域套接字连接到系统实例。
Independent of the system D-Bus instance, there is an optional session instance that runs only when you start a desktop session. Desktop applications that you run connect to this instance.
与系统 D-Bus 实例无关,还有一个可选的会话实例,只有在启动桌面会话时才会运行。
您运行的桌面应用程序会连接到这个实例。
14.5.2 Monitoring D-Bus Messages(监控 D-Bus 消息)
One of the best ways to see the difference between the system and session dbus-daemon instances is to monitor the events that go over the bus. Try using the dbus-monitor utility in system mode like this:
要了解系统和会话 dbus-daemon 实例之间的区别,最好的方法之一是监视通过总线传输的事件。
尝试像这样在系统模式下使用 dbus-monitor 实用程序:
代码语言:javascript复制$ dbus-monitor --system
signal sender=org.freedesktop.DBus -> dest=:1.952 serial=2 path=/org/
freedesktop/DBus; interface=org.freedesktop.DBus; member=NameAcquired
string ":1.952"
The startup message here indicates that the monitor connected and acquired a name. You shouldn’t see much activity when you run it like this, because the system instance usually isn’t very busy. To see something happen, try plugging in a USB storage device.
这里的启动消息表示监视器已连接并获取了一个名称。
当您像这样运行它时,您不应该看到太多活动,因为系统实例通常不太忙碌。
要看到一些活动,请尝试插入一个 USB 存储设备。
By comparison, session instances have much more to do. Assuming you’ve logged in to a desktop session, try this:
相比之下,会话实例要做的事情要多得多。
假设您已经登录到一个桌面会话,请尝试这样做:
代码语言:javascript复制$ dbus-monitor --session
Now move your mouse around to different windows; if your desktop is D-Bus aware, you should get a flurry of messages indicating activated windows.
现在移动鼠标到不同的窗口中;如果您的桌面支持 D-Bus,您应该会收到一系列指示已激活窗口的消息。
14.6 Printing(打印)
Printing a document on Linux is a multistage process. It goes like this:
在 Linux 上打印文档是一个多阶段的过程。步骤如下:
- The program doing the printing usually converts the document into PostScript form. This step is optional.
- The program sends the document to a print server.
- The print server receives the document and places it on a print queue.
- When the document’s turn in the queue arrives, the print server sends the document to a print filter.
- If the document is not in PostScript form, a print filter might perform a conversion.
- If the destination printer does not understand PostScript, a printer driver converts the document to a printer-compatible format.
- The printer driver adds optional instructions to the document, such as paper tray and duplexing options.
- The print server uses a backend to send the document to the printer.
- 进行打印的程序通常会将文档转换为 PostScript 格式。这一步骤是可选的。
- 程序将文档发送到打印服务器。
- 打印服务器接收文档并将其放置在打印队列中。
- 当文档在队列中轮到时,打印服务器会将文档发送到打印过滤器。
- 如果文档不是以 PostScript 形式存在,打印过滤器可能会执行转换。
- 如果目标打印机不理解 PostScript,打印机驱动程序会将文档转换为打印机兼容的格式。
- 打印机驱动程序会向文档添加可选的指令,例如纸盒和双面打印选项。
- 打印服务器使用后端将文档发送到打印机。
The most confusing part of this process is why so much revolves around PostScript. PostScript is actually a programming language, so when you print a file using it, you’re sending a program to the printer. PostScript serves as a standard for printing in Unix-like systems, much as the .tar format serves as an archiving standard. (Some applications now use PDF output, but this is relatively easy to convert.)
这个过程最令人困惑的部分是为什么这么多环节与 PostScript 有关。
PostScript 实际上是一种编程语言,因此当你使用它打印文件时,实际上是将一个程序发送到打印机。
PostScript 在类 Unix 系统中用作打印的标准,就像 .tar 格式用作存档标准一样。
(一些应用程序现在使用 PDF 输出,但这相对容易转换。)
We’ll talk more about the print format later; first, let’s look at the queuing system.
我们稍后会详细讨论打印格式;首先,让我们看看队列系统。
14.6.1 CUPS
The standard printing system in Linux is CUPS (http://www.cups.org/), which is the same system used on Mac OS X. The CUPS server daemon is called cupsd, and you can use the lpr command as a simple client to send files to the daemon.
Linux 中的标准打印系统是 CUPS(http://www.cups.org/),这也是 Mac OS X 上使用的系统。
CUPS 服务器守护程序称为 cupsd,您可以使用 lpr 命令作为简单的客户端将文件发送到守护程序。
One significant feature of CUPS is that it implements Internet Print Protocol (IPP), a system that allows for HTTP-like transactions among clients and servers on TCP port 631. In fact, if you have CUPS running on your system, you can probably connect to http://localhost:631/ to see your current configuration and check on any printer jobs. Most network printers and print servers support IPP, as does Windows, which can make setting up remote printers a relatively simple task.
CUPS 的一个重要特性是它实现了 Internet 打印协议(IPP),这是一种允许客户端和服务器在 TCP 端口 631 上进行类似 HTTP 的交易的系统。
事实上,如果您的系统上运行着 CUPS,您可能可以连接到 http://localhost:631/ 查看当前配置并检查任何打印作业。
大多数网络打印机和打印服务器都支持 IPP,Windows 也支持,这可以使设置远程打印机相对简单。
You probably won’t be able to administer the system from the web interface, because the default setup isn’t very secure. Instead, your distribution likely has a graphical settings interface to add and modify printers. These tools manipulate the configuration files, normally found in /etc/cups. It’s usually best to let these tools do the work for you, because configuration can be complicated. And even if you do run into a problem and need to configure manually, it’s usually best to create a printer using the graphical tools so that you have somewhere to start.
您可能无法通过 Web 界面管理系统,因为默认设置并不太安全。
相反,您的发行版可能有一个图形化设置界面来添加和修改打印机。
这些工具操作配置文件,通常位于 /etc/cups。
最好让这些工具为您完成工作,因为配置可能会很复杂。
即使遇到问题需要手动配置,最好还是使用图形化工具创建打印机,这样您就有了一个起点。
14.6.2 Format Conversion and Print Filters(格式转换和打印过滤器)
Many printers, including nearly all low-end models, do not understand PostScript or PDF. In order for Linux to support one of these printers, it must convert documents to a format specific to the printer. CUPS sends the document to a Raster Image Processor (RIP) to produce a bitmap. The RIP almost always uses the Ghostscript (gs) program to do most of the real work, but it’s somewhat complicated because the bitmap must fit the format of the printer. Therefore, the printer drivers that CUPS uses consult the PostScript Printer Definition (PPD) file for the specific printer to figure out settings such as resolution and paper sizes
许多打印机,包括几乎所有低端型号,不理解 PostScript 或 PDF。为了让 Linux 支持其中一台打印机,必须将文档转换为特定于打印机的格式。
CUPS 将文档发送到光栅图像处理器(RIP)以生成位图。RIP 几乎总是使用 Ghostscript(gs)程序来完成大部分实际工作,但由于位图必须符合打印机的格式,所以有些复杂。
因此,CUPS 使用的打印机驱动程序会查阅特定打印机的 PostScript 打印机定义(PPD)文件,以确定分辨率和纸张尺寸等设置。
14.7 Other Desktop Topics(其他桌面主题)
One interesting characteristic of the Linux desktop environment is that you can generally choose which pieces you want to use and stop using the ones that you dislike. For a survey of many of the desktop projects, have a look at the mailing lists and project links for the various projects at http://www.freedesktop.org/. Elsewhere, you’ll find other desktop projects, such as Ayatana, Unity, and Mir. Another major development in the Linux desktop is the Chromium OS open source project and its Google Chrome OS counterpart found on Chromebook PCs. This is a Linux system that uses much of the desktop technology described in this chapter but is centered around the Chromium/ Chrome web browsers. Much of what’s found on a traditional desktop has been stripped away in Chrome OS.
Linux 桌面环境的一个有趣特点是,通常您可以选择要使用的组件,并停止使用您不喜欢的组件。
要了解许多桌面项目的概况,请查看 http://www.freedesktop.org/ 上各项目的邮件列表和项目链接。
此外,您还会发现其他桌面项目,如 Ayatana、Unity 和 Mir。
Linux 桌面的另一个重大发展是 Chromium OS 开源项目及其在 Chromebook 个人电脑上找到的 Google Chrome OS 对应项目。
这是一个使用本章描述的许多桌面技术的 Linux 系统,但其核心是围绕 Chromium/Chrome 网页浏览器。
Chrome OS 剥离了传统桌面上的许多内容。
欢迎关注公众号获取更多优质内容