+
+ pfds.fd = xcb_get_file_descriptor(draw->conn);
+ pfds.events = POLLIN;
+
+ ev = xcb_poll_for_special_event(draw->conn, draw->special_event);
+ while (!ev) {
+ /* Wait up to ~1s for the XCB FD to become readable */
+ if (poll(&pfds, 1, 1000) < 1) {
+ xcb_get_window_attributes_cookie_t cookie;
+ xcb_get_window_attributes_reply_t *attrib;
+ xcb_generic_error_t *error;
+
+ /* Check if the window still exists */
+ cookie = xcb_get_window_attributes(draw->conn, draw->drawable);
+ attrib = xcb_get_window_attributes_reply(draw->conn, cookie, &error);
+ free(attrib);
+
+ if (error) {
+ if (error->error_code == BadWindow)
+ draw->window_destroyed = true;
+
+ free(error);
+ break;
+ }
+ }
+
+ ev = xcb_poll_for_special_event(draw->conn, draw->special_event);
+ }
+