1

I have created my very first udev rule to automatically setup my external display when I plug in my laptop to docking station. As things turn out it's not working (what a suprise). First things first I checked what events are being sent when I unplug and plug in my external display to docking station (the same events happen when I connect and disconnect docking station itself from the laptop with external display connected to it). Here is the output from *udevadm monitor:

### CONNECTING EXTERNAL DISPLAY ###
KERNEL[12586.516063] change   /devices/pci0000:00/0000:00:01.1/0000:01:00.0/drm/card1 (drm)
UDEV  [12586.520032] change   /devices/pci0000:00/0000:00:01.1/0000:01:00.0/drm/card1 (drm)
KERNEL[12588.090123] change   /devices/pci0000:00/0000:00:01.1/0000:01:00.0/drm/card1 (drm)
UDEV  [12588.094088] change   /devices/pci0000:00/0000:00:01.1/0000:01:00.0/drm/card1 (drm)
### DISCONNECTING EXTERNAL DISPLAY ###
KERNEL[12577.885860] change   /devices/pci0000:00/0000:00:01.1/0000:01:00.0/drm/card1 (drm)
KERNEL[12577.885951] change   /devices/pci0000:00/0000:00:01.1/0000:01:00.0/drm/card1 (drm)
UDEV  [12577.894562] change   /devices/pci0000:00/0000:00:01.1/0000:01:00.0/drm/card1 (drm)
UDEV  [12577.900236] change   /devices/pci0000:00/0000:00:01.1/0000:01:00.0/drm/card1 (drm)

Here is my udev rule:

KERNEL=="card1", SUBSYSTEM=="drm", ACTION=="change", RUN+="su vllblvck -c /usr/bin/setup-ext-display.sh"

And here is the script that it is supposed to run:

#!/bin/sh                                                                                                                                                                                       
# PLACE THIS SCRIPT INSIDE /usr/bin
# Automatically setup external monitor

xrandr_command="/usr/bin/xrandr"
sed_command="/bin/sed"

is_hdmi_connected=`DISPLAY=:0 $xrandr_command | $sed_command -n '/DP-1-2.3 connected/p'`
echo is_hdmi_connected: $is_hdmi_connected

if [ -n "$is_hdmi_connected" ]; then
  DISPLAY=:0 xrandr --output DP-1-2.3 --auto --right-of eDP-1 
  echo connecting
else
  DISPLAY=:0 $xrandr_command --output DP-1-2.3 --off
  echo disconnecting
fi

The script itself works just fine and does what I want it to do. I have even switched to the root user to check if su vllblvck -c part is working correctly and yes it is. I've run below command to check if the rule would even execute and supposedly it would but in reality it does not or malfunctions in some way and my external display is never set up .

udevadm test --action="change" /devices/pci0000:00/0000:00:01.1/0000:01:00.0/drm/card1

I would appreciate any tips on how to fix this or debug this further as udev rules topic is new to me and I've run out of ideas and google searches. And If that matters here I'm running ArcoLinux with 5.14.14-arch1-1 kernel.

1 Answer 1

1

I managed to fix my udev rule after many tries. Here is a working one:

KERNEL=="card1", SUBSYSTEM=="drm", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/vllblvck/.Xauthority", RUN+="/usr/bin/setup-ext-display.sh"

Don't ask me why it works and the previous one does not because I have no idea. Maybe someone more experienced with udev rules could tell us.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .