mirror of https://github.com/libsdl-org/SDL.git
SDL_SetEventFilter: Don't flush good events
Only cut events that don't pass the user filter instead of flushing the entire list. Fixes #9592
This commit is contained in:
parent
4954690828
commit
0136bf2f8f
|
|
@ -1310,12 +1310,22 @@ int SDL_PushEvent(SDL_Event *event)
|
|||
|
||||
void SDL_SetEventFilter(SDL_EventFilter filter, void *userdata)
|
||||
{
|
||||
SDL_EventEntry *event;
|
||||
SDL_LockMutex(SDL_event_watchers_lock);
|
||||
{
|
||||
/* Set filter and discard pending events */
|
||||
SDL_EventOK.callback = filter;
|
||||
SDL_EventOK.userdata = userdata;
|
||||
SDL_FlushEvents(SDL_EVENT_FIRST, SDL_EVENT_LAST);
|
||||
/* Flush all events not accpeted by the filter */
|
||||
SDL_LockMutex(SDL_EventQ.lock);
|
||||
{
|
||||
for (event = SDL_EventQ.head; event; event = event->next) {
|
||||
if (!filter(userdata, &event->event)) {
|
||||
SDL_CutEvent(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
SDL_UnlockMutex(SDL_EventQ.lock);
|
||||
}
|
||||
SDL_UnlockMutex(SDL_event_watchers_lock);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue