Ubuntu – Possible to have xrandr not react to unplug of secondary monitor, removal of HDMI/ DisplayPort cable

16.0416.10multiple-monitorsnvidiaxrandr

I'm on a Nvidia GTX 950 GPU desktop system with three monitors attached. One monitor on HDMI out port, other two on DisplayPort ports.

The default behavior is that turning off one of the 'secondary' monitors causes xrandr to resize the virtual desktop and rearrange all the windows to fit the surviving displays.

Is there a way to have xrandr ignore the removal of a HDMI cable and/or associated monitor so that it keeps the 'virtual desktop' the same (even if the windows are off-screen and difficult to access) and not do the re-arrangement it does to consolidate all the active windows into the surviving displays? Further, to re-insert the cable and same monitor and light it back up?

Both Ubuntu 16.04 and 16.10 seem to have the same basic behavior. I have both as boot options. Thank you.

EDIT 2017: I have found some bash and python scripts to try and automate rearrangement of off-screen windows. These can be of some use to cope with the situation. Even with Ubuntu 17.04 (format fresh install) this general problem is still ongoing for me. Script discussions: How to recover offscreen window after disconnecting second monitor? and Move windows to specific screens using the command line

Best Answer

This may work HDMI/VGA ports but not DP due to some standards for DP that should always pass detection events.

I could test this on Dell E6410 with VGA/DP. Removing cable from VGA now does not trigger xrandr resettings and move windows.

  1. gksu nvidia-settings
  2. Go to X configuration tab then export configuration
  3. Copy only device section
  4. sudo mkdir /etc/X11/xorg.conf.d/
  5. sudo nano /etc/X11/xorg.conf.d/90_my_nvidia_hacks.conf
  6. Paste the device section

    Section "Device"
        Identifier     "Device0"
        Driver         "nvidia"
        VendorName     "NVIDIA Corporation"
        BoardName      "NVS 3100M"
    EndSection
    
  7. Add to it this line Option "UseHotplugEvents" "false"

    Section "Device"
        Identifier     "Device0"
        Driver         "nvidia"
        VendorName     "NVIDIA Corporation"
        BoardName      "NVS 3100M"
        Option "UseHotplugEvents" "false"
    EndSection
    
  8. Reboot or restart lightdm

    sudo systemctl restart lightdm
    

You may find this useful too Option "AllowEmptyInitialConfiguration" "true" which create empty monitor section even no screen is connected on X start.

Reference:

My displays are reconfigured in unexpected ways when I plug in or unplug a display, or power a display off and then power it on again.

This is a special case of the issues described in “The display settings I configured in nvidia-settings do not persist.”. Some desktop environments which include advanced display configuration tools will automatically configure the display layout in response to detected configuration changes. For example, when a new display is plugged in, such a desktop environment may attempt to restore the previous layout that was used with the set of currently connected displays, or may configure a default layout based upon its own policy.

On X servers with support for RandR 1.2 or later, the NVIDIA X driver reports display hotplug events to the X server via RandR when displays are connected and disconnected. These hotplug events may trigger a desktop environment with advanced display management capabilities to change the display configuration. These changes may affect settings such as the set of active displays, their resolutions and positioning relative to each other, per-display color correction settings, and more.

In addition to hotplug events generated by connecting or disconnecting displays, DisplayPort displays will generate a hot unplug event when they power off, and a hotplug event when they power on, even if no physical plugging in or unplugging takes place. This can lead to hotplug-induced display configuration changes without any actual hotplug action taking place.

If display hotplug events are resulting in undesired configuration changes, try the solutions and workarounds listed in “The display settings I configured in nvidia-settings do not persist.”. Another workaround would be to disable the NVIDIA X driver's reporting of hotplug events with the UseHotplugEvents X configuration option. Note that this option will have no effect on DisplayPort devices, which must report all hotplug events to ensure proper functionality.


Option "UseHotplugEvents" "boolean"

When this option is enabled, the NVIDIA X driver will generate RandR display changed events when displays are plugged into or unplugged from an NVIDIA GPU. Some desktop environments will listen for these events and dynamically reconfigure the desktop when displays are added or removed.

Disabling this option suppresses the generation of these RandR events for non-DisplayPort displays, i.e., ones connected via VGA, DVI, or HDMI. Hotplug events cannot be suppressed for displays connected via DisplayPort.

Note that probing the display configuration (e.g. with xrandr or nvidia-settings) may cause RandR display changed events to be generated, regardless of whether this option is enabled or disabled. Additionally, some VGA ports are incapable of hotplug detection: on such ports, the addition or removal of displays can only be detected by re-probing the display configuration.

Default: on. The driver will generate RandR events when displays are added or removed.

Option "AllowEmptyInitialConfiguration" "boolean"

Normally, the NVIDIA X driver will fail to start if it cannot find any display devices connected to the NVIDIA GPU. AllowEmptyInitialConfiguration overrides that behavior so that the X server will start anyway, even if no display devices are connected.

Enabling this option makes sense in configurations when starting the X server with no display devices connected to the NVIDIA GPU is expected, but one might be connected later. For example, some monitors do not show up as connected when they are powered off, even if they are physically connected to the GPU.

Another scenario where this is useful is in Optimus-based laptops, where RandR 1.4 display offload (see Chapter 33, Offloading Graphics Display with RandR 1.4) is used to display the screen on the non-NVIDIA internal display panel, but an external display might be connected later.

Default: off. The driver will refuse to start if it can't find at least one connected display device.

Related Question