X server 的配置 文件都是预设放置在 /etc/X11 目录下,而相关的显示模块或上面提到的总总模块,则主要放置在/usr/lib64/xorg/modules .

比较重要的是字型文件与芯片组,她们主要放置在:

  • 提供的屏幕字体: /usr/share/X11/fonts/

  • 显示适配器的芯片组: /usr/lib64/xorg/modules/drivers/

解析 xorg.conf 设定

如果你想要知道到底你 用的 X Server 版本是第几版,可以使用 X 指令来检查

[root@study ~]# X -version
X.Org X Server 1.15.0
Release Date: 2013-12-27
X Protocol Version 11, Revision 0
Build Operating System:  2.6.32-220.17.1.el6.x86_64
Current Operating System: Linux study.centos.vbird 3.10.0-229.el7.x86_64 #1 SMP Fri Mar 
  6 11:36:42 UTC 2015 x86_64
Kernel command line: BOOT_IMAGE=/vmlinuz-3.10.0-229.el7.x86_64 root=/dev/mapper/centos-
  root ro rd.lvm.lv=centos/root rd.lvm.lv=centos/swap crashkernel=auto rhgb quiet
Build Date: 10 April 2015  11:44:42AM
Build ID: xorg-x11-server 1.15.0-33.el7_1
Current version of pixman: 0.32.4
        Before reporting problems, check http://wiki.x.org
        to make sure that you have the latest version.

从 CentOS 6 以后 (当然包含 CentOS 7),X server 在每次启动的时候都会自行 侦测系统上面的显示芯片、屏幕类型等等, 然后自行搭配优化的驱动程序加载。因此,这个 /etc/X11/xorg.conf 已经不再被需要了。不过,如果你不喜欢 X 系统自行侦测的设定值, 那也可以 自行建置 xorg.conf 就是了。

此外,如果你只想要加入或者是修改部份的设定,并不是每个组件都要自行设定的话,那么可以在 /etc/X11/xorg.conf.d/ 这个目录下建立文件名为 .conf 的文件, 将你需要的额外项目加进去即可喔! 那就不会每个设定都以你的 xorg.conf 为主了!

这个文件的内容是分成数个段落的,每个段落以 Section 开始,以 EndSection 结束, 里面含有该 Section (段落) 的相关设定值,例如:

Section  "section name"
...... <== 与这个 section name 有关的设定项目 
......
EndSection

至于常见的 section name 主要有:

  1. Module: 被加载到 X Server 当中的模块 (某些功能的驱动程序);
  2. InputDevice: 包括输入的 1. 键盘的格式 2. 鼠标的格式,以及其他相关输入设备;
  3. Files: 设定字型所在的目录位置等;
  4. Monitor: 监视器的格式, 主要是设定水平、垂直的更新频率,与硬件有关;
  5. Device: 这个重要,就是显示适配器芯片组的相关设定了;
  6. Screen: 这个是在屏幕上显示的相关分辨率与颜色深度的设定项目,与显示的行为有关;
  7. ServerLayout: 上述的每个项目都可以重复设定,这里则是此一 X server 要取用的哪个项目值的设定啰。

前面说了,xorg.conf 这个文件已经不存在,那我们怎么学习呢?没关系,Xorg 有提供一个简单的方 式可以让我们来重建这个 xorg.conf 文件! 同时,这可能也是 X 自行侦测 GPU 所产生的优化设定 喔!怎么处理呢?假设你是在 multi-user.target 的环境下,那就可以这样作来产生 xorg.conf 喔!

[root@study ~]# Xorg -configure
.....(前面省略).....
Markers: (--) probed, (**) from config file, (==) default setting,
        (++) from command line, (!!) notice, (II) informational,
        (WW) warning, (EE) error, (NI) not implemented, (??) unknown.
(==) Log file: "/var/log/Xorg.0.log", Time: Wed Sep 16 10:13:57 2015
List of video drivers:   # 这里在说明目前这个系统上面有的显示适配器芯片组的驱动程序有哪些的意思
        qxl
        vmware
        v4l
        ati
        radeon
        intel
        nouveau
        dummy
        modesetting
        fbdev
        vesa
(++) Using config file: "/root/xorg.conf.new"        # 使用的配置文件
(==) Using config directory: "/etc/X11/xorg.conf.d" # 额外设定项目的位置
(==) Using system config directory "/usr/share/X11/xorg.conf.d"
(II) [KMS] Kernel modesetting enabled.

.....(中間省略).....

Your xorg.conf file is /root/xorg.conf.new          # 最终新的文件出现了!

