src/events/SDL_events.c
changeset 10060 739bc5c7d339
parent 10003 d91a2c45825e
child 10106 d240baef8248
equal deleted inserted replaced
10059:25f67a2e77a0 10060:739bc5c7d339
   285                 used += SDL_AddEvent(&events[i]);
   285                 used += SDL_AddEvent(&events[i]);
   286             }
   286             }
   287         } else {
   287         } else {
   288             SDL_EventEntry *entry, *next;
   288             SDL_EventEntry *entry, *next;
   289             SDL_SysWMEntry *wmmsg, *wmmsg_next;
   289             SDL_SysWMEntry *wmmsg, *wmmsg_next;
   290             SDL_Event tmpevent;
       
   291             Uint32 type;
   290             Uint32 type;
   292 
   291 
   293             /* If 'events' is NULL, just see if they exist */
   292             if (action == SDL_GETEVENT) {
   294             if (events == NULL) {
   293                 /* Clean out any used wmmsg data
   295                 action = SDL_PEEKEVENT;
   294                    FIXME: Do we want to retain the data for some period of time?
   296                 numevents = 1;
   295                  */
   297                 events = &tmpevent;
   296                 for (wmmsg = SDL_EventQ.wmmsg_used; wmmsg; wmmsg = wmmsg_next) {
   298             }
   297                     wmmsg_next = wmmsg->next;
   299 
   298                     wmmsg->next = SDL_EventQ.wmmsg_free;
   300             /* Clean out any used wmmsg data
   299                     SDL_EventQ.wmmsg_free = wmmsg;
   301                FIXME: Do we want to retain the data for some period of time?
   300                 }
   302              */
   301                 SDL_EventQ.wmmsg_used = NULL;
   303             for (wmmsg = SDL_EventQ.wmmsg_used; wmmsg; wmmsg = wmmsg_next) {
   302             }
   304                 wmmsg_next = wmmsg->next;
   303 
   305                 wmmsg->next = SDL_EventQ.wmmsg_free;
   304             for (entry = SDL_EventQ.head; entry && (!events || used < numevents); entry = next) {
   306                 SDL_EventQ.wmmsg_free = wmmsg;
       
   307             }
       
   308             SDL_EventQ.wmmsg_used = NULL;
       
   309 
       
   310             for (entry = SDL_EventQ.head; entry && used < numevents; entry = next) {
       
   311                 next = entry->next;
   305                 next = entry->next;
   312                 type = entry->event.type;
   306                 type = entry->event.type;
   313                 if (minType <= type && type <= maxType) {
   307                 if (minType <= type && type <= maxType) {
   314                     events[used] = entry->event;
   308                     if (events) {
   315                     if (entry->event.type == SDL_SYSWMEVENT) {
   309                         events[used] = entry->event;
   316                         /* We need to copy the wmmsg somewhere safe.
   310                         if (entry->event.type == SDL_SYSWMEVENT) {
   317                            For now we'll guarantee it's valid at least until
   311                             /* We need to copy the wmmsg somewhere safe.
   318                            the next call to SDL_PeepEvents()
   312                                For now we'll guarantee it's valid at least until
   319                          */
   313                                the next call to SDL_PeepEvents()
   320                         if (SDL_EventQ.wmmsg_free) {
   314                              */
   321                             wmmsg = SDL_EventQ.wmmsg_free;
   315                             if (SDL_EventQ.wmmsg_free) {
   322                             SDL_EventQ.wmmsg_free = wmmsg->next;
   316                                 wmmsg = SDL_EventQ.wmmsg_free;
   323                         } else {
   317                                 SDL_EventQ.wmmsg_free = wmmsg->next;
   324                             wmmsg = (SDL_SysWMEntry *)SDL_malloc(sizeof(*wmmsg));
   318                             } else {
       
   319                                 wmmsg = (SDL_SysWMEntry *)SDL_malloc(sizeof(*wmmsg));
       
   320                             }
       
   321                             wmmsg->msg = *entry->event.syswm.msg;
       
   322                             wmmsg->next = SDL_EventQ.wmmsg_used;
       
   323                             SDL_EventQ.wmmsg_used = wmmsg;
       
   324                             events[used].syswm.msg = &wmmsg->msg;
   325                         }
   325                         }
   326                         wmmsg->msg = *entry->event.syswm.msg;
   326 
   327                         wmmsg->next = SDL_EventQ.wmmsg_used;
   327                         if (action == SDL_GETEVENT) {
   328                         SDL_EventQ.wmmsg_used = wmmsg;
   328                             SDL_CutEvent(entry);
   329                         events[used].syswm.msg = &wmmsg->msg;
   329                         }
   330                     }
   330                     }
   331                     ++used;
   331                     ++used;
   332 
       
   333                     if (action == SDL_GETEVENT) {
       
   334                         SDL_CutEvent(entry);
       
   335                     }
       
   336                 }
   332                 }
   337             }
   333             }
   338         }
   334         }
   339         SDL_UnlockMutex(SDL_EventQ.lock);
   335         SDL_UnlockMutex(SDL_EventQ.lock);
   340     } else {
   336     } else {