5.4.Xorg 配置

Xorg 支持大多数常见的显卡、键盘和输入设备。

警告

显卡、显示器和输入设备会自动检测,无需手动配置。除非自动配置失败,否则不需要创建 xorg.conf 或执行 Xorg -configure 步骤。

5.4.1. 配置文件

Xorg 会在多个目录中查找配置文件。/usr/local/etc/X11/ 是 FreeBSD 上推荐的配置文件目录。使用此目录有助于将应用程序文件与操作系统文件分开。

5.4.2. 单个文件或多个文件

使用多个文件来配置特定设置比传统的单个 xorg.conf 文件更容易。这些文件存储在 /usr/local/etc/X11/xorg.conf.d/ 子目录中。

技巧

传统的单个 xorg.conf 文件仍然有效,但不如 /usr/local/etc/X11/xorg.conf.d/ 子目录中的多个文件清晰且灵活。

5.4.3. 显卡

可以在 /usr/local/etc/X11/xorg.conf.d/ 目录中指定显卡驱动程序。

要在配置文件中配置 Intel® 驱动程序:

示例 1. 在文件中选择 Intel® 显卡驱动程序

/usr/local/etc/X11/xorg.conf.d/20-intel.conf

Section "Device"
	Identifier "Card0"
	Driver     "intel"
EndSection

要在配置文件中配置 AMD® 驱动程序:

示例 2. 在文件中选择 AMD® 显卡驱动程序

/usr/local/etc/X11/xorg.conf.d/20-radeon.conf

Section "Device"
	Identifier "Card0"
	Driver     "radeon"
EndSection

要在配置文件中配置 NVIDIA® 驱动程序:

示例 3. 在文件中选择 NVIDIA® 显卡驱动程序

/usr/local/etc/X11/xorg.conf.d/20-nvidia.conf

Section "Device"
	Identifier "Card0"
	Driver     "nvidia"
EndSection

技巧

也可以使用 x11/nvidia-xconfig 来基本控制 NVIDIA 驱动程序的配置选项。

要在配置文件中配置 VESA 驱动程序:

示例 4. 在文件中选择 VESA 显卡驱动程序

/usr/local/etc/X11/xorg.conf.d/20-vesa.conf

Section "Device"
	Identifier "Card0"
	Driver     "vesa"
EndSection

要在配置文件中配置 SCFB 驱动程序:

示例 5. 在文件中选择 SCFB 显卡驱动程序

/usr/local/etc/X11/xorg.conf.d/20-scfb.conf

Section "Device"
	Identifier "Card0"
	Driver     "scfb"
EndSection

要配置多个显卡,可以添加 BusID。可以通过执行以下命令来显示显卡总线 ID 列表:

% pciconf -lv | grep -B3 display

输出应类似于以下内容:

vgapci0@pci0:0:2:0:     class=0x030000 rev=0x07 hdr=0x00 vendor=0x8086 device=0x2a42 subvendor=0x17aa subdevice=0x20e4
    vendor     = 'Intel Corporation'
    device     = 'Mobile 4 Series Chipset Integrated Graphics Controller'
    class      = display
--
vgapci1@pci0:0:2:1:     class=0x038000 rev=0x07 hdr=0x00 vendor=0x8086 device=0x2a43 subvendor=0x17aa subdevice=0x20e4
    vendor     = 'Intel Corporation'
    device     = 'Mobile 4 Series Chipset Integrated Graphics Controller'
    class      = display

示例 6. 在文件中选择 Intel® 显卡驱动程序和 NVIDIA® 显卡驱动程序

/usr/local/etc/X11/xorg.conf.d/20-drivers.conf

Section "Device"
	Identifier "Card0"
	Driver     "intel"
	BusID     "pci0:0:2:0"
EndSection

Section "Device"
	Identifier "Card0"
	Driver     "nvidia"
	BusID     "pci0:0:2:1"
EndSection

5.4.4. 显示器

几乎所有的显示器都支持扩展显示识别数据标准(EDID)。Xorg 使用 EDID 与显示器通信,并检测支持的分辨率和刷新率。然后,Xorg 会选择最适合的设置组合来使用该显示器。

显示器支持的其他分辨率可以通过在配置文件中设置所需的分辨率,或在启动 X 服务器后使用 xrandr(1) 来选择。

5.4.4.1. 使用 RandR(调整大小和方向)

运行 xrandr(1) 命令不带任何参数,以查看视频输出和检测到的显示器模式列表:

% xrandr

输出应类似于以下内容:

Screen 0: minimum 320 x 200, current 2560 x 960, maximum 8192 x 8192
LVDS-1 connected 1280x800+0+0 (normal left inverted right x axis y axis) 261mm x 163mm
   1280x800      59.99*+  59.81    59.91    50.00
   1280x720      59.86    59.74
   1024x768      60.00
   1024x576      59.90    59.82
   960x540       59.63    59.82
   800x600       60.32    56.25
   864x486       59.92    59.57
   640x480       59.94
   720x405       59.51    58.99
   640x360       59.84    59.32
VGA-1 connected primary 1280x960+1280+0 (normal left inverted right x axis y axis) 410mm x 257mm
   1280x1024     75.02    60.02
   1440x900      74.98    60.07
   1280x960      60.00*
   1280x800      74.93    59.81
   1152x864      75.00
   1024x768      75.03    70.07    60.00
   832x624       74.55
   800x600       72.19    75.00    60.32    56.25
   640x480       75.00    72.81    66.67    59.94
   720x400       70.08
HDMI-1 disconnected (normal left inverted right x axis y axis)
DP-1 disconnected (normal left inverted right x axis y axis)
HDMI-2 disconnected (normal left inverted right x axis y axis)
DP-2 disconnected (normal left inverted right x axis y axis)
DP-3 disconnected (normal left inverted right x axis y axis)

这显示了 VGA-1 输出正在以大约 60 Hz 的刷新率显示 1280x960 像素的屏幕分辨率,LVDS-1 作为副显示器显示 1280x800 像素的屏幕分辨率,刷新率为大约 60 Hz。HDMI-1HDMI-2DP-1DP-2DP-3 连接器未连接显示器。

可以使用 xrandr(1) 选择任何其他显示模式。例如,要切换到 1280x1024 分辨率,刷新率为 60 Hz:

% xrandr --output LVDS-1 --mode 1280x720 --rate 60

5.4.4.2. 使用 Xorg 配置文件

也可以在配置文件中设置显示器配置。

要在配置文件中设置屏幕分辨率为 1024x768:

示例 7. 在文件中设置屏幕分辨率

/usr/local/etc/X11/xorg.conf.d/10-monitor.conf

Section "Screen"
	Identifier "Screen0"
	Device     "Card0"
	SubSection "Display"
	Modes      "1024x768"
	EndSubSection
EndSection

5.4.5. 输入设备

Xorg 支持通过 x11/libinput 驱动的大多数输入设备。

技巧

一些桌面环境(例如 KDE Plasma)提供了一个图形化的用户界面来设置这些参数。在进行手动配置编辑之前,请检查是否提供此功能。

例如,要配置键盘布局:

示例 8. 设置键盘布局

/usr/local/etc/X11/xorg.conf.d/00-keyboard.conf

Section "InputClass"
        Identifier "Keyboard1"
        MatchIsKeyboard "on"
        Option "XkbLayout" "es, fr"
        Option "XkbModel" "pc104"
        Option "XkbVariant" ",qwerty"
        Option "XkbOptions" "grp:win_space_toggle"
EndSection

最后更新于