Posted a problem with Display settings not being remembered across sessions after unplugging/replugging daisychained displayport monitors. After some hints/suggestions from ericmarceau and col.row, I got to the following solution. Posting in case it helps someone else.
Steps:
Get display set up how you want it with multiple monitors
Install arandr
Open arandr. It should show your current layout.
Layout → Save as
Give the output a name, the default is to save in ~/.screenlayout which is fine. The output will save as a .sh script
If you open the .sh script, you’ll see an xrandr command detailing your layout. If you unplug external monitors, plug back in, and run that file as a script, it’ll magically fix your display setup.
One option is to create a panel button to launch that script. Plug external monitors in and if the display isn’t set up how you prefer, click the button and you’re done.
If you want to automate running the script on hotplugging your external monitors, do the following:
Create a script called dp-hotplug.sh in /usr/local/bin with the following contents [change xrandr command to match contents of the file created by arandr]
#!/bin/sh
Auto-detect user info
USER_NAME=“$(whoami)”
USER_UID=“$(id -u)”
export DISPLAY=“:0”
export XAUTHORITY=“/home/${USER_NAME}/.Xauthority”
export DBUS_SESSION_BUS_ADDRESS=“unix:path=/run/user/${USER_UID}/bus”
Check if any of the DP outputs are connected (indicating plug-in event)
DP_OUTPUTS=“DP-1 DP-2 DP-3 DP-4 DP-2-8 DP-2-1 DP-2-1-8 DP-2-1-1”
any_dp_connected=false
for OUT in $DP_OUTPUTS; do
if xrandr | grep “^${OUT} connected” >/dev/null 2>&1; then
any_dp_connected=true
break
fi
done
if $any_dp_connected; then
Your exact xrandr sequence for when DP is plugged in
xrandr --output eDP-1 --mode 1920x1200 --pos 3840x0 --rotate normal
–output DP-1 --off
–output DP-2 --off
–output DP-3 --off
–output DP-4 --off
–output DP-2-8 --mode 1920x1200 --pos 1920x0 --rotate normal
–output DP-2-1 --off
–output DP-2-1-8 --primary --mode 1920x1200 --pos 0x0 --rotate normal
–output DP-2-1-1 --off
else
Fallback: just enable internal display when no external DPs detected
xrandr --output eDP-1 --mode 1920x1200 --auto
fi
then do:
sudo chown root:root /usr/local/bin/dp-hotplug.sh
sudo chmod +x /usr/local/bin/dp-hotplug.sh
as root, create a file /etc/systemd/system/dp-hotplug.service with this as contents:
[Unit]
Description=Handle DisplayPort hotplug
[Service]
Type=oneshot
ExecStart=/usr/local/bin/dp-hotplug.sh
[Install]
WantedBy=multi-user.target
then do:
sudo systemctl daemon-reload
as root, create a file /etc/udev/rules.d/90-monitor-hotplug.rules with this in it:
/etc/udev/rules.d/90-monitor-hotplug.rules
ACTION==“change”, SUBSYSTEM==“drm”, KERNEL==“card1”,
RUN+=“/usr/bin/systemctl start dp-hotplug.service”
then do:
sudo udevadm control --reload-rules
sudo udevadm trigger --subsystem-match=drm
then do:
sudo systemctl edit dp-hotplug.service
it’ll open a file in nano. Add this after the line “### Anything between here and the comment below will become the contents of the drop-in file”, changing YOURUSERNAME to your actual username:
[Service]
Type=oneshot
User=YOURUSERNAME
Group=YOURUSERNAME
Environment=DISPLAY=:0
Environment=XAUTHORITY=/home/pete/.Xauthority
Save and exit.
Then do:
sudo systemctl daemon-reload
sudo systemctl start dp-hotplug.service
And you should be done. Unplug and replug in your external displayport monitors and everything should come back up in the configuration you want..