Return the full number of events from SDL_PeepEvents() if NULL is passed in with SDL_PEEKEVENT
authorSam Lantinga <slouken@libsdl.org>
Sun, 31 Jan 2016 11:29:11 -0800
changeset 10060739bc5c7d339
parent 10059 25f67a2e77a0
child 10061 698a7d8626b9
Return the full number of events from SDL_PeepEvents() if NULL is passed in with SDL_PEEKEVENT
src/events/SDL_events.c
     1.1 --- a/src/events/SDL_events.c	Sun Jan 31 09:39:42 2016 -0400
     1.2 +++ b/src/events/SDL_events.c	Sun Jan 31 11:29:11 2016 -0800
     1.3 @@ -287,52 +287,48 @@
     1.4          } else {
     1.5              SDL_EventEntry *entry, *next;
     1.6              SDL_SysWMEntry *wmmsg, *wmmsg_next;
     1.7 -            SDL_Event tmpevent;
     1.8              Uint32 type;
     1.9  
    1.10 -            /* If 'events' is NULL, just see if they exist */
    1.11 -            if (events == NULL) {
    1.12 -                action = SDL_PEEKEVENT;
    1.13 -                numevents = 1;
    1.14 -                events = &tmpevent;
    1.15 +            if (action == SDL_GETEVENT) {
    1.16 +                /* Clean out any used wmmsg data
    1.17 +                   FIXME: Do we want to retain the data for some period of time?
    1.18 +                 */
    1.19 +                for (wmmsg = SDL_EventQ.wmmsg_used; wmmsg; wmmsg = wmmsg_next) {
    1.20 +                    wmmsg_next = wmmsg->next;
    1.21 +                    wmmsg->next = SDL_EventQ.wmmsg_free;
    1.22 +                    SDL_EventQ.wmmsg_free = wmmsg;
    1.23 +                }
    1.24 +                SDL_EventQ.wmmsg_used = NULL;
    1.25              }
    1.26  
    1.27 -            /* Clean out any used wmmsg data
    1.28 -               FIXME: Do we want to retain the data for some period of time?
    1.29 -             */
    1.30 -            for (wmmsg = SDL_EventQ.wmmsg_used; wmmsg; wmmsg = wmmsg_next) {
    1.31 -                wmmsg_next = wmmsg->next;
    1.32 -                wmmsg->next = SDL_EventQ.wmmsg_free;
    1.33 -                SDL_EventQ.wmmsg_free = wmmsg;
    1.34 -            }
    1.35 -            SDL_EventQ.wmmsg_used = NULL;
    1.36 -
    1.37 -            for (entry = SDL_EventQ.head; entry && used < numevents; entry = next) {
    1.38 +            for (entry = SDL_EventQ.head; entry && (!events || used < numevents); entry = next) {
    1.39                  next = entry->next;
    1.40                  type = entry->event.type;
    1.41                  if (minType <= type && type <= maxType) {
    1.42 -                    events[used] = entry->event;
    1.43 -                    if (entry->event.type == SDL_SYSWMEVENT) {
    1.44 -                        /* We need to copy the wmmsg somewhere safe.
    1.45 -                           For now we'll guarantee it's valid at least until
    1.46 -                           the next call to SDL_PeepEvents()
    1.47 -                         */
    1.48 -                        if (SDL_EventQ.wmmsg_free) {
    1.49 -                            wmmsg = SDL_EventQ.wmmsg_free;
    1.50 -                            SDL_EventQ.wmmsg_free = wmmsg->next;
    1.51 -                        } else {
    1.52 -                            wmmsg = (SDL_SysWMEntry *)SDL_malloc(sizeof(*wmmsg));
    1.53 +                    if (events) {
    1.54 +                        events[used] = entry->event;
    1.55 +                        if (entry->event.type == SDL_SYSWMEVENT) {
    1.56 +                            /* We need to copy the wmmsg somewhere safe.
    1.57 +                               For now we'll guarantee it's valid at least until
    1.58 +                               the next call to SDL_PeepEvents()
    1.59 +                             */
    1.60 +                            if (SDL_EventQ.wmmsg_free) {
    1.61 +                                wmmsg = SDL_EventQ.wmmsg_free;
    1.62 +                                SDL_EventQ.wmmsg_free = wmmsg->next;
    1.63 +                            } else {
    1.64 +                                wmmsg = (SDL_SysWMEntry *)SDL_malloc(sizeof(*wmmsg));
    1.65 +                            }
    1.66 +                            wmmsg->msg = *entry->event.syswm.msg;
    1.67 +                            wmmsg->next = SDL_EventQ.wmmsg_used;
    1.68 +                            SDL_EventQ.wmmsg_used = wmmsg;
    1.69 +                            events[used].syswm.msg = &wmmsg->msg;
    1.70                          }
    1.71 -                        wmmsg->msg = *entry->event.syswm.msg;
    1.72 -                        wmmsg->next = SDL_EventQ.wmmsg_used;
    1.73 -                        SDL_EventQ.wmmsg_used = wmmsg;
    1.74 -                        events[used].syswm.msg = &wmmsg->msg;
    1.75 +
    1.76 +                        if (action == SDL_GETEVENT) {
    1.77 +                            SDL_CutEvent(entry);
    1.78 +                        }
    1.79                      }
    1.80                      ++used;
    1.81 -
    1.82 -                    if (action == SDL_GETEVENT) {
    1.83 -                        SDL_CutEvent(entry);
    1.84 -                    }
    1.85                  }
    1.86              }
    1.87          }