views:

715

answers:

2

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 resize 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?

A: 

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.

André
I could probably do that, but I'm a little reluctant to using xhost to grant local access to the display. Maybe I'm needlessly paranoid.
JesperE
True, it's more kind of a hack, but if someone is already logged into your laptop, which I assume you're the only user on, you have a problem anyway I guess.
André
+2  A: 

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.

matli