[Share Experiences] 笔记本电脑双屏设置及显示
Tofloor
poster avatar
打个酱油先
deepin
2024-04-27 23:37
Author

hardware config

$ lsb_release -a   
No LSB modules are available.
Distributor ID: Deepin
Description:    Deepin 20.9
Release:        20.9
Codename:       apricot

$ lspci|grep -i VGA
00:02.0 VGA compatible controller: Intel Corporation UHD Graphics 630 (Mobile)
01:00.0 VGA compatible controller: NVIDIA Corporation GP107M [GeForce GTX 1050 Mobile] (rev a1)

Install NVIDIA driver

sudo ./NVIDIA-Linux-x86_64-550.67.run --no-x-check --no-nouveau-check --no-opengl-files
sudo reboot
$ nvidia-smi   
Sat Apr 27 23:20:47 2024   
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 550.67                 Driver Version: 550.67         CUDA Version: 12.4     |
|-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA GeForce GTX 1050        Off |   00000000:01:00.0  On |                  N/A |
| N/A   46C    P8             N/A / ERR!  |     107MiB /   2048MiB |      0%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+
                                                                                   
+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI        PID   Type   Process name                              GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|    0   N/A  N/A      3920      G   /usr/lib/xorg/Xorg                            104MiB |
+-----------------------------------------------------------------------------------------+

Dual screen setting

cat /etc/X11/xorg.conf
# nvidia-xconfig: X configuration file generated by nvidia-xconfig
# nvidia-xconfig:  version 550.67

Section "ServerLayout"
    Identifier     "Layout0"
    Screen      0  "nvidia" 0 0
    Screen      1  "intel"  1920 0 
    InputDevice    "Keyboard0" "CoreKeyboard"
    InputDevice    "Mouse0" "CorePointer"
    Option         "Xinerama" "on"
EndSection

Section "Files"
EndSection

Section "InputDevice"
    # generated from default
    Identifier     "Mouse0"
    Driver         "mouse"
    Option         "Protocol" "auto"
    Option         "Device" "/dev/psaux"
    Option         "Emulate3Buttons" "no"
    Option         "ZAxisMapping" "4 5"
EndSection

Section "InputDevice"
    # generated from default
    Identifier     "Keyboard0"
    Driver         "kbd"
EndSection

Section "Monitor"
    Identifier     "Monitor0"
    VendorName     "Unknown"
    ModelName      "Unknown"
    Option         "DPMS"
EndSection

Section "Device"
    Identifier     "intel"
    VendorName     "intel Corporation"
    BusID          "PCI:0:2:0"
    Driver         "modesetting"
EndSection

Section "Screen"
    Identifier     "intel"
    Device         "intel"
    Monitor        "Monitor0"
    DefaultDepth    24
    SubSection     "Display"
        Depth       24
    EndSubSection
EndSection

Section "Device"
        Identifier "nvidia"
        Driver "nvidia"
        BusID "PCI:1:0:0"
EndSection

Section "Screen"
        Identifier "nvidia"
        Device "nvidia"
        Option "AllowEmptyInitialConfiguration" "Yes"
        Monitor        "Monitor1"
EndSection

Section "Monitor"
    Identifier     "Monitor1"
    VendorName     "Unknown"
    ModelName      "Unknown"
    Option         "DPMS"
EndSection

FAQ

  1. dual screnn module, 模块使用 Xinerama 不用 xrand 否则没有效果还是单屏

    Option         "Xinerama" "on"
    
  2. dual scrren size config

        Screen      0  "nvidia" 0 0
        Screen      1  "intel"  1920 0 
    

使用Xrand 模块只能使用一个屏

cat ./NVIDIA.sh        
#提示文本
echo '即将切换至NVIDIA显卡,请输入登录密码,回车后会自动注销。在此之前,请保存好当前的工作。'

#获取NVIDIA显卡的BusID
NVIDIA_BusID=`lspci | egrep 'VGA|3D' | grep 'NVIDIA' | cut -d ' ' -f 1 | sed -r 's/0?(.)/\1/' | sed -e 's/:0/:/g' -e 's/\./:/g'`

#写入Xorg配置文件
echo 'Section "Module"
        Load "modesetting"
EndSection
Section "Device"
        Identifier "nvidia"
        Driver "nvidia"
        BusID "PCI:'$NVIDIA_BusID'"  
        Option "AllowEmptyInitialConfiguration"
EndSection' | sudo tee /etc/X11/xorg.conf.d/20-nvidia.conf > /dev/null

#写入LightDM启动脚本
echo '#!/bin/sh
xrandr --setprovideroutputsource modesetting NVIDIA-0
xrandr --auto
xrandr --dpi 96' | sudo tee /etc/lightdm/display_setup.sh > /dev/null

#为启动脚本赋予可执行权限
sudo chmod +x /etc/lightdm/display_setup.sh

#修改LightDM配置文件
sudo sed -i 's$#display-setup-script=$display-setup-script=/etc/lightdm/display_setup.sh$g' /etc/lightdm/lightdm.conf

#写入内核参数,防止撕裂问题
echo 'options nvidia-drm modeset=1' | sudo tee /etc/modprobe.d/nvidia-graphics-drivers.conf > /dev/null

#重启LightDM服务,注销即可切换
sudo service lightdm restart
cat ./Intel.sh 
#提示文本
echo '即将切换至Intel显卡,请输入登录密码,回车后会自动注销。在此之前,请保存好当前的工作。'

#删除配置文件
sudo rm /etc/X11/xorg.conf.d/20-nvidia.conf
sudo rm /etc/lightdm/display_setup.sh
sudo rm /etc/modprobe.d/nvidia-graphics-drivers.conf

#恢复LightDM配置文件
sudo sed -i 's$display-setup-script=/etc/lightdm/display_setup.sh$#display-setup-script=$g' /etc/lightdm/lightdm.conf

#重启LightDM服务,注销即可切换
sudo service lightdm restart
Reply Favorite View the author
All Replies
打个酱油先
deepin
2024-04-27 23:40
#1

存在的问题

  1. 应用最大化之后会占满两个屏幕,而不是当前屏幕
  2. 拔掉外接显示器之后无法自动切换成一个屏幕的模式,严重情况是电脑自动关机
Reply View the author
蒙笛
deepin
2024-04-27 23:50
#2

赞一个agree

不太懂,deepin下不能在显示设置里设置双屏幕显示吗?我用的mint里可以直接设置啊,
还是服务器里没有图形界面,需要通过修改配置文件来实现?

image.png

Reply View the author
乾豫恒益
deepin
2024-04-28 08:46
#3
打个酱油先

存在的问题

  1. 应用最大化之后会占满两个屏幕,而不是当前屏幕
  2. 拔掉外接显示器之后无法自动切换成一个屏幕的模式,严重情况是电脑自动关机

基本上是硬件问题,十年前的老笔记本,用HDMI线,双屏设置,随意切换。

Reply View the author