Ubuntu

Comment 3 for bug 660901

Marius (mariusknaust) wrote :

Hi Alex,

the problem is, also root hasn't the rights to use a x-server owned by an other user. You can force root to use an other users xauthority by setting the environment variable to the users xauthority data:

export XAUTHORITY=/home/.../.Xauthority

Here is my hack to use the external monitor if the VGA is plugged in:

/etc/udev/rules.d/70-external-monitor.rules:
# VGA changed
KERNEL=="card0", ACTION=="change", RUN+="/usr/local/scripts/external-monitor.sh"

/usr/local/scripts/external-monitor.sh:
#!/bin/sh

status="$(cat /sys/class/drm/card0-VGA-1/status)"

export XAUTHORITY=/home/marius/.Xauthority
export DISPLAY=:0.0

if [ "${status}" = disconnected ]
then
 xrandr --output LVDS1 --auto --output VGA1 --off
elif [ "${status}" = connected ]
then
 xrandr --output LVDS1 --off --output VGA1 --auto
fi