wsi/x11: Avoid a class of deadlocks in the WSI queue thread
Here are two facts, each mildly unpleasant, quite nasty taken together:
- xcb_wait_for_special_event retries its poll() if the fd woke up but no matching event arrived, without verifying that the special event queue is still registered.
- Present gives no in-band notification of window destruction.
Now if the window is destroyed before the swapchain we're in trouble. Our WSI thread might be stuck in xcb_wait_for_special_event as we're awaiting a completion that won't come (the pixmap was being presented as the window, and then the window was destroyed, so no more events can happen on that window).
The solution is to use xcb_poll_for_special_event, which is non-blocking, and handle the appropriate edge cases. If we've run the event queue but we still don't have an image to acquire, we poke the X server with a request that gently verifies that the window exists, allowing the thread to exit gracefully in the above case.