Auto-resize X11 display when connecting an external monitor

I have a laptop running Ubuntu to which I connect an external monitor when I am in the office. This usually requires running xrandr --auto so that the laptop can resize the display to match the external monitor. It would be nice if it could be done automatically, or it worked when the monitor was connected, but it would be enough to run xrandr --auto when the laptop wakes up from standby / hibernation mode.

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

 xrandr --auto 

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

Any ideas?

+4
source share
2 answers

I believe the problem is that the script runs as root, without accessing your xauth data. Depending on your setup, something like this might work:

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

You could use something smarter to figure out which user you need to extract xauth data if you need.

+2
source

Did you try to set the DISPLAY variable correctly in the script and provide other users access to your DISPLAY using xhost + localhost? I don't know if this helps, but it's worth a try.

0
source

Source: https://habr.com/ru/post/1277126/


All Articles