Xorg (简体中文)
- X.Org 项目提供了 X 窗口系统的开源实现。开发工作实在 freedesktop.org 社区的通力合作下完成。X.Org 组织是非盈利教育机构,其董事会为这项工作服务,其成员领导这项工作。
Xorg (通常简称为 X)在 Linux 用户中非常流行,已经成为图形用户程序的必备条件,所以大部分发行版都提供了它。详情参见 Xorg 维基文章或访问Xorg 网站。
安装
安装 软件包 xorg-server。
此外,xorg-apps 组提供了一些程序以完成某些特定的配置工作。
软件包组 xorg 包含了 Xorg server,xorg-apps 中的软件包以及字体.
驱动安装
Linux 内核包含了开源的视频驱动,支持硬件加速。OpenGL 和 X11 的 2D 加速需要用户空间工具。
执行如下命令查询显卡类型:
$ lspci | grep -e VGA -e 3D
安装对应的驱动,输入下面命令,查看所有开源驱动:
$ pacman -Ss xf86-video
Xorg 会自动搜索安装的驱动:
- 如果无法找到设备在下表中列出的驱动,会首先查看是否安装了 fbdev (xf86-video-fbdev).
- 如果依然没有找到,会搜索 vesa (xf86-video-vesa), 这是一个支持大部分显卡的通用驱动,不提供任何 2D 和 3D 加速功能。
- 如果没有找到 vesa,Xorg 会使用 kernel mode setting, 这个驱动提供了 GLAMOR 加速 (参考 modesetting(4)).
要充分发挥显卡性能,请按下表安装驱动程序。推荐先使用开源驱动,这些驱动出问题的可能性较小。
厂商 | 类型 | 驱动 | OpenGL | OpenGL (multilib) | 文档 |
---|---|---|---|---|---|
AMD / ATI | Open source | xf86-video-amdgpu | mesa | lib32-mesa | AMDGPU |
xf86-video-ati | ATI | ||||
Intel | Open source | xf86-video-intel | mesa | lib32-mesa | Intel graphics |
NVIDIA | Open source | xf86-video-nouveau | mesa | lib32-mesa | Nouveau |
Proprietary | nvidia | nvidia-utils | lib32-nvidia-utils | NVIDIA | |
nvidia-390xxAUR | nvidia-390xx-utilsAUR | lib32-nvidia-390xx-utilsAUR |
- 对于同时使用集成显卡和独立显卡的 NVIDIA Optimus 笔记本,请参考 NVIDIA Optimus。
- 对于第四代及更新的 Intel 显卡,阅读英特尔显卡#安装来获取可用驱动。
其它驱动也都位于 xorg-drivers 软件包组中.
没有闭源驱动,Xorg 也应正常工作。闭源驱动的典型用途是某些高级图形功能例如为游戏提供 3D 渲染加速。某些例外是某些最新的 GPU (尤其是 NVIDIA 的 GPU),它们不受开源驱动支持。
AMD
GPU 架构 | Radeon 显卡 | 开源驱动 | 非开源驱动 |
---|---|---|---|
GCN 4 及之后 |
多种 | AMDGPU | AMDGPU PRO |
GCN 3 | AMDGPU | Catalyst / AMDGPU PRO | |
GCN 2* | AMDGPU* / ATI | Catalyst | |
GCN 1* | AMDGPU* / ATI | Catalyst | |
TeraScale 2&3 | HD 5000 - HD 6000 | ATI | Catalyst |
TeraScale 1 | HD 2000 - HD 4000 | Catalyst legacy | |
旧型号 | X1000及之前 | 不支持 |
- *: AMDGPU 实验支持
运行
Xorg(1)命令通常不直接运行。要么使用显示管理器,要么使xinit来启动 X server。
配置
/usr/share/X11/xorg.conf.d
的默认配置文件。通常情况下,用户无需进行额外的配置与修改即可正常使用。Xorg 使用名为 xorg.conf
的配置文件和后缀为 .conf
的文件作为它的初始设置。这些文件的位置的完整列表可以在xorg.conf(5)中找到,其中还附有全部可用选项的详尽解释。
使用 .conf 文件
/etc/X11/xorg.conf.d/
目录保存主机特有设置,你可以创建自己的配置文件,需要以 XX-
开头(XX 是数字)并以.conf
结尾(例如 10 在 20 之前读取).X 服务器启动是会解析这些文件,将其视为 xorg.conf
的一部分进行处理。如果配置之间有冲突,将会使用最后被处理的文件。所以通用的设置应该放到前面。最后会解析 xorg.conf
文件。
设置请参考 Fedora wiki.
使用 xorg.conf
可以通过 /etc/X11/xorg.conf
或 /etc/xorg.conf
配置 Xorg,用下面命令可以生成 xorg.conf
模板:
# Xorg :0 -configure
执行后会在 /root/
生成 xorg.conf.new
文件,然后你可以将它复制到 /etc/X11/xorg.conf
。
Xorg :2 -configure
。或者,显卡的专有驱动可能也提供了自动配置 Xorg 的工具,详情请参考 NVIDIA 或 AMD Catalyst。
输入设备
X 服务器默认使用 libinput 驱动(xf86-input-libinput) 处理输入设备,xf86-input-evdev 和相关驱动是后备方案[1]。
Udev,作为 systemd 的依赖项被提供,将会检测硬件。这两个驱动程序将作为几乎所有设备的热插拔输入驱动,它们的行为定义在位于 /usr/share/X11/xorg.conf.d/
的默认配置文件 10-quirks.conf
and 40-libinput.conf
中。
在启动 X server 后,日志文件将会为每个设备显示发生了什么热插拔(注意最近的日志名称可能有所不同):
$ grep -e "Using input driver " Xorg.0.log
如果两个驱动都不支持您的设备, 请从xorg-drivers 组安装需要的驱动程序。如果你想要使用其他驱动,也可以这样做。
想要干预热插拔,请参考 #配置。
更详细的信息,请参考 libinput ,文后的链接,和 Fedora wiki。
输入映射
参考键盘按键#映射按键码。
鼠标加速
鼠标加速。
扩展鼠标按键
鼠标按键。
触摸板
参考 Libinput (简体中文) 或 Touchpad_Synaptics。
触摸屏
触摸屏。
键盘设置
参考 Xorg/Keyboard configuration。
显示器设置
开始
无头配置需要 xf86-video-dummy 驱动; 安装然后创建一个配置文件,例如:
/etc/X11/xorg.conf.d/10-headless.conf
Section "Monitor" Identifier "dummy_monitor" HorizSync 28.0-80.0 VertRefresh 48.0-75.0 Modeline "1920x1080" 172.80 1920 2040 2248 2576 1080 1081 1084 1118 EndSection Section "Device" Identifier "dummy_card" VideoRam 256000 Driver "dummy" EndSection Section "Screen" Identifier "dummy_screen" Device "dummy_card" Monitor "dummy_monitor" SubSection "Display" EndSubSection EndSection
多个显示器
参考主要文章 多头 了解通用信息。
参见GPU的具体说明:
- NVIDIA (简体中文)#多台显示器
- Nouveau (简体中文)#双输出
- AMD Catalyst#Double Screen (Dual Head / Dual Screen / Xinerama)
- ATI#Multihead setup
多于一个显卡
你必须指定正确的驱动,输入你的显卡的 bus ID(以十进制表示)。
Section "Device" Identifier "Screen0" Driver "intel" BusID "PCI:0:2:0" EndSection Section "Device" Identifier "Screen1" Driver "nouveau" BusID "PCI:1:0:0" EndSection
为了获取 BusID (十六进制):
$ lspci | grep -e VGA -e 3D
00:02.0 VGA compatible controller: Intel Corporation HD Graphics 630 (rev 04) 01:00.0 3D controller: NVIDIA Corporation GP107M [GeForce GTX 1050 Mobile] (rev a1)
这个示例的BusID是 0:2:0 和 1:0:0。
显示大小和 DPI
The DPI of the X server is determined in the following manner:
- dpi命令行选项具有最高优先级。
- If this is not used, the DisplaySize setting in the X config file is used to derive the DPI, given the screen resolution.
- If no DisplaySize is given, the monitor size values from DDC are used to derive the DPI, given the screen resolution.
- 如果DDC不指定大小, 75 DPI默认使用。
In order to get correct dots per inch (DPI) set, the display size must be recognized or set. Having the correct DPI is especially necessary where fine detail is required (like font rendering). Previously, manufacturers tried to create a standard for 96 DPI (a 10.3" diagonal monitor would be 800x600, a 13.2" monitor 1024x768). These days, screen DPIs vary and may not be equal horizontally and vertically. For example, a 19" widescreen LCD at 1440x900 may have a DPI of 89x87. To be able to set the DPI, the Xorg server attempts to auto-detect your monitor's physical screen size through the graphic card with DDC. When the Xorg server knows the physical screen size, it will be able to set the correct DPI depending on resolution size.
To see if your display size and DPI are detected/calculated correctly:
$ xdpyinfo | grep -B2 resolution
Check that the dimensions match your display size. If the Xorg server is not able to correctly calculate the screen size, it will default to 75x75 DPI and you will have to calculate it yourself.
If you have specifications on the physical size of the screen, they can be entered in the Xorg configuration file so that the proper DPI is calculated:
Section "Monitor" Identifier "Monitor0" DisplaySize 286 179 # In millimeters EndSection
If you only want to enter the specification of your monitor without creating a full xorg.conf create a new config file. For example (/etc/X11/xorg.conf.d/90-monitor.conf
):
Section "Monitor" Identifier "<default monitor>" DisplaySize 286 179 # In millimeters EndSection
If you do not have specifications for physical screen width and height (most specifications these days only list by diagonal size), you can use the monitor's native resolution (or aspect ratio) and diagonal length to calculate the horizontal and vertical physical dimensions. Using the Pythagorean theorem on a 13.3" diagonal length screen with a 1280x800 native resolution (or 16:10 aspect ratio):
$ echo 'scale=5;sqrt(1280^2+800^2)' | bc # 1509.43698
This will give the pixel diagonal length and with this value you can discover the physical horizontal and vertical lengths (and convert them to millimeters):
$ echo 'scale=5;(13.3/1509)*1280*25.4' | bc # 286.43072 $ echo 'scale=5;(13.3/1509)*800*25.4' | bc # 179.01920
手动设置DPI
For RandR compliant drivers (for example the open source ATI driver), you can set it by:
$ xrandr --dpi 144
See Execute commands after X start to make it permanent.
专有的NVIDIA驱动程序
DPI can be set manually if you only plan to use one resolution (DPI calculator):
Section "Monitor" Identifier "Monitor0" Option "DPI" "96 x 96" EndSection
You can manually set the DPI adding the options below on /etc/X11/xorg.conf.d/20-nvidia.conf
(inside Device section):
Option "UseEdidDpi" "False" Option "DPI" "96 x 96"
DPMS
DPMS (显示器电源管理信号) 是一种技术,可以在计算机不使用时,可以使用显示器的省电行为. 这将允许您的显示器在预定时间段后自动进入待机。
合成
X 的合成扩展使窗口层次结构的整个子树呈现到屏幕外的缓冲区。应用程序可以获取缓冲区的内容并执行它们喜欢的任何操作。屏幕外的缓冲区可以自动合并到父窗口中,也可以被称为合成管理器的外部程序合并。要了解更多信息,参考compositing window manager
某些窗口管理器(例如 Compiz, Enlightenment, KWin, Marco, Metacity, Muffin, Mutter, Xfwm)自己完成这些合成。对于其他窗口管理器,可以使用一个独立的合成管理器。
合成管理器列举
- Picom — 合成器(Compton 的一个分支)
- Xcompmgr — 复合窗口效果管理器
- Unagi — 致力于用C语言编写,基于 XCB 的模块化合成管理器
技巧和技巧
自动化
这一节列出用于键盘、鼠标输入和窗口操作自动化的实用程序(例如移动、调整大小和层级)。
工具 | 软件包 | 手册 | keyboard input | 窗口操作 | 注 |
---|---|---|---|---|---|
xautomation | xautomation | xte(1) | Yes | No | 也包含 screen scraping tools。无法模拟 F13+. |
xdo | xdo | xdo(1) | No | Yes | 用于执行基本窗口操作的轻量级X实用工具 |
xdotool | xdotool | xdotool(1) | Yes | Yes | 充满 Bug 且开发不活跃,比如说CLI解析错误。[2][3] |
xvkbd | xvkbdAUR | xvkbd(1) | Yes | No | 面向 Xorg 的虚拟键盘,在发送字母时也有 -text 选项。
|
也可以参考 Clipboard#Tools and an overview of X automation tools.
嵌套 X 会话
在嵌套的 X 的会话中启动其他桌面环境:
$ /usr/bin/Xnest :1 -geometry 1024x768+0+0 -ac -name Windowmaker & wmaker -display :1
这会在你当前的 X 会话中启动一个1024 × 768大小的 Window Maker 会话。
需要安装xorg-server-xnest。
远程启动 GUI 程序
查看主条目:X11转发。
按需禁用和启用输入源
利用xinput你可以您可以暂时禁用或启用输入源。这可能很有用,例如,在具有多个鼠标的系统上(如ThinkPad),可以只使用一个鼠标以避免不必要的点击。
从official repositories安装 xorg-xinput。
找到要禁用的设备的ID:
$ xinput
例如在Lenovo ThinkPad T500中,输出如下所示:
$ xinput
⎡ Virtual core pointer id=2 [master pointer (3)] ⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)] ⎜ ↳ TPPS/2 IBM TrackPoint id=11 [slave pointer (2)] ⎜ ↳ SynPS/2 Synaptics TouchPad id=10 [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)] ↳ Video Bus id=7 [slave keyboard (3)] ↳ Sleep Button id=8 [slave keyboard (3)] ↳ AT Translated Set 2 keyboard id=9 [slave keyboard (3)] ↳ ThinkPad Extra Buttons id=12 [slave keyboard (3)]
使用xinput --disable device_id
禁用设备,device_id是你要禁用的设备的ID。在此示例中,我们将禁用ID为10的Synaptics触摸板:
$ xinput --disable 10
要重新启用该设备,只需发出相反的命令:
$ xinput --enable 10
使用热建结束应用程序
在热键上运行脚本:
#!/bin/bash windowFocus=$(xdotool getwindowfocus); pid=$(xprop -id $windowFocus | grep PID); kill -9 $pid
阻止 TTY 访问
要在X中阻止tty访问,请将以下内容添加到xorg.conf:
Section "ServerFlags" Option "DontVTSwitch" "True" EndSection
防止用户结束 X
要防止用户在运行时被结束,请将以下内容添加到xorg.conf:
Section "ServerFlags" Option "DontZap" "True" EndSection
没有 root 权限的 Xorg
Xorg 可以使用标准用户权限而不是 root 来运行(所谓的“rootless” Xorg)。这对于用 root 权限运行是很大的安全性提升。注意大多数显示管理器都不支持 rootless Xorg。
你可以用 Template:Ps -o user $(pgrep Xorg) 来验证 Xorg 在以什么用户的身份运行。
也可参考Xorg.wrap(1), systemd-logind(8), Systemd/User#Xorg as a systemd user service, [4] and FS#41257。
Using xinitrc
To configure rootless Xorg using xinitrc:
- Run startx as a subprocess of the login shell; run
startx
directly and do not useexec startx
. - If using certain proprietary display drivers, kernel mode setting auto-detection will fail. In such cases, you must set
needs_root_rights = no
in/etc/X11/Xwrapper.config
.
Using GDM
GDM will run Xorg without root privileges by default when kernel mode setting is used.
Session log redirection
When Xorg is run in rootless mode, Xorg logs are saved to ~/.local/share/xorg/Xorg.log
. However, the stdout and stderr output from the Xorg session is not redirected to this log. To re-enable redirection, start Xorg with the -keeptty
flag and redirect the stdout and stderr output to a file:
startx -- -keeptty &> ~/.xorg.log
Alternatively, copy /etc/X11/xinit/xserverrc
to ~/.xserverrc
, and append -keeptty
. See [5].
故障和修复
通用问题
如果你在使用Xorg中遇到问题, 查看位于 /var/log/
的日志,或者对于从 v1.16 起的无 root X,位于 ~/.local/share/xorg/
。 GDM 用户应当检查 systemd journal. [6]
日志文件的格式为 Xorg.n.log
, 其中 n
表示显示器编号。对于单用户、使用默认配置文件的机器,日志文件常常是 Xorg.0.log
,其它情形可能会有区别。 想要找到正确的文件,可以考虑检查 X 服务器会话启动的时间戳以及它是从哪个控制台启动的。例如:
$ grep -e Log -e tty Xorg.0.log
[ 40.623] (==) Log file: "/home/archuser/.local/share/xorg/Xorg.0.log", Time: Thu Aug 28 12:36:44 2014 [ 40.704] (--) controlling tty is VT number 1, auto-enabling KeepTty
- 在日志文件中寻找以
(EE)
开头的行,它代表错误,以及(WW)
,代表警告(可能暗示着其他问题)。 - 如果在你的
$HOME
里有一个空的.xinitrc
文件,删除或修改它以使 X 正确启动。如果你不这样做,X 会显示黑屏并不会在Xorg.0.log
中输出任何错误。简单地删除它就可以使 X 以默认配置运行。 - 如果你遇到黑屏,你仍可以尝试切换到不同的虚拟控制台 (例如
Ctrl+Alt+F6
),然后不假思索地以 root 登录。你可以通过输入root
(然后按下Enter
) 然后输入密码(同样地,输入后按下Enter
)。
- 你也可以尝试这样杀死 X server:
# pkill -x X
- 如果不行,直接重启:
# reboot
- 如果你有关于键盘,鼠标,触摸板等等的问题,参考 Category:Input devices 中具体的文章。
- 最后,在ATI, Intel和NVIDIA等文章中搜索常见问题。
黑屏,没有指定协议..,资源暂时不可用等问题
X在当前用户的主目录中创建配置和临时文件。确保主目录所在的分区上有可用的可用磁盘空间。然而,在这种情况下,X服务器不提供有关磁盘空间不足的更明显信息。
Matrox显卡的DRI功能失效
如果你使用的是Matrox显卡,在升级到Xorg7后它的DRI功能失效,试着在xorg.conf的显卡设备设置段Device section中加入下面一行:
Option "OldDmaInit" "On"
无法运行在frambuffer模式下
如果X启动失败,日志中有以下信息:
(WW) Falling back to old probe method for fbdev (II) Loading sub module "fbdevhw" (II) LoadModule: "fbdevhw" (II) Loading /usr/lib/xorg/modules/linux//libfbdevhw.so (II) Module fbdevhw: vendor="X.Org Foundation" compiled for 1.6.1, module version = 0.0.2 ABI class: X.Org Video Driver, version 5.0 (II) FBDEV(1): using default device Fatal server error: Cannot run in framebuffer mode. Please specify busIDs for all framebuffer devices
只需要卸载xf86-video-fbdev就可以了。
无法加载'(null)'字体
- 一些程序无法运行,提示无法加载`(null)'字体.
这些软件包可能需要一些额外的字体。某些程序只能使用位图字体。 目前有两种主要的位图字体包:xorg-fonts-75dpi、xorg-fonts-100dpi。选择其中一个就可以了。通过下面这个命令查看显示设置:
$ xdpyinfo | grep resolution
根据显示信息选择合适dpi的字体即可(用75 或 100 代替XX):
# pacman -S xorg-fonts-XXdpi
修复:在出现GUI登录界面之前,不启动Xorg
如果Xorg设置为自动启动并且出于某些原因你不想让它出现在 登录/显示 管理器之前,有两种办法:
- 将启动目标修改为 rescue.target. 参阅 systemd#Change default target to boot into.
- 如果 X 无法启动,而且 GRUB 超时时间设置成了 0,无法进 Grub 禁止 Xorg boot. 可以使用 Arch CD 启动,然后挂载配置文件所在分区,
- 可以以root用户使用命令
# fdisk -l
- 来查看你的全部分区。通常你所要的那个是形如
/dev/sda1
这样的东东。然后,使用命令
# mount /dev/sda1 /mnt
挂载该分区至 /mnt
。
这样你的文件系统就挂载在了 /mnt
下。例如,可以删除 gdm
来阻止Xorg正常启动,或者做其他一些必需的改动。
无法用"su"以root身份启动X客户端
如果你遇到"Client is not authorized to connect to server",尝试将以下内容
session optional pam_xauth.so
加入到/etc/pam.d/su
文件中。pam_xauth
就可以正常设置环境变量以及处理 xauth
密钥了。
X 启动失败:键盘初始化失败
遇到“X failed to start : Keyboard initialization failed”。
如果您的硬盘已满,startx将失败。 /var/log/Xorg.0.log
的末尾会是:
(EE) Error compiling keymap (server-0) (EE) XKB: Couldn't compile keymap (EE) XKB: Failed to load keymap. Loading default keymap instead. (EE) Error compiling keymap (server-0) (EE) XKB: Couldn't compile keymap XKB: Failed to compile keymap Keyboard initialization failed. This could be a missing or incorrect setup of xkeyboard-config. Fatal server error: Failed to activate core devices. Please consult the The X.Org Foundation support at http://wiki.x.org for help. Please also check the log file at "/var/log/Xorg.0.log" for additional information. (II) AIGLX: Suspending AIGLX clients for VT switch
在/分区上腾出一些可用空间,X才能启动。
想看视频时屏幕总是绿色
你的颜色深度设置错误。例如它可能需要设置为24位却被设置成了16位。
SocketCreateListener error
如果 X 结束,伴随着错误信息 "SocketCreateListener() failed",你可能需要删除位于 /tmp/.X11-unix
的 socket 文件。这有可能在你先前以 root 身份运行 Xorg (例如想要生成 xorg.conf
)后发生。
想要以 root 权限运行程序时出现 无效的 MIT-MAGIC-COOKIE-1 密钥
这个错误意味着只有当前用户有权访问 X server。解决办法是将访问权授予 root:
$ xhost +si:localuser:root
这条命令也可以将 X server 访问权授予其他用户。
Xorg-server 致命错误: (EE) AddScreen/ScreenInit
如果 Xorg 偶发故障并且在 Xorg 日志中看到:
systemd-logind: failed to take device /dev/dri/card0: Operation not permitted ... AddScreen/ScreenInit failed for driver 0
那么,这个问题可能由 systemd issue 13943引起。设置 KMS 早启动。
另请参阅
- Xplain - In-depth explanation of the X Window System
- Xorg(1) - Xorg's Manual Page
- Gentoo/Xorg#Configuration - Gentoo Wiki's Xorg Configuration page