External monitor on Linux

1. On each connect

Short command to set the correct resolution and scaling for an external monitor.
I've decided to write this down because the --scale-from parameter seems to be uncommon. Most suggestions on the internet only use --scale, which I find less intuitive to use.

# XPS 13 with full hd display
xrandr --output DP1 --primary --mode 1920x1080 --scale-from 1920x1080 --same-as eDP1
# XPS 15 with 4k display on an external WQHD display
xrandr --output DP1 --primary --mode 2560x1440 --scale-from 3840x2160 --same-as eDP1

2. Automate it by using autorandr

sudo pacman -S autorandr
sudo systemctl enable --now autorandr.service

I've created two profiles.

autorandr should switch to the correct mode automatically (hence the name) from now on.

What's neat: If you close the lid while the notebook is connected to the external monitor, it doesn't go into sleep mode.

Problems with autorandr

I now had two different laptops where autorandr caused problems. After connecting to a screen I had no output (not even on the laptop screen) and xrandr commands were "ignored": It returned immediately, but didn't change anything.

I don't know a good alternative, so I will keep custom xrandr scripts for my different displays. :(

I might try xlayoutdisplay in future, although it works a bit differently.

Update: This doesn't seem to be a problem of autorandr, but rather some display driver issue, even though I've experienced this issue on two different devices. I had the same problem with autorandr uninstalled and using xrandr directly now.