there's a file called status
in cat /sys/class/drm/card0-CONNECTION
where CONNECTION
is the name xrandr --listmonitors
shows on the right. So e.g. for me it looks like this:
$ xrandr --listmonitors
Monitors: 2
0: +*DP-3 2560/553x1440/311+0+430 DP-3
1: +DP-5 1440/553x2560/311+2560+0 DP-5
$ cat /sys/class/drm/card0-DP-3/status
connected
You can watch this file with inotifywatch -e modify
. You can put this in a systemd.path unit which calls your script as a one-shot or with an environment parameter.
You can also use srandrd but IMHO that's a bit overkill when you can do it with pid0 tools 😅