To test the server, run 'X -config /root/xorg.conf.new' # 测试手段!

这样就在你的 root 家目录产生一个新的 xorg.conf.new 啰!好了,直接来看看这个文件的内容吧! 这个文件预设的情况是取消很多设定值的, 所以你的配置文件可能不会看到这么多的设定项目。不 要紧的,后续的章节会交代如何设定这些项目的喔!

[root@study ~]# vim xorg.conf.new
Section "ServerLayout"                             # 目前 X 决定使用的设定项目
        Identifier     "X.org Configured"
        Screen      0  "Screen0" 0 0               # 使用的屏幕为 Screen0 这一个 (后面会解释)
        InputDevice    "Mouse0" "CorePointer"      # 使用的鼠标设定为Mouse0
        InputDevice    "Keyboard0" "CoreKeyboard"  # 使用的键盘设定为 Keyboard0
EndSection
# 系统可能有多组的设定值,包括多种不同的键盘、鼠标、显示芯片等等,而最终 X 使用的设定,
# 就是在这个 ServerLayout 项目中来处理的!因此,你还得要去底下找出 Screen0 是啥

Section "Files"
        ModulePath   "/usr/lib64/xorg/modules"
        FontPath     "catalogue:/etc/X11/fontpath.d"
        FontPath     "built-ins"
EndSection
# 我们的 X Server 很重要的一点就是必须要提供字型,这个 Files 的项目就是在设定字型,
# 当然啦,你的主机必须要有字型文件才行。一般字型文件在:/usr/share/X11/fonts/ 目录中。
# 但是 Xorg 会去读取的则是在 /etc/X11/fontpath.d 目录下的设定喔!

Section "Module"
        Load  "glx"
EndSection
# 上面这些模块是 X Server 启动时,希望能够额外获得的相关支持的模块。
# 关于更多模块可以搜寻一下 /usr/lib64/xorg/modules/extensions/ 这个目录

Section "InputDevice"
        Identifier  "Keyboard0"
        Driver      "kbd"
EndSection
# 就是键盘,在 ServerLayout 项目中有出现这个 Keyboard0 吧!主要是设定驱动程序!

Section "InputDevice"
        Identifier  "Mouse0"
        Driver      "mouse"
        Option      "Protocol" "auto"
        Option      "Device" "/dev/input/mice"
        Option      "ZAxisMapping" "4 5 6 7"   # 支持滚轮功能
EndSection
# 这个则主要在设定鼠标功能,重点在那个 Protocol 项目,
# 那个是可以指定鼠标接口的设定值,我这里使用的是自动侦测!不论是 USB/PS2。

Section "Monitor"
        Identifier   "Monitor0"
        VendorName   "Monitor Vendor"
        ModelName    "Monitor Model"
EndSection
# 屏幕监视器的设定仅有一个地方要注意,那就是垂直与水平的更新频率,常见设定如下:
#       HorizSync    30.0 - 80.0
#       VertRefresh  50.0 - 100.0
# 在上面的 HorizSync 与 VerRefresh 的设定上,要注意,不要设定太高,
# 这个玩意儿与实际的监视器功能有关,请查询你的监视器手册说明来设定吧!
# 传统 CRT 屏幕设定太高的话,据说会让 monitor 烧毁呢,要很注意啊。

Section "Device"     # 显示适配器芯片 (GPU) 的驱动程序!很重要的设定!
        Identifier  "Card0"
        Driver      "qxl"        # 实际使用的显示适配器驱动程序!
        BusID       "PCI:0:2:0"
EndSection
# 这地方重要了,这就是显示适配器的芯片模块加载的设定区域。由于鸟哥使用 Linux KVM
# 仿真器仿真这个测试机,因此这个地方显示的驱动程序为 qxl 模块。
# 更多的显示芯片模块可以参考  /usr/lib64/xorg/modules/drivers/

Section "Screen"                # 与显示的画面有关,分辨率与颜色深度
        Identifier "Screen0"    # 就是 ServerLayout 里面用到的那个屏幕设定
        Device     "Card0"      # 使用哪一个显示适配器的意思!
        Monitor    "Monitor0"   # 使用哪一个屏幕的意思!
        SubSection "Display"    # 此阶段的附属设定项目
                Viewport   0 0
                Depth     1     # 就是颜色深度的意思!
        EndSubSection
        SubSection "Display"
                Viewport   0 0
                Depth     16
        EndSubSection
        SubSection "Display"
                Viewport   0 0
                Depth     24
        EndSubSection
