如何禁用监视器自动配置?

如何禁用监视器自动配置?

我正在运行 Ubuntu 16.04(开发分支),XFCE 作为桌面环境。

我的电脑连接了两台显示器。一台通过普通 VGA 电缆连接,另一台连接到 HDMI 切换器。该设置工作正常,但每次我临时将 HDMI 切换器更改为另一个 HDMI 连接时,Xorg 都会检测到显示器已断开连接,并将 Xorg 重新配置为仅使用单个显示器,将 HDMI 切换器切换回我的电脑也无法重新激活双显示器使用,我必须手动触发xrandr

如何防止发生这种自动显示器检测和重新配置?我希望能够在计算机不执行任何操作的情况下切换 HDMI 切换器。

用于恢复多显示器设置的命令:

xrandr \
 --output HDMI-1 \
   --mode "1920x1080" \
   --panning "1920x1080+1280+0/0x0+0+0" \
 --output DVI-1-I \
   --mode "1280x1024" \
   --panning "1280x1024/0x0+0+0"

常规使用时的 xrandr 输出:

Screen 0: minimum 320 x 200, current 3200 x 1080, maximum 8192 x 8192
DP-1 disconnected (normal left inverted right x axis y axis)
HDMI-1 connected 1920x1080+1280+0 (normal left inverted right x axis y axis) 443mm x 249mm panning 1920x1080+1280+0
   1920x1080     60.00*+  60.00    50.00    59.94    59.93  
   1920x1080i    60.00    50.00    59.94  
   1680x1050     59.95    59.88  
   1600x1024     60.17  
   1400x1050     74.76    70.00    59.98  
   1280x1024     75.02    60.02  
   1440x900      59.89    59.90  
   1280x960      60.00  
   1360x768      59.80    59.96  
   1280x800      59.91  
   1152x864      75.00    75.00    70.00    60.00  
   1280x720      60.00    50.00    59.94  
   1024x768      60.04    75.03    70.07    60.00  
   960x720       75.00    60.00  
   928x696       75.00    60.05  
   896x672       75.05    60.01  
   960x600       60.00  
   832x624       74.55  
   960x540       59.99  
   800x600       75.00    70.00    65.00    60.00    72.19    75.00    60.32    56.25  
   840x525       74.96    69.88    60.01    59.88  
   720x576       50.00  
   800x512       60.17  
   700x525       74.76    70.06    59.98  
   720x480       60.00    59.94  
   640x512       75.02    60.02  
   720x450       59.89  
   640x480       60.00    72.81    75.00    66.67    60.00    59.94  
   720x400       70.08  
   680x384       59.80    59.96  
   576x432       75.00    75.00    70.00    60.06  
   512x384       75.03    70.07    60.00  
   416x312       74.66  
   400x300       72.19    75.12    60.32    56.34  
   320x240       72.81    75.00    60.05  
DVI-I-1 connected 1280x1024+0+0 (normal left inverted right x axis y axis) 359mm x 287mm
   1280x1024     60.02*+  75.02  
   1280x960      60.00  
   1280x800      74.93    59.81  
   1152x864      75.00  
   1280x768      74.89    59.87  
   1280x720      60.00  
   1024x768      75.08    75.03    70.07    60.00  
   1024x576      59.97  
   832x624       74.55  
   800x600       72.19    75.00    70.01    60.32    56.25  
   848x480       60.00  
   640x480       75.00    72.81    66.67    60.00  
   720x400       70.08  

当 HDMI 切换器切换到不同的连接时,xrandr 输出:

Screen 0: minimum 320 x 200, current 1280 x 1024, maximum 8192 x 8192
DP-1 disconnected (normal left inverted right x axis y axis)
HDMI-1 disconnected (normal left inverted right x axis y axis)
DVI-I-1 connected 1280x1024+0+0 (normal left inverted right x axis y axis) 359mm x 287mm
   1280x1024     60.02*+  75.02  
   1280x960      60.00  
   1280x800      74.93    59.81  
   1152x864      75.00  
   1280x768      74.89    59.87  
   1280x720      60.00  
   1024x768      75.08    75.03    70.07    60.00  
   1024x576      59.97  
   832x624       74.55  
   800x600       72.19    75.00    70.01    60.32    56.25  
   848x480       60.00  
   640x480       75.00    72.81    66.67    60.00  
   720x400       70.08  

我还尝试了一些其他的事情:

连接显示器后找出模式行:

$ xvidtune -show 
"1920x1080"   148.50   1920 2008 2052 2200   1080 1084 1089 1125 -hsync +vsync

然后断开监视器的连接:

$ xrandr --newmode "1920x1080-new"   148.50   1920 2008 2052 2200   1080 1084 1089 1125 -hsync +vsync
$ xrandr --addmode HDMI-1 1920x1080-new
$ xrandr --output HDMI-1 --mode 1920x1080-new

这样我就可以在断开连接时激活显示器,否则由于不存在 1920x1080 模式,该功能将失败。但问题仍然存在,如果我切换 HDMI 切换器,显示器将被禁用,即使我将其设置为自定义模式。

这是使用 HDMI 切换器断开显示器连接时的 udev 事件:

$ udevadm monitor --property
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent

