I have setup a basic udev rule to detect when I connect or disconnect a mDP cable.
The file is /etc/udev/rules.d/95-monitor-hotplug.rules
KERNEL=="card0", SUBSYSTEM=="drm", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/var/run/gdm/auth-for-vazquez-OlbTje/database", RUN+="/usr/bin/arandr"
It should just launch arandr when their is a mDP cable connected or disconnected, but nothing happens. I have also reloaded the rules with:
udevadm control --reload-rules
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
This is how the problem was solved. With the links provided by @Gilles. I added the following code to my .profile
then pointed the ENV{$XAUTHORITY}="/home/user/.Xauthority"
and also added ACTION=="change"
to the rules file. After that everything was working as it should. Thanks Gilles.
case $DISPLAY:$XAUTHORITY in
:*:?*)
# DISPLAY is set and points to a local display, and XAUTHORITY is
# set, so merge the contents of `$XAUTHORITY` into ~/.Xauthority.
XAUTHORITY=~/.Xauthority xauth merge "$XAUTHORITY";;
esac
sudo udevmonitor -e
or watching/var/log/udev
– tiktak May 08 '16 at 18:41