EndSection
# Monitor 与实际的显示器有关,而 Screen 则是与显示的画面分辨率、颜色深度有关。
# 我们可以设定多个分辨率,实际应用时可以让用户自行选择想要的分辨率来呈现,设定如下:
#		Modes    "1024x768" "800x600" "640x480" <==分辨率
# 上述的 Modes 是在 "Display" 底下的子设定。
# 不过,为了避免困扰,鸟哥通常只指定一到两个分辨率而已。

上面设定完毕之后,就等于将整个 X Server 设定妥当了,很简单吧。如果你想要更新其他的例如显示芯片的模块的话,就得要去硬件开发商的网站下载原始档来编译才行。设定完毕之后,你就可以 启动 X Server 试看看啰。然后,请将 xorg.conf.new 更名成类似 00-vbird.conf 之类的档名, 再将 该文件移动到 /etc/X11/xorg.conf.d/ 里面去,这样就 OK 了!

# 测试 X server 的配置文件是否正常:
[root@study ~]# startx <==直接在 multi-user.target 启动 X 看看
[root@study ~]# Xorg :1 <==在 tty3 单独启动 X server 看看

当然,你也可以利用 systemctl isolate graphical.target 这个指令直接切换到图形接口的登入来试看看。

字型管理

我们 Xorg 所使用的字型大部分都是放置于底下的目录中:

  • /usr/share/X11/fonts/
  • /usr/share/fonts/

不过 Xorg 默认会加载的字型则是记录于 /etc/X11/fontpath.d/ 目录中,使用链接文件的模式来进行 链接的动作而已。我们默认的 Xorg 使用的字型 就是取自于 /etc/X11/fontpath.d。

CentOS 7 针对中文字型 (chinese) 来说,有楷书与明体,明体预设安装了,不过楷书 却没有安装耶~ 那我们能不能安装了楷书之后,将楷书也列为默认的字型之一呢?来瞧一瞧我们怎 么作的好了:

# 1. 检查中文字型,并且安装中文字型与检验有没有放置到 fontpath.d 目录中!
[root@study ~]# ll -d /usr/share/fonts/cjk*
drwxr-xr-x. 2 root root 22 May 4 17:54 /usr/share/fonts/cjkuni-uming

[root@study ~]# yum install cjkuni-ukai-fonts
[root@study ~]# ll -d /usr/share/fonts/cjk*
drwxr-xr-x. 2 root root 21 Sep 16 11:48 /usr/share/fonts/cjkuni-ukai # 这就是楷书!
drwxr-xr-x. 2 root root 22 May 4 17:54 /usr/share/fonts/cjkuni-uming

[root@study ~]# ll /etc/X11/fontpath.d/
lrwxrwxrwx. 1 root root 29 Sep 16 11:48 cjkuni-ukai-fonts -> /usr/share/fonts/cjkuni-ukai/
lrwxrwxrwx. 1 root root 30 May  4 17:54 cjkuni-uming-fonts -> /usr/share/fonts/cjkuni-uming/
lrwxrwxrwx. 1 root root 36 May  4 17:52 default-ghostscript -> /usr/share/fonts/default/ghostscript
lrwxrwxrwx. 1 root root 30 May  4 17:52 fonts-default -> /usr/share/fonts/default/Type1
lrwxrwxrwx. 1 root root 27 May  4 17:51 liberation-fonts -> /usr/share/fonts/liberation
lrwxrwxrwx. 1 root root 27 Sep 15 17:10 xorg-x11-fonts-100dpi:unscaled:pri=30 -> /usr/share/X11/fonts/100dpi
lrwxrwxrwx. 1 root root 26 Sep 15 17:10 xorg-x11-fonts-75dpi:unscaled:pri=20 -> /usr/share/X11/fonts/75dpi
lrwxrwxrwx. 1 root root 26 May  4 17:52 xorg-x11-fonts-Type1 -> /usr/share/X11/fonts/Type1
# 竟然会自动的将该字型加入到 fontpath.d 当中!

# 2. 建立该字型的字型快取数据,并检查是否真的取用了?
[root@study ~]# fc-cache -v | grep ukai
/usr/share/fonts/cjkuni-ukai: skipping, existing cache is valid: 4 fonts, 0 dirs

[root@study ~]# fc-list | grep ukai
/usr/share/fonts/cjkuni-ukai/ukai.ttc: AR PL UKai TW:style=Book
/usr/share/fonts/cjkuni-ukai/ukai.ttc: AR PL UKai HK:style=Book
/usr/share/fonts/cjkuni-ukai/ukai.ttc: AR PL UKai CN:style=Book
/usr/share/fonts/cjkuni-ukai/ukai.ttc: AR PL UKai TW MBE:style=Book

