Handle focus more subtly

Sometimes the activation from the output terminal and the activation from the shell
terminal (for showing the next prompt) arrive out-of-order. Preliminary handling of
that case.