|
@@ -1557,23 +1557,21 @@ X11_HandleFocusChanges(_THIS)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-/* Ack! X11_XPending() actually performs a blocking read if no events available */
|
|
|
-static int
|
|
|
-X11_Pending(Display * display)
|
|
|
+
|
|
|
+static Bool
|
|
|
+isAnyEvent(Display *display, XEvent *ev, XPointer arg)
|
|
|
{
|
|
|
- /* Flush the display connection and look to see if events are queued */
|
|
|
- X11_XFlush(display);
|
|
|
- if (X11_XEventsQueued(display, QueuedAlready)) {
|
|
|
- return (1);
|
|
|
- }
|
|
|
+ return True;
|
|
|
+}
|
|
|
|
|
|
- /* More drastic measures are required -- see if X is ready to talk */
|
|
|
- if (SDL_IOReady(ConnectionNumber(display), SDL_IOR_READ, 0)) {
|
|
|
- return (X11_XPending(display));
|
|
|
+static SDL_bool
|
|
|
+X11_PollEvent(Display *display, XEvent *event)
|
|
|
+{
|
|
|
+ if (!X11_XCheckIfEvent(display, event, isAnyEvent, NULL)) {
|
|
|
+ return SDL_FALSE;
|
|
|
}
|
|
|
|
|
|
- /* Oh well, nothing is ready .. */
|
|
|
- return (0);
|
|
|
+ return SDL_TRUE;
|
|
|
}
|
|
|
|
|
|
void
|
|
@@ -1611,17 +1609,21 @@ X11_WaitEventTimeout(_THIS, int timeout)
|
|
|
|
|
|
SDL_zero(xevent);
|
|
|
|
|
|
- if (timeout == 0) {
|
|
|
- if (X11_Pending(display)) {
|
|
|
- X11_XNextEvent(display, &xevent);
|
|
|
- } else {
|
|
|
- return 0;
|
|
|
- }
|
|
|
+ /* Flush and poll to grab any events already read and queued */
|
|
|
+ X11_XFlush(display);
|
|
|
+ if (X11_PollEvent(display, &xevent)) {
|
|
|
+ /* Fall through */
|
|
|
+ } else if (timeout == 0) {
|
|
|
+ return 0;
|
|
|
} else {
|
|
|
/* Use SDL_IOR_NO_RETRY to ensure SIGINT will break us out of our wait */
|
|
|
int err = SDL_IOReady(ConnectionNumber(display), SDL_IOR_READ | SDL_IOR_NO_RETRY, timeout);
|
|
|
if (err > 0) {
|
|
|
- X11_XNextEvent(display, &xevent);
|
|
|
+ if (!X11_PollEvent(display, &xevent)) {
|
|
|
+ /* Someone may have beat us to reading the fd. Return 1 here to
|
|
|
+ * trigger the normal spurious wakeup logic in the event core. */
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
} else if (err == 0) {
|
|
|
/* Timeout */
|
|
|
return 0;
|
|
@@ -1679,8 +1681,7 @@ X11_PumpEvents(_THIS)
|
|
|
SDL_zero(xevent);
|
|
|
|
|
|
/* Keep processing pending events */
|
|
|
- while (X11_Pending(data->display)) {
|
|
|
- X11_XNextEvent(data->display, &xevent);
|
|
|
+ while (X11_PollEvent(data->display, &xevent)) {
|
|
|
X11_DispatchEvent(_this, &xevent);
|
|
|
}
|
|
|
|