# 3. 重新启动 Xorg,或者是强制重新进入 graphical.target
[root@study ~]# systemctl isolate multi-user.target; systemctl isolate graphical.target

  • 让窗口管理员可以使用额外的字型

来看看如何增加字型吧!(假设上述的字体文件是放置在 /root/font 中)

# 1. 将字型文件放置到系统设定目录,亦即底下的目录中:
[root@study ~]# cd /usr/share/fonts/
[root@study ~]# mkdir windows
[root@study ~]# cp /root/font/*.ttf /usr/share/fonts/windows/

# 2. 使用 fc-cache 将上述的文件加入字型的支持中:
[root@study ~]# fc-cache -f -v
....(前面省略)....
/usr/share/fonts/windows: caching, new cache contents: 6 fonts, 0 dirs 
....(后面省略)....
# -v 仅是列出目前的字型数据, -f 则是强制重新建立字型快取!

# 3. 透过 fc-list 列出已经被使用的文件看看:
[root@study ~]# fc-list : file | grep window  <==找出被快取住的檔名
/usr/share/fonts/windows/timesbi.ttf:
/usr/share/fonts/windows/timesi.ttf:
/usr/share/fonts/windows/msjh.ttf:
/usr/share/fonts/windows/times.ttf:
/usr/share/fonts/windows/msjhbd.ttf:
/usr/share/fonts/windows/timesbd.ttf:

显示器参数微调

屏幕的分辨率应该与显示适配器相关性不高,而是与显示器的更新频率有关!

所谓的更新频率,指的是在一段时间内屏幕重新绘制画面的速度。举例来说, 60Hz 的更新频率, 指 的是每秒钟画面更新 60 次的意思。那么关于显示器的更新频率该如何调整呢? 你得先去找到你的 显示器的使用说明书 (或者是网站会有规格介绍),取得最高的更新率后,接下来选择你想要的分辨 率, 然后透过这个 gtf 的指令功能来调整:

# 1. 先来测试一下你目前的屏幕搭配显卡所能够处理的分辨率与更新频率 (须在 X 环境下)
[root@study ~]# xrandr
Screen 0: minimum 320 x 200, current 1440 x 900, maximum 8192 x 8192
Virtual-0 connected primary 1440x900+0+0 0mm x 0mm
   1024x768       59.9 +
   1920x1200      59.9
   1920x1080      60.0
   1600x1200      59.9
   1680x1050      60.0
   1400x1050      60.0
   1280x1024      59.9
   1440x900       59.9*
   1280x960       59.9
   1280x854       59.9
   1280x800       59.8
   1280x720       59.9
   1152x768       59.8
   800x600        59.9
   848x480        59.7
   720x480        59.7
   640x480        59.4
# 上面显示现在的环境中,测试过最高分辨率大概是 1920x1200 ,但目前是 1440x900 (*)
# 若需要调整成 1280*800 的话,可以使用底下的方式来调整喔!

[root@study ~]# xrandr -s 1280x800

# 2. 若想强迫 X server 更改屏幕的分辨率与更新频率,则需要修订 xorg.conf 的设定。先来侦测:
[root@study ~]# gtf 水平像素 垂直像素 更新频率 [-xv]
选项与参数:
水平像素:就是分辨率的 X 轴
垂直像素:就是分辨率的 Y 轴 
更新频率:与显示器有关,一般可以选择 60, 75, 80, 85 等频率 
-x :使用 Xorg 配置文件的模式输出,这是默认值
-v :显示侦测的过程

# 1. 使用 1024x768 的分辨率,75 Hz 的更新频率来取得显示器内容
[root@study ~]# gtf 1024 768 75 -x
# 1024x768 @ 75.00 Hz (GTF) hsync: 60.15 kHz; pclk: 81.80 MHz
Modeline "1024x768_75.00" 81.80 1024 1080 1192 1360 768 769 772 802 -HSync +Vsync
# 重点是 Modeline 那一行!那行给他抄下来

# 2. 将上述的数据输入 xorg.conf.d/*.conf 内的 Monitor 项目中:
[root@study ~]# vim /etc/X11/xorg.conf.d/00-vbird.conf
Section "Monitor"
    Identifier   "Monitor0"
    VendorName   "Monitor Vendor"
    ModelName    "Monitor Model"
    Modeline "1024x768_75.00"  81.80  1024 1080 1192 1360  768 769 772 802  -HSync +Vsync
EndSection
# 就是新增上述的那行特殊字体部分到 Monitor 的项目中即可。
posted on 2017-11-06 17:46  uetucci  阅读(6669)  评论(0编辑  收藏  举报