Linux笔记本外接显示器时彻底禁用内置屏幕的Xorg配置方案


阅读 2 次

问题场景描述

在使用HP Compaq nc6400笔记本(配备Intel 945GM显卡)通过扩展坞连接外接显示器时,即使合上笔记本盖子,Xorg仍会默认启用内置LVDS屏幕。这导致:

  • 登录界面显示在内置屏幕
  • 有限的显卡性能被两个显示器分摊
  • Gnome显示设置无法影响登录前的Xorg初始配置

硬件检测与验证

首先确认硬件状态:


# 检查显卡信息
sudo lspci -v -s 0:2 | grep -i vga
# 验证合盖传感器
cat /proc/acpi/button/lid/LID/state

对于没有合盖传感器的老机型,需要通过Xorg配置强制禁用。

Xorg配置方案

创建以下配置文件(适用于Intel显卡):


# /etc/X11/xorg.conf.d/10-monitor.conf
Section "Monitor"
    Identifier  "LVDS1"
    Option      "Ignore" "true"
EndSection

Section "Screen"
    Identifier  "Screen0"
    Device      "Card0"
    Monitor     "DVI1"
    DefaultDepth 24
    SubSection "Display"
        Depth   24
        Modes   "1920x1080"
    EndSubSection
EndSection

DRM内核参数方案

对于新版内核(4.15+),可通过DRM参数禁用:


# /etc/default/grub 追加参数
GRUB_CMDLINE_LINUX="... drm_kms_helper.edid_firmware=LVDS-1:none"

更新GRUB后重启:


sudo update-grub

登录管理器配置

针对GDM/SDDM的预处理脚本:


# /etc/gdm/PreSession/Default
#!/bin/sh
xrandr --output LVDS-1 --off
exit 0

自动化切换方案

创建udev规则实现扩展坞热插拔自动切换:


# /etc/udev/rules.d/99-dock.rules
ACTION=="change", SUBSYSTEM=="drm", ENV{HOTPLUG}=="1", RUN+="/usr/local/bin/dock-handler"

配套处理脚本:


#!/bin/bash
# /usr/local/bin/dock-handler
if [ $(cat /sys/class/drm/card0-DP-1/status) == "connected" ]; then
    xrandr --output LVDS-1 --off --output DP-1 --auto
else
    xrandr --output LVDS-1 --auto --output DP-1 --off
fi

验证与调试

检查当前配置状态:


xrandr --verbose
cat /var/log/Xorg.0.log | grep -i "connected"