Tidy up and fix unreliable test `test_x11_remote`

It was failing intermittently on Travis due to not knowing when xterm
is ready to accept key events.  Instead we keep sending key events until
we can see that they are having an effect.

This also tidies up the test somewhat.  By pulling the starting/stopping
of the X server out into a context manager it is clearer exactly what
`test_x11_remote` is intended to test, and how it tries to test it.

The broken test was introduced in a64e7ac7.
Merge pull request #180 from wmanley/fix-test-x11-remote

Tidy up and fix unreliable test `test_x11_remote`