problem can also be reproduced if I just call a single line of xrandr, i.e. switch off external screen after undocking, switching on external screen after docking. It can not be reproduced leaving out the STR step it seems.