Xorg (简体中文)
Xorg 是 X11 窗口系统的一个开源实现。Xorg 在 Linux 用户中非常流行,已经成为图形用户程序的必备条件,所以大部分发行版都提供了它。详情参见 Xorg 维基文章或访问Xorg 网站。
Contents
- 1 安装
- 2 运行
- 3 配置
- 4 输入设备
- 5 显示器设置
- 6 Composite
- 7 配置文件样例
- 8 技巧和技巧
-
9 故障和修复
- 9.1 通用问题
- 9.2 Black screen, No protocol specified.., Resource temporarily unavailable for all or some users
- 9.3 CTRL 右键无法与和oss keymap一起工作
- 9.4 Ctrl-Alt-Backspace无法退出X
- 9.5 Apple 的键盘问题
- 9.6 触摸板点击不正常
- 9.7 额外的鼠标按键不工作
- 9.8 无法用"su"以root身份启动X客户端
- 9.9 无法加载'(null)'字体
- 9.10 无法运行在frambuffer模式下
- 9.11 Matrox显卡的DRI功能失效
- 9.12 修复:在出现GUI登录界面之前,不启动Xorg
- 9.13 X failed to start : Keyboard initialization failed
- 9.14 不使用 root 权限的 Xorg (v1.16)
安装
安装 位于官方软件仓库 的软件包 xorg-server。
另外,安装位于 xorg-server-utils 组中的某些工具以进行某些特定的配置工作。其他一些有用的工具可以在 xorg-apps 组中找到。
驱动安装
Linux 内核包含了开源的视频驱动,支持硬件加速的 framebuffers。OpenGL 和 X11 的 2D 加速需要用户空间工具。
如果不知道显卡类型,请执行如下命令进行查询:
$ lspci | grep -e VGA -e 3D
输入下面命令,查看所有开源驱动:
$ pacman -Ss xf86-video | less
vesa
是一个支持大部分显卡的通用驱动,不提供任何 2D 和 3D 加速功能。要充分发挥显卡性能,请按下表安装驱动程序。推荐先使用开源驱动,这些驱动出问题的可能性较小。
厂商 | 类型 | 驱动 | Multilib 软件包 (适用于 Arch x86_64 上的 32 位程序) |
文档 |
---|---|---|---|---|
AMD/ATI | 开源 | xf86-video-ati | lib32-mesa-libgl | ATI (简体中文) |
闭源 | catalystAUR | lib32-catalyst-libglAUR | AMD Catalyst (简体中文) | |
Intel | 开源 | xf86-video-intel | lib32-mesa-libgl | Intel graphics (简体中文) |
Nvidia | 开源 | xf86-video-nouveau | lib32-mesa-libgl | Nouveau (简体中文) |
闭源 | nvidia | lib32-nvidia-libgl | NVIDIA (简体中文) | |
nvidia-340xx | lib32-nvidia-340xx-libgl | |||
nvidia-304xx | lib32-nvidia-304xx-libgl |
运行
如果不用登陆管理器启动 X,需要安装软件包 xorg-xinit。
startx
和 xinit
命令将启动 X 服务器和客户端(startx
脚本是更通用命令 xinit
的前端)。为了确定要运行的客户端,startx
/xinit
先在用户目录解析 ~/.xinitrc
文件,如果 ~/.xinitrc
不存在,使用默认的 /etc/X11/xinit/xinitrc
, 其中默认会使用 Twm 窗口管理器,Xclock 和 Xterm(需安装 xorg-twm, xorg-xclock 和 xterm).
更多信息请阅读 xinitrc (简体中文).
配置
Xorg 可以通过 /etc/X11/xorg.conf
或 /etc/xorg.conf
和位于 /etc/X11/xorg.conf.d/
的配置文件配置。用户可以创建自己的配置文件,需要以 XX-
开头(XX 是数字)并以.conf
结尾(例如 10 在 20 之前读取)。
此外,显卡驱动可能提供了自动配置工具,例如 NVIDIA 提供了 nvidia-xconfig
,ATI 提供了 aticonfig
。
输入设备
udev 会自动检测硬件,evdev 可以用作绝大部分设备的即插即用驱动。Udev 由 systemd 和 xf86-input-evdev需要通过 xorg-server提供,所以不需要显式安装。
你应该有10-evdev.conf
在 /usr/share/X11/xorg.conf.d/
目录,它管理键盘,鼠标,触摸板和触摸屏。
如果 evdev不支持您的设备, 请从xorg-drivers组安装需要的驱动程序. Alike evdev, libinput (xf86-input-libinput) is a driver which supports a wide array of hardware from all device categories.
鼠标加速
扩展鼠标按键
触摸板
见 Touchpad Synaptics (简体中文) 或 libinput.
触摸屏
见 Touchscreen.
键盘设置
见 Keyboard configuration in Xorg.
显示器设置
开始
首先,创建一个新的配置文件,例如/etc/X11/xorg.conf.d/10-monitor.conf
。
将下列代码加入到上述配置文件中:
Section "Monitor" Identifier "Monitor0" EndSection Section "Device" Identifier "Device0" Driver "vesa" #Choose the driver used for this monitor EndSection Section "Screen" Identifier "Screen0" #Collapse Monitor and Device section to Screen section Device "Device0" Monitor "Monitor0" DefaultDepth 16 #Choose the depth (16||24) SubSection "Display" Depth 16 Modes "1024x768_75.00" #Choose the resolution EndSubSection EndSection
多个显示器
See main article Multihead for general information.
参见GPU的具体说明:
- NVIDIA#Multiple monitors
- Nouveau#Dual Head
- AMD Catalyst#Double Screen (Dual Head / Dual Screen / Xinerama)
- ATI#Dual Head setup[broken link: invalid section]
多于一个显卡
你必须指定正确的驱动以使用你的显卡。
Section "Device" Identifier "Screen0" Driver "nouveau" BusID "PCI:0:12:0" EndSection Section "Device" Identifier "Screen1" Driver "radeon" BusID "PCI:1:0:0" EndSection
为了获取你的BusID:
$ lspci | grep VGA 01:00.0 VGA compatible controller: nVidia Corporation G96 [GeForce 9600M GT] (rev a1)
这个示例的BusID是 1:0:0.
切换笔记本内部/外部显示的脚本
这个脚本可以用于键盘快捷键中。
#!/bin/bash IN="LVDS1" EXT="VGA1" if (xrandr | grep "$EXT" | grep "+") then xrandr --output $EXT --off --output $IN --auto else if (xrandr | grep "$EXT" | grep " connected") then xrandr --output $IN --off --output $EXT --auto fi fi
为了获取内部/外部显示的名字,你可以输入:
# xrandr -q
如果你没有 xrandr
, install xorg-xrandr 来获取它。
显示大小和 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 (显示器电源管理信号) 是一种技术,可以在计算机不使用时,可以使用显示器的省电行为. 这将允许您的显示器在预定时间段后自动进入待机。 见: DPMS
Composite
The Composite extension for X causes an entire sub-tree of the window hierarchy to be rendered to an off-screen buffer. Applications can then take the contents of that buffer and do whatever they like. The off-screen buffer can be automatically merged into the parent window or merged by external programs, called compositing managers. See the following article for more information: compositing window manager
List of composite managers
- Cairo Composite Manager — Cairo based composite manager
- Compiz — Composite manager for Aiglx and Xgl, with plugins and CCSM
- http://www.compiz.org/ || compizAUR
- Compton — Compositor (a fork of xcompmgr-dana)
- Xcompmgr — Composite window-effects manager
- Unagi — Modular compositing manager which aims written in C and based on XCB
配置文件样例
Anyone who has an xorg.conf
file written up that works, go ahead and post a link to it here for others to look at. Please do not in-line the entire configuration file; upload it somewhere else and link to it.
请只贴热插拔示例否则注明配置未使用热插拔 (Xorg 1.8 = udev)
示例1 : xorg.conf
& /etc/X11/xorg.conf.d/10-evdev.conf
这是 /etc/X11/xorg.conf.d/10-evdev.conf
配置键盘布局的示例:
xorg.conf
: http://pastebin.com/raw.php?i=EuSKahkn/etc/X11/xorg.conf.d/10-evdev.conf
: http://pastebin.com/raw.php?i=4mPY35Mw/etc/X11/xorg.conf.d/10-monitor.conf
(VMware): http://pastebin.com/raw.php?i=fJv8EXGb/etc/X11/xorg.conf.d/10-monitor.conf
(KVM): http://pastebin.com/raw.php?i=NRz7v0Kn
技巧和技巧
调整 X 启动参数(/usr/bin/startx
)
参看X的选项:
$ man Xserver
以下的选项可以附加在/usr/bin/startx
文件的"defaultserverargs"
变量中.
- 为16位字体使能延缓字形加载:
-deferglyphs 16
Virtual X session
To start another X session in, for example, Ctrl+Alt+F8
, you need to type this on a console:
xinit /path/to/wm -- :1
Change "/path/to/wm" to your window manager start file or to your login manager like gdm, kdm, or slim.
Nested X session
To run a nested session of another desktop environment:
$ /usr/bin/Xnest :1 -geometry 1024x768+0+0 -ac -name Windowmaker & wmaker -display :1
This will launch a Window Maker session in a 1024 by 768 window within your current X session.
This needs the package xorg-server-xnest to be installed.
Starting GUI programs remotely
See main article: SSH#X11 forwarding.
On-demand disabling and enabling of input sources
With the help of xinput you can temporarily disable or enable input sources. This might be useful, for example, on systems that have more than one mouse, such as the ThinkPads and you would rather use just one to avoid unwanted mouse clicks.
Install the xorg-xinput package from the official repositories.
Find the ID of the device you want to disable:
$ xinput
For example in a Lenovo ThinkPad T500, the output looks like this:
$ 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)]
Disable the device with xinput --disable device_id
, where device_id is the device ID you want to disable. In this example we will disable the Synaptics Touchpad, with the ID 10:
$ xinput --disable 10
To re-enable the device, just issue the opposite command:
$ xinput --enable 10
故障和修复
通用问题
如果你在使用Xorg中遇到问题,无法启动或者黑屏,鼠标键盘不能正常工作,那么先进行以下步骤:
- 查看log日志文件:
cat /var/log/Xorg.0.log
, 可以从 X 启动终端之外的虚拟控制台查看错误。注意所有以(EE)
开头的行,EE 代表有错误。同时注意(WW)
警告,可能预示着其他问题。 - 需要安装输入驱动:(鼠标、键盘、触摸板等)
- 最后,在ATI, Intel和NVIDIA等文章中搜索常见问题。
如果还有问题,请到 Arch 论坛提问,请安装和使用wgetpaste:
#pacman -S wgetpaste
在论坛提问的帖子中,用 wgetpaste 提供如下文件的链接:
- ~/.xinitrc
- /etc/X11/xorg.conf
- /var/log/Xorg.0.log
- /var/log/Xorg.0.log.old
wgetpaste 用法:
$wgetpaste </path/to/file>
X creates configuration and temporary files in current user's home directory. Make sure there is free disk space available on the partition your home directory resides in. Unfortunately, X server does not provide any more obvious information about lack of disk space in this case.
CTRL 右键无法与和oss keymap一起工作
编辑 /usr/share/X11/xkb/symbols/fr
,将:
include "level5(rctrl_switch)"
改成
// include "level5(rctrl_switch)"
然后重启 X 或者系统。
Ctrl-Alt-Backspace无法退出X
System-wide
Within /etc/X11/xorg.conf.d/10-evdev.conf
, simply add the following:
Section "InputClass" Identifier "Keyboard Defaults" MatchIsKeyboard "yes" Option "XkbOptions" "terminate:ctrl_alt_bksp" EndSection
User-specific
另外一种方法是加入以下内容到~/.xinitrc
:
setxkbmap -option terminate:ctrl_alt_bksp
Apple 的键盘问题
触摸板点击不正常
- 参见: Synaptics
额外的鼠标按键不工作
无法用"su"以root身份启动X客户端
如果你遇到"Client is not authorized to connect to server",尝试将以下内容
session optional pam_xauth.so
加入到/etc/pam.d/su
文件中。pam_xauth
就可以正常设置环境变量以及处理 xauth
密钥了。
无法加载'(null)'字体
- 一些程序无法运行,提示无法加载`(null)'字体.
这些软件包可能需要一些额外的字体。某些程序只能使用位图字体。 目前有两种主要的位图字体包:xorg-fonts-75dpi、xorg-fonts-100dpi。选择其中一个就可以了。通过下面这个命令查看显示设置:
$ xdpyinfo | grep resolution
根据显示信息选择合适dpi的字体即可(用75 或 100 代替XX):
# pacman -S xorg-fonts-XXdpi
无法运行在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就可以了。
Matrox显卡的DRI功能失效
如果你使用的是Matrox显卡,在升级到Xorg7后它的DRI功能失效,试着在xorg.conf的显卡设备设置段Device section中加入下面一行:
Option "OldDmaInit" "On"
修复:在出现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正常启动,或者做其他一些必需的改动。
X failed to start : Keyboard initialization failed
If your hard disk is full, startx will fail. /var/log/Xorg.0.log
will end with:
(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
Make some free space on your root partition and X will start.
不使用 root 权限的 Xorg (v1.16)
在 1.16 版及以后 [1], Xorg 可能在 logind
的帮助下以用户特权运行。如此运行对系统的要求如下所示:
- systemd: 版本 >=216 以支持多实例;
- 经由 xinit 启动 X: 显示管理器(登陆管理器)不被支持;
- Kernel mode setting: implementations in proprietary display drivers fail auto-detection and require manually setting
needs_root_rights = no
in/etc/X11/Xwrapper.config
.
If you do not fit these requirements, re-enable root rights in /etc/X11/Xwrapper.config
:
needs_root_rights = yes
同时请参见 Xorg.wrap(1) 和 Systemd/User#Xorg as a systemd user service。