The goal is to launch Xephyr in a script. The most popular approach is this:
Xephyr :4 &
sleep 1 # or sleep 2
launch_your_program_here
Let's see what happens here. First, unfortunately, Xephyr cannot daemonize itself, so we have to launch it asynchonously (&). Then we don't know when it's initialized, so we give it 1-2 seconds to initialize. This feels hacky. How to do it faster and more reliably?