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,52 +287,48 @@ 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) { /* Clean out any used wmmsg data
action = SDL_PEEKEVENT; FIXME: Do we want to retain the data for some period of time?
numevents = 1; */
events = &tmpevent; for (wmmsg = SDL_EventQ.wmmsg_used; wmmsg; wmmsg = wmmsg_next) {
wmmsg_next = wmmsg->next;
wmmsg->next = SDL_EventQ.wmmsg_free;
SDL_EventQ.wmmsg_free = wmmsg;
}
SDL_EventQ.wmmsg_used = NULL;
} }
/* Clean out any used wmmsg data for (entry = SDL_EventQ.head; entry && (!events || used < numevents); entry = next) {
FIXME: Do we want to retain the data for some period of time?
*/
for (wmmsg = SDL_EventQ.wmmsg_used; wmmsg; wmmsg = wmmsg_next) {
wmmsg_next = wmmsg->next;
wmmsg->next = SDL_EventQ.wmmsg_free;
SDL_EventQ.wmmsg_free = wmmsg;
}
SDL_EventQ.wmmsg_used = NULL;
for (entry = SDL_EventQ.head; entry && 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) {
events[used] = entry->event; if (events) {
if (entry->event.type == SDL_SYSWMEVENT) { events[used] = entry->event;
/* We need to copy the wmmsg somewhere safe. if (entry->event.type == SDL_SYSWMEVENT) {
For now we'll guarantee it's valid at least until /* We need to copy the wmmsg somewhere safe.
the next call to SDL_PeepEvents() For now we'll guarantee it's valid at least until
*/ the next call to SDL_PeepEvents()
if (SDL_EventQ.wmmsg_free) { */
wmmsg = SDL_EventQ.wmmsg_free; if (SDL_EventQ.wmmsg_free) {
SDL_EventQ.wmmsg_free = wmmsg->next; wmmsg = SDL_EventQ.wmmsg_free;
} else { SDL_EventQ.wmmsg_free = wmmsg->next;
wmmsg = (SDL_SysWMEntry *)SDL_malloc(sizeof(*wmmsg)); } else {
wmmsg = (SDL_SysWMEntry *)SDL_malloc(sizeof(*wmmsg));
}
wmmsg->msg = *entry->event.syswm.msg;
wmmsg->next = SDL_EventQ.wmmsg_used;
SDL_EventQ.wmmsg_used = wmmsg;
events[used].syswm.msg = &wmmsg->msg;
}
if (action == SDL_GETEVENT) {
SDL_CutEvent(entry);
} }
wmmsg->msg = *entry->event.syswm.msg;
wmmsg->next = SDL_EventQ.wmmsg_used;
SDL_EventQ.wmmsg_used = wmmsg;
events[used].syswm.msg = &wmmsg->msg;
} }
++used; ++used;
if (action == SDL_GETEVENT) {
SDL_CutEvent(entry);
}
} }
} }
} }