KERNEL[41678.571099] change   /devices/pci0000:00/0000:00:02.0/0000:01:00.0/drm/card0 (drm)
ACTION=change
DEVNAME=/dev/dri/card0
DEVPATH=/devices/pci0000:00/0000:00:02.0/0000:01:00.0/drm/card0
DEVTYPE=drm_minor
HOTPLUG=1
MAJOR=226
MINOR=0
SEQNUM=3248
SUBSYSTEM=drm

UDEV  [41678.573432] change   /devices/pci0000:00/0000:00:02.0/0000:01:00.0/drm/card0 (drm)
ACTION=change
DEVNAME=/dev/dri/card0
DEVPATH=/devices/pci0000:00/0000:00:02.0/0000:01:00.0/drm/card0
DEVTYPE=drm_minor
HOTPLUG=1
ID_FOR_SEAT=drm-pci-0000_01_00_0
ID_PATH=pci-0000:01:00.0
ID_PATH_TAG=pci-0000_01_00_0
MAJOR=226
MINOR=0
SEQNUM=3248
SUBSYSTEM=drm
TAGS=:uaccess:master-of-seat:seat:
USEC_INITIALIZED=31279519

这是使用 HDMI 切换器重新启用显示器时的 udev 事件:

$ udevadm monitor --property
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent

KERNEL[41696.104481] change   /devices/pci0000:00/0000:00:02.0/0000:01:00.0/drm/card0 (drm)
ACTION=change
DEVNAME=/dev/dri/card0
DEVPATH=/devices/pci0000:00/0000:00:02.0/0000:01:00.0/drm/card0
DEVTYPE=drm_minor
HOTPLUG=1
MAJOR=226
MINOR=0
SEQNUM=3249
SUBSYSTEM=drm

UDEV  [41696.105685] change   /devices/pci0000:00/0000:00:02.0/0000:01:00.0/drm/card0 (drm)
ACTION=change
DEVNAME=/dev/dri/card0
DEVPATH=/devices/pci0000:00/0000:00:02.0/0000:01:00.0/drm/card0
DEVTYPE=drm_minor
HOTPLUG=1
ID_FOR_SEAT=drm-pci-0000_01_00_0
ID_PATH=pci-0000:01:00.0
ID_PATH_TAG=pci-0000_01_00_0
MAJOR=226
MINOR=0
SEQNUM=3249
SUBSYSTEM=drm
TAGS=:seat:master-of-seat:uaccess:
USEC_INITIALIZED=31279519

$ sudo lshw -c display
  *-display                 
       description: VGA compatible controller
       product: Redwood XT [Radeon HD 5670/5690/5730]
       vendor: Advanced Micro Devices, Inc. [AMD/ATI]
       physical id: 0
       bus info: pci@0000:01:00.0
       version: 00
       width: 64 bits
       clock: 33MHz
       capabilities: pm pciexpress msi vga_controller bus_master cap_list rom
       configuration: driver=radeon latency=0
       resources: irq:55 memory:c0000000-cfffffff memory:fea20000-fea3ffff ioport:e000(size=256) memory:c0000-dffff

答案1

对于其他 Cinnamon 和 Gnome,可以找到解决方案这里

肉桂:

gsettings set org.cinnamon.settings-daemon.plugins.xrandr active false

侏儒:

gsettings set org.gnome.settings-daemon.plugins.xrandr active false

答案2

这不是最终答案,只是指向正确方向的指针。在 XFCE 上,xfsettingsd程序负责处理事件RRScreenChangeNotify并触发模式切换,确切的函数可以在xfce4-settings-4.12.0/xfsettingsd/displays.c第 77 行找到,该函数名为xfce_displays_helper_screen_on_event。禁用该函数将使模式在新显示器连接时不再改变。

可以通过以下方式获取调试信息:

DISPLAY=:0 XFSETTINGSD_DEBUG=512 xfsettingsd --replace --no-daemon

答案3

以下命令在 Ubuntu Mate 20.04 上对我有效:

gsettings set org.mate.SettingsDaemon.plugins.xrandr active false

在应用此修复程序之前,我遇到过类似的情况,关闭连接 HDMI 的显示器会导致它永远不会恢复,除非我xrandr使用已知的良好设置手动运行。

答案4

因为这似乎是特定于窗口管理器的,如果它不是已在 OP 的其他答案中列出的设置之一,这里有一种方法可以找到适合您系统的设置:

搜索:gsettings list-recursivelyxrandr

]$ gsettings list-recursively|grep xrandr
org.mate.SettingsDaemon.plugins.xrandr priority 1
org.mate.SettingsDaemon.plugins.xrandr default-configuration-file '/etc/mate-settings-daemon/xrandr/monitors.xml'
org.mate.SettingsDaemon.plugins.xrandr show-notification-icon false
org.mate.SettingsDaemon.plugins.xrandr turn-on-external-monitors-at-startup false
org.mate.SettingsDaemon.plugins.xrandr turn-on-laptop-monitor-at-startup true
org.mate.SettingsDaemon.plugins.xrandr active true
org.mate.SettingsDaemon.plugins.xrandr use-xorg-monitor-settings true

您可以查看xrandr active设置,然后使用gsettings set它进行更改。在此示例中,它是 Mate,正如已经回答的那样@Daniel 以上,但这个 SE 答案并非旨在重复,而是添加了有关如何xrandr在窗口管理器不是 Cinnamon、Gnome 或 Mate 的情况下查找特定于窗口管理器的设置的信息。

还值得注意的是:gsettings这是一个侏儒的东西,所以不是所有的 WM 都会使用它,但如果它有用的话,请仅供参考。

相关内容