Question

I have a laptop running Ubuntu to which I connect an external monitor when I'm at the office. Usually this requires me to run xrandr --auto in order for the laptop to re-size the display to match the external monitor. It would be nice if this could be done automatically, either triggered when the monitor is connected, but it would be enough to actually run xrandr --auto when the laptop wakes up from suspend/hibernate.

I created a script /etc/pm/sleep.d/00xrandr.sh containing the line

xrandr --auto

but this fails since the script does not have access to the X display.

Any ideas?

Was it helpful?

Solution

I guees that the problem is that the script is being run as root, with no access to your xauth data. Depending on your setup, something like this could work:

xauth merge /home/your_username/.Xauthority
export DISPLAY=:0.0
xrandr --auto

You could use something more clever to find out which user you need to extract xauth data from if you need to.

OTHER TIPS

Have you tried to set the DISPLAY variable in the script correctly and granted access for other users to your DISPLAY with xhost + localhost? Don't know if that helps, but it's worth a try.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top