Index: src/events/SDL_events.c =================================================================== --- src/events/SDL_events.c (revision 4406) +++ src/events/SDL_events.c (working copy) @@ -399,17 +399,23 @@ int SDL_PollEvent(SDL_Event * event) { - SDL_PumpEvents(); - - /* We can't return -1, just return 0 (no event) on error */ - if (SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_ALLEVENTS) <= 0) - return 0; - return 1; + return SDL_WaitEventTimeout(event, 0); } int SDL_WaitEvent(SDL_Event * event) { + return SDL_WaitEventTimeout(event, -1); +} + +int +SDL_WaitEventTimeout(SDL_Event * event, int timeout) +{ + Uint32 expiration; + + if (timeout > 0) + expiration = SDL_GetTicks() + timeout; + while (1) { SDL_PumpEvents(); switch (SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_ALLEVENTS)) { @@ -418,7 +424,10 @@ case 1: return 1; case 0: - SDL_Delay(10); + if (timeout == 0 || (timeout > 0 && SDL_GetTicks() >= expiration)) + return 0; + else + SDL_Delay(10); } } } Index: include/SDL_events.h =================================================================== --- include/SDL_events.h (revision 4406) +++ include/SDL_events.h (working copy) @@ -412,6 +412,14 @@ */ extern DECLSPEC int SDLCALL SDL_WaitEvent(SDL_Event * event); +/* Waits until the specified timeout (in milliseconds) for the next available + event, returning 1, or 0 if there was an error while waiting for events. If + 'event' is not NULL, the next event is removed from the queue and stored in + that area. + */ +extern DECLSPEC int SDLCALL SDL_WaitEventTimeout(SDL_Event * event, + int timeout); + /* Add an event to the event queue. This function returns 1 on success, 0 if the event was filtered, or -1 if the event queue was full or there was some other error.