I have the same issue when my laptop is on and off it's base (connected to
DVI).
Didn't go through the issue yet, but I want to try to refresh xrandr, if that
makes sense.
The reason is it's always right when I turn the laptop on.
It doesn't when I try to put it on or off the base/DVI (connect/disconnect
from external screen).
Maybe playing with this could help:
https://askubuntu.com/questions/356621/refresh-display-settings-using-xrandr-laptop-screen-off-external-screen-on
But to make a script out of it, I would need to identify the trigger that
makes the xrandr config change when I plug or unplug the external screen.