这两天给实验室的电脑加了一个显示器,发现装好gnome的archlinux不能自动识别,因此折腾了一下双显示器的配置问题。对于双屏幕的设置有Xinerama, Twinview, randr等方法。

Xinerama

对于Archlinux下的Xorg的双屏设置,默认情况下只会使用第一个显示器。如果想要使用双屏,最直接的办法是使用Xorg的Xinerama扩展
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
Section "ServerLayout"
    Identifier     "DualSreen"
    Screen       0 "Screen0"
    Screen       1 "Screen1" RightOf "Screen0" #Screen1 at the right of Screen0
    Option         Xinerama "1" #To move windows between screens
EndSection
 
Section "Monitor"
    Identifier     "Monitor0"
    Option         "Enable" "true"
EndSection
 
Section "Monitor"
    Identifier     "Monitor1"
    Option         "Enable" "true"
EndSection
 
Section "Device"
    Identifier     "Device0"
    Driver         "nvidia"
    Screen         0
EndSection
 
Section "Device"
    Identifier     "Device1"
    Driver         "nvidia"
    Screen         1
EndSection
 
Section "Screen"
    Identifier     "Screen0"
    Device         "Device0"
    Monitor        "Monitor0"
    DefaultDepth    24
    Option         "TwinView" "0"
    SubSection "Display"
        Depth          24
        Modes          "1280x800_75.00"
    EndSubSection
EndSection
 
Section "Screen"
    Identifier     "Screen1"
    Device         "Device1"
    Monitor        "Monitor1"
    DefaultDepth   24
    Option         "TwinView" "0"
    SubSection "Display"
        Depth          24
    EndSubSection
EndSection

只需要把上述内容保存在/etc/X11/xorg.rc.d/10-monitor.conf就可以开启双屏输出了。但是不知道为什么我使用这个方法配置的时候两个屏幕的内容会出现重叠,屏幕分辨率也有问题,尝试了各种配置都没有完全解决。使用Xinerama扩展来双屏输出还有一个问题就是不能支持composition。

Twinview

因此我转向使用nvidia提供的另外一个方法:使用nvdia显卡驱动的twinview扩展,最简单的方法就是运行

1
sudo nvidia-xconfig --twinview

这会生成一个/etc/X11/xorg.conf,并且会忽略/etx/X11/xorg.rc.d/10-monitor.conf中的设置。使用twinview方式显卡驱动会将两个显示器拼成一个显示器–这意味着你在gnome, kde的显示器设置中只会看到一个显示器,它的分辨率是两个显示器之和。因此在xorg.conf中也只需要配置一个显示器,具体配置文件的用法可以参考这里,你可以在配置文件里面手动指定两个屏幕的分辨率等等。用这个方法的好处是可以有桌面特效加速,但是用ATI显卡的同学就不能这么用了。

自动生成的配置有一个问题:显卡的第二个接口连接的显示器分辨率最多只能上到640X400,解决的方法也很简单,只需要把Monitor中的HorizSync和VertRefresh注释掉就可以了:

1
2
3
4
5
6
7
8
9
Section "Monitor"
        Identifier      "Monitor0"
        Option          "Enable"   "True"
        VendorName      "Unknown"
        ModelName       "Unknown"
        #HorizSync      28.0 - 33.0
        #VertRefresh    43.0 - 72.0
        Option          "DPMS"
EndSection

如果你已经可以启动图形界面的话,可以用管理员权限运行nvidia-settings来用nvidia驱动自带的GUI程序对双屏幕进行设置,设置会自动保存到xorg.conf中。

针对Wine的设置

如果使用Twinview方式设置双屏的话,wine下运行的程序会不正常–在我的机器上如果是两个分辨率不一样的屏幕左右排列,右边个屏幕上的wine程序就会有一块是白板。如果是运行游戏的话鼠标会被限制在一个小范围中,不能点到整个屏幕。

解决这个问题的折衷办法是在twinview的分辨率模式中为wine下面的游戏添加一个模式–让主显示器用正常分辨率,把另外一个显示器关掉:

1
2
3
4
5
6
7
8
9
10
11
12
13
Section "Screen"
    Identifier     "Screen0"
    Device         "Device0"
    Monitor        "Monitor0"
    DefaultDepth    24
    Option         "TwinView" "1"
    Option         "TwinViewXineramaInfoOrder" "CRT-1"
    # 第一个模式是自动匹配最佳分辨率,第二个是在运行游戏的时候关掉一个显示器
    Option         "metamodes" "nvidia-auto-select,nvidia-auto-select;NULL,1440x900"
    SubSection     "Display"
        Depth       24
    EndSubSection
EndSection