1

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
  • Try to debug with sudo udevmonitor -e or watching /var/log/udev – tiktak May 8 '16 at 18:41
  • I don't have udevmonitor and is their anything I should be grepping for in /var/log/udev/? I see all the usual output from connecting and disconnecting the mDP cable – user3577138 May 8 '16 at 18:58
2

An udev rule applies to the add action by default. The udev rule is on a graphics card, not on a monitor; so it runs when a graphics card is added to the system, which in practice means at boot time.

Plugging in a monitor results in a change action, not an add action. You can observe this by running udevadm monitor and plugging a monitor in. So the udev rule should specify a change action.

KERNEL=="card0", SUBSYSTEM=="drm", ACTION=="change", \
    ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/var/run/gdm/auth-for-vazquez-OlbTje/database", RUN+="/usr/bin/arandr"

Examples found on the web corroborate my understanding, e.g. codingtony whose monitor-hotplug.sh script may be of interest to you.

The file name under /var/run changes each time you reboot, so you should determine it automatically inside your script. This answer should help.

  • 1
    Should ACTION=''change" be ACTION=**=**"change" --> added another = – user3577138 May 9 '16 at 4:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.