Return the full number of events from SDL_PeepEvents() if NULL is passed in with SDL_PEEKEVENT

This commit is contained in:
Sam Lantinga 2016-01-31 11:29:11 -08:00
parent 325921789a
commit 1fb30db048
1 changed files with 32 additions and 36 deletions

View File

@ -287,16 +287,9 @@ SDL_PeepEvents(SDL_Event * events, int numevents, SDL_eventaction action,
} else { } else {
SDL_EventEntry *entry, *next; SDL_EventEntry *entry, *next;
SDL_SysWMEntry *wmmsg, *wmmsg_next; SDL_SysWMEntry *wmmsg, *wmmsg_next;
SDL_Event tmpevent;
Uint32 type; Uint32 type;
/* If 'events' is NULL, just see if they exist */ if (action == SDL_GETEVENT) {
if (events == NULL) {
action = SDL_PEEKEVENT;
numevents = 1;
events = &tmpevent;
}
/* Clean out any used wmmsg data /* Clean out any used wmmsg data
FIXME: Do we want to retain the data for some period of time? FIXME: Do we want to retain the data for some period of time?
*/ */
@ -306,11 +299,13 @@ SDL_PeepEvents(SDL_Event * events, int numevents, SDL_eventaction action,
SDL_EventQ.wmmsg_free = wmmsg; SDL_EventQ.wmmsg_free = wmmsg;
} }
SDL_EventQ.wmmsg_used = NULL; SDL_EventQ.wmmsg_used = NULL;
}
for (entry = SDL_EventQ.head; entry && used < numevents; entry = next) { for (entry = SDL_EventQ.head; entry && (!events || used < numevents); entry = next) {
next = entry->next; next = entry->next;
type = entry->event.type; type = entry->event.type;
if (minType <= type && type <= maxType) { if (minType <= type && type <= maxType) {
if (events) {
events[used] = entry->event; events[used] = entry->event;
if (entry->event.type == SDL_SYSWMEVENT) { if (entry->event.type == SDL_SYSWMEVENT) {
/* We need to copy the wmmsg somewhere safe. /* We need to copy the wmmsg somewhere safe.
@ -328,12 +323,13 @@ SDL_PeepEvents(SDL_Event * events, int numevents, SDL_eventaction action,
SDL_EventQ.wmmsg_used = wmmsg; SDL_EventQ.wmmsg_used = wmmsg;
events[used].syswm.msg = &wmmsg->msg; events[used].syswm.msg = &wmmsg->msg;
} }
++used;
if (action == SDL_GETEVENT) { if (action == SDL_GETEVENT) {
SDL_CutEvent(entry); SDL_CutEvent(entry);
} }
} }
++used;
}
} }
} }
SDL_UnlockMutex(SDL_EventQ.lock); SDL_UnlockMutex(SDL_EventQ.lock);