重新连接DisplayPort显示器时配置重置问题求助
I’ve run into this exact headache with NVIDIA’s display handling before—when you save the layout via nvidia-settings, it writes a config tied directly to the currently connected displays. As soon as you disconnect the DisplayPort monitor, Xorg re-detects available devices and falls back to a default layout, wiping your custom positions. Reconnecting the DP monitor doesn’t restore the old setup because the Xorg config isn’t built to handle hotplugging gracefully.
Here are the most reliable fixes to keep your layout consistent, even when you disconnect/reconnect displays:
1. Build a Persistent Xorg Configuration File
Instead of relying on nvidia-settings to generate a generic config, create a custom one that explicitly defines each monitor’s position and settings—even if the display is disconnected.
Step-by-Step:
- Create a new config file in
/etc/X11/xorg.conf.d/(this directory overrides the mainxorg.conf):sudo nano /etc/X11/xorg.conf.d/10-nvidia-custom.conf - Paste this template, replacing resolutions, positions, and identifiers with your actual monitor details (grab these from
xrandroutput):Section "Monitor" Identifier "DVI-Monitor" VendorName "Your Monitor Brand" ModelName "Your DVI Monitor Model" Option "PreferredMode" "1920x1080" # Match your monitor's native resolution Option "Position" "0 0" # Set your desired X/Y position EndSection Section "Monitor" Identifier "HDMI-Monitor" VendorName "Your Monitor Brand" ModelName "Your HDMI Monitor Model" Option "PreferredMode" "1920x1080" Option "Position" "1920 0" # Position to the right of DVI EndSection Section "Monitor" Identifier "DP-Monitor" VendorName "Your Monitor Brand" ModelName "Your DP Monitor Model" Option "PreferredMode" "2560x1440" Option "Position" "3840 0" # Position to the right of HDMI EndSection Section "Screen" Identifier "Screen0" Device "Device0" # Match the Device identifier from your existing xorg.conf Monitor "DVI-Monitor" DefaultDepth 24 # Xorg will ignore disconnected displays in this metamode list Option "metamodes" "DVI-D-0: 1920x1080+0+0, HDMI-0: 1920x1080+1920+0, DP-0: 2560x1440+3840+0" SubSection "Display" Depth 24 EndSubSection EndSection - Save the file and reboot your system (or restart the X server).
Now, when you disconnect the DP monitor, Xorg will skip the DP entry in metamodes and keep your DVI/HDMI layout intact. Reconnecting the DP monitor will automatically restore its original position.
2. Use a Hotplug Script with udev
For dynamic, automatic adjustments when displays are plugged/unplugged, pair a custom script with udev rules.
Step-by-Step:
- Create a script to handle display changes:
sudo nano /usr/local/bin/monitor-hotplug.sh - Add this logic (adjust output names and resolutions to match your setup):
#!/bin/bash sleep 2 # Wait for the system to finish detecting display changes # Check if DP monitor is connected if xrandr | grep -q "DP-0 connected"; then # Load your saved nvidia-settings configuration nvidia-settings --load-config-only else # Disable DP and set DVI/HDMI to your preferred layout xrandr --output DP-0 --off \ --output DVI-D-0 --mode 1920x1080 --pos 0x0 \ --output HDMI-0 --mode 1920x1080 --pos 1920x0 fi - Make the script executable:
sudo chmod +x /usr/local/bin/monitor-hotplug.sh - Create a udev rule to trigger the script on display changes:
sudo nano /etc/udev/rules.d/95-monitor-hotplug.rules - Add this line:
SUBSYSTEM=="drm", ACTION=="change", RUN+="/usr/local/bin/monitor-hotplug.sh" - Reload udev rules to apply changes:
sudo udevadm control --reload-rules && sudo udevadm trigger
3. Disable Desktop Environment Auto-Adjustment
Many desktop environments (GNOME, KDE, Xfce) have built-in display managers that override Xorg settings. To prevent this:
- For GNOME:
gsettings set org.gnome.settings-daemon.plugins.xrandr active false - For KDE: Go to System Settings > Display and Monitor > Display Configuration and uncheck "Apply display configuration on startup".
Why This Works
NVIDIA’s default nvidia-settings save function creates a config that only applies to the exact set of displays connected at the time. By explicitly defining each monitor in the Xorg config or using a script to handle hotplug events, you’re telling the system to respect your layout regardless of which displays are connected.
内容的提问来源于stack exchange,提问作者Max Matti

