3

I use gnome with multiple displays. I use these in a mirroring setup. However, whenever my external display reconnects (whether by plugging in or by powering on the display), it seems to forget that i preferred for it to mirror.

Is there any way i can set this as the default somehow?

  • You may want to review the monitors.xml file found in ~/.config. This file is managed through the Gnome Control Center. I've run into similar situations when using multiple displays, and I noticed that the monitors.xml file can get rather messy. You may even want to rename that file (e.g., orig_monitors.xml) and have Gnome Control Center recreate it. In my case, the "clean" monitors.xml file resolved my display configuration issues. – richbl Sep 25 '22 at 17:48
  • @richbl it doesn't seem like i have such a file – Kiara Grouwstra Sep 26 '22 at 18:15

1 Answers1

2

When an external display connect, we need to trigger a shell script We can do this by using udev

First, if you don't have udev on your Ubuntu

Run the following command:

sudo apt install udev

Monitor (output) UDEV events with udevadm

This step will be most important for each user. Run udevadm monitor --environment --udev. Then connect your HDMI cable.

udev rule

Based on the output from the above command, the user created this udev rule at /etc/udev/rules.d/95-monitor-hotplug.rules.

KERNEL=="card0", SUBSYSTEM=="drm", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/YOUR_USER_NAME_GOES_HERE/.Xauthority", RUN+="/usr/local/bin/hotplug_monitor.sh"

Where YOUR_USER_NAME_GOES_HERE is your username.

You may want to adjust the xrandr options to suit your needs.

First run xrandr to detect your current screens:

$ xrandr
Screen 0: minimum 320 x 200, current 3840 x 1080, maximum 8192 x 8192
LVDS1 connected (normal left inverted right x axis y axis)
   1600x900       60.0*+   40.0  
   1024x768       60.0  
   800x600        60.3     56.2  
   640x480        59.9
HDMI3 connected 1920x1080+0+0 (normal left inverted right x axis y axis) 521mm x 293mm
   1920x1080      60.0*+
   1600x1200      60.0  
   1680x1050      59.9  
   1680x945       60.0
   [...]

To Set the displays so that the external monitor will mirror the current display:

$ xrandr --output HDMI3 --same-as LVDS1 

Check your screen display names (LVDS1 etc..).

xrandr script to put at /usr/local/bin/hotplug_monitor.sh:


#! /usr/bin/bash

export DISPLAY=:0 export XAUTHORITY=/home/YOUR_USER_NAME_GOES_HERE/.Xauthority

function connect(){ xrandr --output HDMI3 --same-as LVDS1
}

function disconnect(){ xrandr --output HDMI3 --off }

xrandr | grep "HDMI3 connected" &> /dev/null && connect || disconnect

Pablo Bianchi
  • 15,657
Sagi Weizmann
  • 741
  • 5
  • 9
  • actually, this seems to do part of the job: it works when you plug out and in, but not when you turn the display off and on. – Kiara Grouwstra Sep 27 '22 at 09:38
  • 1
    @KiaraGrouwstra , well in your question you wrote about screen reconnects which mean plug in plug out behavior , not on the screen turn off/turn on , you may add it to your question .. – Sagi Weizmann Sep 27 '22 at 09:56
  • okay, I've specified the reconnection triggers in the question now – Kiara Grouwstra Sep 27 '22 at 13:23